-
Notifications
You must be signed in to change notification settings - Fork 120
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
Issue getting incremental updates to compile_commands.json to play nicely. #300
Comments
It doesn't actually watch for changes in an event-driven way, but rather looks for updates when the compile command is fetched (e.g. because the file has changed and we're reparsing it). So in effect, diagnostics will be updated the next time the file is edited, or when any file is saved (the latter in case the file you edited was a header included from other files). If you want to trigger this externally, I don't think there's a well-supported way. Sending a spurious didSave notification would probably do it (though not guaranteed for the future). I don't know if you can do that from another extension? A couple of caveats:
|
Thanks so much for explaining, really appreciate it. If I understand you correctly then the following should result in vscode displaying accurate diagnostics about the file: Assume there is no entry for
If this is the case maybe I can just cause the file to be saved instead restarting, though as you mentioned maybe the throttling could have some weird interaction with this.
Yep, good to know though. |
Perhaps it would make sense for clangd to support a "reload CDBs" message which an extension could invoke to trigger reloading CDBs without a restart? |
The save is not necessary - the edit will cause that file's diagnostics to be updated. BTW I checked the cache time, and we'll only check once every five seconds for a changed file.
Maybe, but I think we may need to see that it's a bit more widely applicable? IIUC for this case we'd need to:
|
Can we enable "clangd.onConfigChanged" back? In file: It seems that this.context.subscriptions.push(new ConfigFileWatcher(this.context)) When I removed the condition: And in file https://github.com/clangd/vscode-clangd/blob/master/src/clangd-context.ts: It worked fine for me, and the server refreshes all open files whenever compile_commands.json is changed Can we enable this config back? Because it fixes the problem for me at least Thanks |
I've done a bit of poking around to understand the history here. Summarizing my understanding and some notes:
So indeed the server-side functionality is better in some ways (when a change is detected, the server updates its state gracefully without going through the longer process of a restart), but also worse in some ways (detecting a change requires an edit or save of the file, it doesn't happen automatically if you're just reading the file). This downside was actually recognized when the
You're basically noticing this "mild regression". Given that the In the longer term, we should be able to get the best of both worlds by hooking up the server's graceful "hot reload" to be triggered by an actual file watcher. |
I agree enabling back config-file-watcher.ts would be a good idea (As an optional setting, the way it was before in the setting) |
Would you like to submit a PR? |
In the meantime, it seems there is no way to trigger clangd restart from the command line since it has to be done at clangd extension level, correct? |
Not that I can think of. Note that there is a patch fixing this at #688. It needs only minor updates, though I haven't heard from the patch author in a while. If you're interested, you're welcome to take it across the finish line. |
Note: "Bug" is probably the wrong term for this, "question" is likely better but I couldn't find a better place to ask.
My situation
I work on a very large c++ monorepo where generating
compile_commands.json
takes a long time so to give our devs a nicer experience we have utilities setup for generatingcompile_commands.json
incrementally (i.e. only for the files/libraries you're actively working with). I've built a small vscode extension that is able to, upon changing the build or opening new files, trigger these incremental updates tocompile_commands.json
.The Issue
If I open a new file that doesn't yet have an entry in
compile_commands.json
it will show all kinds of errors (as expected); however, after thecompile_commands.json
file is generatedclangd
/this extension doesn't seem to realize it has new information about the open file and re-evaluated it. Right now I just have my extension useclangd.restart
to fix this but I imagine there is a better way that is less disruptive.I'm not an LSP expert so was hoping someone here who is more familiar could advise on the right place for this fix. I've seen here and upstream that
clangd
(after 12+) does watchcompile_commands.json
so do I just need to issue a rpc call to clangd to ask it to re-evaluate open files?The text was updated successfully, but these errors were encountered: