When creating files, Calva’s default clojure-lsp settings is to 'auto-add-ns-to-new-files?': true. This is great. However, when some API call create a file with content, things tend to be get messed up, with clojure-lsp’s edit being appended to the default content. I think there may be a timing issue and that VS Code add default content after the file is created, rather than write a new file with content. The race for editing the file after creation creates huge problems for AI agents. Can we think of some way to mitigate this?
Is there something like compare-and-swap! for files? lsp could check if it's really adding to an empty file, and if not, leave it?
clojure-lsp doesn’t edit content to files move into the project, so there is some distinction done there… It leads me to believe that clojure-lsp does check the content first, but that it may check it just in that gap in time before VS Code adds default content. But I am speculating.
I believe clojure-lsp checks for that already, but maybe there is some improvement to be made
Exactly
we actually https://github.com/clojure-lsp/clojure-lsp/blob/f5cab6c31c834e850f1b1993c6ff0cba78e0ae9d/lib/src/clojure_lsp/feature/file_management.clj#L26-L29on the text sent by client, I believe for this one we could slurp the uri again?
even so, pretty rare to happen that I believe
never faced that
It is completely reproducible and happens all the time with Copilot. 😃
how/why copilot touches that?
Copilot uses a VS Code built in tool for creating files. The tool takes a path and content as args.
got it, but it creates the file with a content right?
so clojure-lsp receives the did-open request with text, so it knows it should not add the ns
I tested that multiple times with #eca where it has tools to create files as well and never faced that
The end result should be a file created with content. But I suspect that VS Code will first create the file (triggering clojure-lsp) and then adds content.
humm interesting, even so, I beleive the time to a tool call happen from LLM would not be as fast as a message to clojure-lsp, but yeah, possible
Not following. I think this happens in the tool implementation, so there is no LLM roundtrip between creating the file and adding content.
hum, I see so it could be a bug in vscode-lsp impl, one way to confirm that is: check client<->server logs for did-open request of that file, what I believe it could be happening is: vscode is sending empty text but the file was actually created with content from LLM.
Any assistance for my question above?
sorry, missed the message