-
Notifications
You must be signed in to change notification settings - Fork 59
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
Multi project (workspaceFolders) support #1549
Comments
FWIW, I think that running a single clangd instance for the entire workspace would be the approach that corresponds more closely with Eclipse CDT's current behaviour. The main reason is that this setup supports cross-project references, e.g. a function defined in one project (say a library) with call sites in another project (say an application). Even if the indexes are stored per project (next to each I appreciate that symbols with the same name in different projects pose a challenge, however I don't think this would be a new problem for CDT -- the current indexer struggles with this too (see for example bug 337583 and its numerous duplicates and linked bugs). Furthermore, I believe there is a path forward to improving the handling of multiple definitions in clangd, as described in #1101 (comment).
Clangd should be able to gather information about inclusion relationships during indexing (at least, for every file transitively included by some source file listed in
I'm not aware of anyone actively working on this, but as a feature specified in LSP, I think we are definitely open to contributions in this area. I do see the potential for |
Why should they know each other? If a project A uses files from project B, this should be stated in the the compile_commands.json of project A. A single clangd instance would be interesting when I think the use case that a header file has been opened by a hyperlink in the edited file is very common. Therefor clangd needs more context information. If clangd knows the origin, then their compile commands should be used. Is it correct that the LSP provides no information how a file has been opened? So the LS cannot determine if it has been opened by a hyperlink nor the origin? Edit: I checked the LSP documentation for linking. It seems that the server has no knowledge about the origin. The server is only informed about opened files. |
My recollection is that when searching for occurrences of a symbol, Eclipse CDT would return results across all projects in the workspace.
The compile_commands.json of project A will have include paths that point to the headers of project B, and thereby allow you to navigate to e.g. the declaration of a function in those headers. However, you would not be able to go from a use in project A to the definition of the function in project B (nor find references in project A starting from the definition in project B) without having some sort of merged view of the two indexes.
Clangd implements a heuristic today where it keeps track of the include graphs of all open files, and uses that to choose a compile command for headers included transitively from an open file. In the case of hyperlink navigation, the file containing the hyperlink is necessarily open, so this heuristic handles the scenario fairly well. Concretely, if you're in source file
|
@HighCommander4 Thank you for the fast reply!
I thought that the compile_commands.json has no entries for header files?
I assume that this case can be improved when working with |
I'm not referring to entries for header files, but rather flags in the compile commands for project A source files pointing to project B include directories like so: {
"directory": "/workspace/projectA",
"file": "/workspace/projectA/file1.cpp",
"command": "/usr/bin/gcc -I/workspace/projectB/include -c /workspace/projectA/file1.cpp"
} This would allow, even in a clangd-instance-per-project setup, for project A's clangd instance to open a header file located in However, opening the definition of such a function inside project B would only work in a setup where the two projects share a clangd instance.
Somewhat improved perhaps, but compile commands can also differ between files in the same project. We may be able to offer a heuristic solution where we choose the source file for which we received the most recent LSP message, which is very likely to be the one you're navigating from. |
Hi,
we are developing a LSP based C/C++ Editor for the Eclipse CDT platform. In Eclipse CDT it's common practise to work on several C/C++ projects simultaneously.
At this point we come into trouble with the current clangd design, which is, when I understand the comments here right, based on the assumption that a connected editor works with one project at the moment.
Now you could argue why don't you use one LS for the whole workspace, since clangd searches and uses the individual compile_commands.json file in the source directory path to determine the CDB. But this has several drawbacks:
A solution to determine the correct CDB for an external header file would be to fetch it from the origin file. This implies that clangd has the knowledge of hyperlinks from a source to an external header file, and from header to header. I'am not sure if the server can do that. If so, then the CDB from the origin file should be used. Otherwise this logic could be implemented in the client.
Are there any activities to support LSP workspace folders?
The text was updated successfully, but these errors were encountered: