lsp

pez 2025-08-21T07:53:01.201449Z

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?

borkdude 2025-08-21T07:59:18.933809Z

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?

👍 1
pez 2025-08-21T08:28:24.883119Z

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.

ericdallo 2025-08-21T11:43:27.283449Z

I believe clojure-lsp checks for that already, but maybe there is some improvement to be made

ericdallo 2025-08-21T11:43:45.095929Z

Exactly

ericdallo 2025-08-21T14:26:56.290399Z

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?

ericdallo 2025-08-21T14:27:09.312799Z

even so, pretty rare to happen that I believe

ericdallo 2025-08-21T14:27:16.224729Z

never faced that

pez 2025-08-21T14:30:41.866829Z

It is completely reproducible and happens all the time with Copilot. 😃

🤔 1
ericdallo 2025-08-21T14:31:26.602509Z

how/why copilot touches that?

pez 2025-08-21T14:32:34.008989Z

Copilot uses a VS Code built in tool for creating files. The tool takes a path and content as args.

ericdallo 2025-08-21T14:32:54.443759Z

got it, but it creates the file with a content right?

ericdallo 2025-08-21T14:33:07.973019Z

so clojure-lsp receives the did-open request with text, so it knows it should not add the ns

ericdallo 2025-08-21T14:33:37.424519Z

I tested that multiple times with #eca where it has tools to create files as well and never faced that

pez 2025-08-21T14:33:48.378279Z

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.

ericdallo 2025-08-21T14:41:34.964989Z

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

pez 2025-08-21T14:44:19.167059Z

Not following. I think this happens in the tool implementation, so there is no LLM roundtrip between creating the file and adding content.

ericdallo 2025-08-21T14:45:51.262109Z

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.

mikejcusack 2025-08-21T15:34:34.396239Z

Any assistance for my question above?

ericdallo 2025-08-21T15:39:16.700649Z

sorry, missed the message

👌 1