-
-
Notifications
You must be signed in to change notification settings - Fork 212
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
Adding ns form to a newly created clojure file #844
Comments
We need a way to collect all current source paths. |
Why are all source paths needed? |
Because to get ns form we need to build a relative path first. function resolvePackageName(sourcePaths: string[], filePath: string): string {
if (!sourcePaths || !sourcePaths.length) {
return "";
}
for (const sourcePath of sourcePaths) {
if (isPrefix(sourcePath, filePath)) {
const relative = path.relative(sourcePath, path.dirname(filePath));
return relative.replace(/[\/\\]/g, ".")
.replace("_", "-");
}
}
return "";
} In general, any directory under a clojure project could be a source path. There are at least two common ways to get source paths.
|
Today I made a prototype with a hardcoded source path. Works fine. |
Ah, so wherever the file is created you need to find the first parent folder that is a source directory (which probably would be the only in that path)? |
Right. |
Cursive and Emacs have this feature. It would be nice to have it in Calva too.
When I create a new clojure file, I'd like its ns form is created automatically. For example if a new file is
src/my_app/core.clj
, I'd expect to see(ns my-app.core)
in it.To do it we need to add a handler for
workspace.onDidCreateFiles
.https://code.visualstudio.com/api/references/vscode-api#workspace
Also the vscode-java extension already supports similar feature for java files.
The text was updated successfully, but these errors were encountered: