Skip to content
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

clangd requires manual restart after changes to project settings. #185

Open
ReinhardKeil opened this issue Jan 31, 2025 · 4 comments
Open
Assignees
Labels
enhancement New feature or request

Comments

@ReinhardKeil
Copy link
Collaborator

ReinhardKeil commented Jan 31, 2025

Currently it is required to execute manually "clangd: Restart Language Server" in the following situations:

  1. A change to .vscode/settings.json:

    "clangd.arguments": [
           "--compile-commands-dir=c:\\Test\\Jan10\\M410_Adc\\ARM\\out\\M410_Adc\\Target_1"
       ]
    }
    
  2. A change to the file compile_commands.json that is reference by the .vscode/settings.json. These modifications are the generated by cbuild setup that is called when csolution project files change.

Proposal

Trigger automatically "clangd: Restart Language Server" (clangd.restart) when clangd.arguments or file compile_commands.json change.

@ReinhardKeil ReinhardKeil added bug Something isn't working enhancement New feature or request and removed bug Something isn't working labels Jan 31, 2025
@JonatanAntoni JonatanAntoni moved this from Backlog to In progress in CMSIS Solution Extension Feb 6, 2025
@JonatanAntoni
Copy link
Member

JonatanAntoni commented Feb 6, 2025

I'd not expect these files to be modified manually. I.e., no need to put file watches on them. Instead, I can see that these files are repeatedly updated, e.g., by/after cbuild setup.
Doesn't clangd auto-detect changes to its compile_commands.json? If yes, could this be seen as a shortcoming/bug in the clangd extension? Hence, any addition at our end would be a workaround.

What is the test case to replicate the issue and verify a potential fix?
We need to check the version of clangd used. On my Mac I have installed AppleClang 16 and the clangd is taken from this installation.

Relates to: clangd/vscode-clangd#681, clangd/vscode-clangd#300, clangd/vscode-clangd#116

Some aspects we need to check are documented in these issues:

  • in any case checks for changes to compile_commands are throttled to ~1/5sec. So if you try to force a check, you can be unlucky: check + overwrite compile_commands + force attempt in quick succession will not see the change
  • hopefully you're generating the new file into a new location and renaming: bad things may happen if we see a half-written file
  • Restarting the server is kind of a crude way to react to a change, because it comes with a potentially non-trivial performance penalty:
    • the project's index has to be reloaded from disk, and its in-memory representation rebuilt
    • preambles for all open files have to be rebuilt, not just files whose compile command changed
  • In clangd 12, "hot reload" of compile_commands.json was implemented on the server side.

@JonatanAntoni JonatanAntoni moved this from In progress to Backlog in CMSIS Solution Extension Feb 6, 2025
@JonatanAntoni
Copy link
Member

@brondani: Please check the above statement

hopefully you're generating the new file (compile_commands.json) into a new location and renaming: bad things may happen if we see a half-written file

@brondani
Copy link
Collaborator

hopefully you're generating the new file (compile_commands.json) into a new location and renaming: bad things may happen if we see a half-written file

The final location is the output directory which is always the same, but it is done with the CMake command ${CMAKE_COMMAND} -E copy_if_different which should be reasonably solid and does not touch the file when there are no changes.

@ReinhardKeil
Copy link
Collaborator Author

This needs more review from my side.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: Backlog
Development

No branches or pull requests

3 participants