-
-
Notifications
You must be signed in to change notification settings - Fork 217
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve leiningen project search #1403
base: dev
Are you sure you want to change the base?
Conversation
I have a problem when I use Calva's Jack In command - I have to run to open my project.clj file in the root of the repo before I Jack In. If I run the command when I have any source files open in the editor, the Jack In fails. The reason for this is that Calva will search from the directory containing the current file down to the workspace root. There are many projects named `project.clj` in the main CircleCI repo, since a project one of our core domain objects: ``` marc@blaster ~/dev/circleci/circle $ find . -name project.clj ./project.clj ./src/circle/project.clj ./src/circle/http/api/v1/v1_0/project.clj ./src/circle/http/api/v1/v1_1/project.clj ./src/circle/http/api/v1/shared/project.clj ./src/circle/http/api/v2/insights/project.clj ./src/circle/http/api/v2/project.clj ./src/circle/http/api/v2/entities/insights/project.clj ./src/circle/http/api/v2/entities/project.clj ./src/circle/model/project.clj ./src/circle/model/api/project.clj ``` If I have any file open in `src/circle`, (which is the location of all source files), Calva will find `src/circle/project.clj` before it considers the project.clj in the root. As far as I understand, this is a desirable search behaviour, since it allows folks to use Calva in projects that contain multiple leiningen projects. This change alters the search behaviour to only consider files that don't begin with the string `(ns ` when attempting the determine the project path. Fixes BetterThanTomorrow#871
839fbd3
to
1fb466d
Compare
This might somewhat conflict with planned changes mentioned here, #1254, but maybe not.
I think along with a menu, we could also provide a way to make a single file be used each time, in case someone always wants the top-level project file to be used, for example. @PEZ What are your thoughts on maybe only providing an option to always use the root project file when connecting and jacking in? This could work in conjunction with and be added before adding the menu feature mentioned in #1254, I think. |
I may be misunderstanding, or could use some educating, but do some project.clj files begin with |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this, will be good in combo with some other fixes for this. Only issue is how we determine if there is an ns
or not.
function isNamespace(path: string): boolean { | ||
const content = filesCache.content(path); | ||
const hasNsDecl = /^\(ns /.test(content); | ||
return hasNsDecl; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a bit brittle. People have white space and comments and whatever before the ns form. I think that if we refactor out a version of src/namespace.ts:getNameSpace()
that takes a string as its argument, that'll be more safer and more battle tested. I can help with this if you like. I think I might have created a thing that can be used in the mega-parinfer PR:
Line 489 in 6e756d7
export class StringDocument implements EditableDocument { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And no that PR is merged!
@bpringe @marcomorain regarding #1254 I think this is only slightly related. project.clj files with ns forms are never Leiningen files, right? In any case, I think some of the questions you raised, @bpringe should be added to #1254. It's good to have a fuller picture there for when someone has the time to try implement. |
Oh I now get that someone could have a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should have a more stable way to find the ns
form. Other than that, this looks good.
What has Changed?
I have a problem when I use Calva's Jack In command - I have to run to
open my project.clj file in the root of the repo before I Jack In. If
I run the command when I have any source files open in the editor, the
Jack In fails.
The reason for this is that Calva will search from the directory
containing the current file down to the workspace root.
There are many projects named
project.clj
in the main CircleCI repo,since a project one of our core domain objects:
If I have any file open in
src/circle
, (which is the location of allsource files), Calva will find
src/circle/project.clj
before itconsiders the project.clj in the root. As far as I understand, this is a
desirable search behaviour, since it allows folks to use Calva in
projects that contain multiple leiningen projects.
This change alters the search behaviour to only consider files that
don't begin with the string
(ns
when attempting the determine theproject path.
Fixes #871
My Calva PR Checklist
I have:
dev
branch. (Or have specific reasons to target some other branch.)published
. (Sorry for the nagging.)[Unreleased]
entry inCHANGELOG.md
, linking the issue(s) that the PR is addressing.ci/circleci: build
test. NB: You need to sign in/up at Circle CI to find the Artifacts tab.Ping @PEZ, @bpringe