[PATCH] D49267: [clangd] Watch for changes in compile_commands.json
Simon Marchi via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Jul 12 14:12:57 PDT 2018
simark created this revision.
Herald added subscribers: cfe-commits, jkorous, MaskRay, ioeric, ilya-biryukov.
This patch adds support for watching for changes to
compile_commands.json, and reparsing files if needed.
The watching is done using the "workspace/didChangeWatchedFiles"
notification, so the actual file watching is the frontend's problem.
To keep things simple, we react to any change involving a file called
"compile_commands.json".
The chosen strategy tries to avoid useless reparses. We don't want to
reparse a file if its compile commands don't change. So when we get a
change notification, we:
1. Save the compile commands of all open files on the side.
2. Clear everything we know about compilation databases and compilation commands.
3. Query the compile commands again for all open files (which will go read the possibly updated compile commands). If the commands are different than the saved ones, we reparse the file.
I updated the vscode-clangd extension. If you don't feel inspired, you
can use this small .cpp to test it:
#ifdef MACRO
#warning "MACRO is defined"
#else
#warning "MACRO is not defined"
#endif
int main() {}
and this compile_commands.json:
[{
"directory": ".",
"file": "test.cpp",
"arguments": ["g++", "-c", "test.cpp", "-DMACRO=2"]
}]
Adding and removing the "-DMACRO=2" argument, you should see a different
Repository:
rCTE Clang Tools Extra
https://reviews.llvm.org/D49267
Files:
clangd/ClangdLSPServer.cpp
clangd/ClangdLSPServer.h
clangd/GlobalCompilationDatabase.cpp
clangd/GlobalCompilationDatabase.h
clangd/ProtocolHandlers.cpp
clangd/ProtocolHandlers.h
clangd/clients/clangd-vscode/src/extension.ts
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D49267.155271.patch
Type: text/x-patch
Size: 11288 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180712/ea583164/attachment-0001.bin>
More information about the cfe-commits
mailing list