Skip to content
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

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from

Conversation

marcomorain
Copy link
Contributor

@marcomorain marcomorain commented Nov 30, 2021

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:

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 #871

My Calva PR Checklist

I have:

  • Read How to Contribute.
  • Directed this pull request at the dev branch. (Or have specific reasons to target some other branch.)
  • Made sure I have changed the PR base branch, so that it is not published. (Sorry for the nagging.)
  • Updated the [Unreleased] entry in CHANGELOG.md, linking the issue(s) that the PR is addressing.
  • Figured if anything about the fix warrants tests on Mac/Linux/Windows/Remote/Whatever, and either tested it there if so, or mentioned it in the PR.
  • Added to or updated docs in this branch, if appropriate
  • Tested the VSIX built from the PR (so, after you've submitted the PR). You'll find the artifacts by clicking Show all checks in the CI section of the PR page, and then Details on the ci/circleci: build test. NB: You need to sign in/up at Circle CI to find the Artifacts tab.
    • Tested the particular change
    • Figured if the change might have some side effects and tested those as well.
    • Smoke tested the extension as such.
  • Referenced the issue I am fixing/addressing in a commit message for the pull request.
    • If I am fixing the issue, I have used GitHub's fixes/closes syntax
    • If I am fixing just part of the issue, I have just referenced it w/o any of the "fixes” keywords.
  • Created the issue I am fixing/addressing, if it was not present.

Ping @PEZ, @bpringe

src/state.ts Outdated Show resolved Hide resolved
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
@bpringe
Copy link
Member

bpringe commented Dec 1, 2021

This might somewhat conflict with planned changes mentioned here, #1254, but maybe not.

Generally, I think what makes sense is for Calva to ”collect” project files from the current file up to the repo/window/workspace root and present a menu where the user can select one of those.

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.

@bpringe
Copy link
Member

bpringe commented Dec 1, 2021

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.

I may be misunderstanding, or could use some educating, but do some project.clj files begin with (ns?

Copy link
Collaborator

@PEZ PEZ left a 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.

Comment on lines +144 to +148
function isNamespace(path: string): boolean {
const content = filesCache.content(path);
const hasNsDecl = /^\(ns /.test(content);
return hasNsDecl;
}
Copy link
Collaborator

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:

export class StringDocument implements EditableDocument {

Copy link
Collaborator

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!

@PEZ
Copy link
Collaborator

PEZ commented Dec 1, 2021

@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.

@bpringe
Copy link
Member

bpringe commented Dec 2, 2021

project.clj files with ns forms are never Leiningen files, right?

since a project one of our core domain objects

Oh I now get that someone could have a project.clj source file 😄 .

@bpringe
Copy link
Member

bpringe commented Dec 2, 2021

I think some of the questions you raised, @bpringe should be added to #1254

It seems that things I mentioned here have been covered in that issue.

Copy link
Collaborator

@PEZ PEZ left a 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants