-
-
Notifications
You must be signed in to change notification settings - Fork 219
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
Account for multiple project roots #1609
Conversation
Let the user pick if there are more than one Changes the way we find the closest project root Not using node fs module at all Fixes #1254
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 had a couple questions but other than that this is beautiful 😚👌🏻
src/state.ts
Outdated
async function findProjectRootPaths() { | ||
const projectFileNames: string[] = ['project.clj', 'shadow-cljs.edn', 'deps.edn']; | ||
const projectFilesGlob = `**/{${projectFileNames.join(',')}}`; | ||
const excludeDirsGlob = `**/{${config.getConfig().projectRootsSearchExclude.join(',')}}`; |
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 see target
is in the list of excluded directories. Would that exclude a directory named target-files
or does it need to be just target
by itself in order to match this glob?
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.
It will only exclude target
, exactly as that. Wherever it appears, though...
src/state.ts
Outdated
console.debug('glob took', new Date().getTime() - t0, 'ms'); | ||
const projectFilePaths = candidateUris.map((uri) => path.dirname(uri.fsPath)); | ||
const candidatePaths = [...new Set(projectFilePaths)]; | ||
console.log(candidatePaths); |
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.
It might be cool to make this console.log({candidatePaths})
so the log entry contents are labeled?
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.
TIL.
Wasn't intending to keep this logging in there, though. Except the timing of the glob, which could be good to be able to ask users about for a while.
src/state.ts
Outdated
? candidatePaths | ||
.filter((p) => docDir.startsWith(p)) | ||
.sort() | ||
.reverse()[0] |
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.
Nice! That's a good way to find the longest match 😄
src/config.ts
Outdated
@@ -161,6 +161,7 @@ function getConfig() { | |||
useDeprecatedAliasFlag: configOptions.get<boolean>('jackIn.useDeprecatedAliasFlag'), | |||
}, | |||
enableClojureLspOnStart: configOptions.get<boolean>('enableClojureLspOnStart'), | |||
projectRootsSearchExclude: configOptions.get<string[]>('projectRootsSearchExclude'), |
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.
Oh! I missed one thing! We should probably add a default here so that it satisfies the gods of strictNullChecks
:
configOptions.get<string[]>('projectRootsSearchExclude') ?? []
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.
Thanks. I used the default value signature of the get
:
configOptions.get<string[]>('projectRootsSearchExclude', [])
Does that also satisfy the rule? Less syntax to parse...
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.
ooooh, I didn't know about that one! I think that should fix it? and If not I can fix it later when i'm fixing null check things 😊
And generallt just clean up the logic some
@Cyrik : can you have a look at e356cfd and see if you think it is viable way to deal with the quick-pick menus in e2e tests? I didn't figure out a very nice way to select the correct sequence... I'd be awesome if @corasaurus-hex and @bpringe had a look as well. ❤️ |
I wonder why that |
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 this looks great! I love to see code improvements like this.
src/connector.ts
Outdated
let projectDirUri = state.getProjectRootUri(); | ||
if (!projectDirUri) { | ||
projectDirUri = await state.getOrCreateNonProjectRoot(context, true); | ||
} |
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.
it looks like getOrCreateNonProjectRoot
calls getProjectRootUri
internally, first thing, and returns it later. Could we ditch the getProjectRootUri
here and just call getOrCreateNonProjectRoot
on its own here? Or should we remove the getProjectRootUri
from getOrCreateNonProjectRoot
? Or just leave everything as-is?
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'll have to check and think. You are probably right. This has been somewhat cleaned up, but I might have missed this opportunity. Tomorrow, though, because right now too 💤 !
src/connector.ts
Outdated
if (!projectDirUri) { | ||
projectDirUri = await state.getOrCreateNonProjectRoot(context, true); | ||
} | ||
await state.initProjectDir(projectDirUri); |
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.
We add a .catch
to this function in connectCommand
, do we need one here?
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.
Iirc i added the one in connectCommand
because the user can do funny stuff with the menu. Here we don't allow that. But it could also go wrong because of non-validated glob patterns, so yes, we should have one here anyway. =)
src/utilities.ts
Outdated
@@ -547,6 +558,7 @@ export { | |||
logSuccess, | |||
getCljsReplStartCode, | |||
getShadowCljsReplStartCode, | |||
quickPickActive as quicPickActive, |
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.
Can we get rid of the as quicPickActive
here? We'll need to fix the references to it in the tests, too.
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.
No idea why this coercion is here... I'll ditch it!
❤️ When I tried to extract the find-root-paths stuff to a module named |
Co-authored-by: Brandon Ringe <[email protected]>
…morrow/calva into 1254-multiple-project-roots
🎉 |
Glob for all project roots in the workspace
Let the user pick if there are more than one
Changes the way we find the closest project root
Not using node fs module at all
Fixes #1254
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.npm run prettier-format
)npm run eslint
before creating your PR, or runnpm run eslint-watch
to eslint as you go).Ping @PEZ, @bpringe