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
x/tools/gopls: support something like compile_commands.json
#36995
Comments
I don't think this is feasible in the current architecture. We use the output of |
To clarify, the compile_commands.json file contains entries like this: (for C++)
Thus it is more than just a list of files. It is all information needed for full semantic analysis of all code that was compiled. For go, perhaps it would contain entries made up of things like the following:
From there, I assume it would be possible to derive further information that exactly matches the way the files were built by the build system.
In reality, our team is using Bazel :-) So eventually, I am sure gopls will work. My fear though is that there are other build systems. And that, even for Bazel, there may be quirks (like updates to Bazel, build system hacks, weird edge cases, etc.) that cause the support to be imperfect. In contrast, the above approach (in theory) cannot fail; the tool (e.g. clangd or gopls) has exactly the same information as the compiler. By definition, it cannot be missing any information or have the wrong information.
Yes, perhaps it would be possible to make a driver that reads a "compile_commands-like" file (for all go files that were compiled) and returns the relevant JSON. This issue was mainly just to ask whether the team has considered relying (directly or indirectly) on the actual compilation commands executed, and whether this seems like it may have advantages over relying on a driver for each build system? Could these drivers get details incorrect? Etc. |
Just to add a note to this. I ran into a hitch with sonarcloud not understanding cgo. A "compilation database" file would be one way to work around it. |
Almost three years had passed. I doubt gopls wants to change its architecture to support this now - cc @findleyr I am afraid
If you are looking for a way to produce compilation info, I am afraid that |
I think I misunderstood this ticket to be about generating rather than consuming a compile_commands.json. I have moved the sonar discussion to a new ticket - #56706 . That said surely the purpose of a language server protocol is to interface with other tools so have it cause something to generate something like a |
the scope of LSP is determined in its spec and I don't see how generation of I hope the discussion in the other issue helps you find a solution. I see |
Build systems such as CMake and Ninja can output a compilation database -- a
compile_commands.json
file that contains every command that was executed to compile each C++ source file.Bear intercepts process forking/creation to get the
compile_commands.json
from any build system, even those that do not natively support outputting acompile_commands.json
file.A
compile_commands.json
file can be used by Clang tooling, such asclangd
to get autocompletion, go-to-definition, etc. in editors like Vim, Emacs, and VSCode. The CLion IDE supports opening acompile_commands.json
file as a C++ project to get the usual autocompletion and refactoring features.The nice thing about
compile_commands.json
is that, regardless of your build system, you know that it must be possible to log each invocation of the compiler, and thus get acompile_commands.json
file, one way or another. Furthermore, regardless of the various project models or abstractions that various tools/IDEs/build systems come up with, you know it must be possible to get all the required information from each invocation of the compiler, and thus any tool should be able to import acompile_commands.json
file to create its project model.Is there any way that
gopls
could support using acompile_commands.json
file for golang (or a similar type of file that essentially is a log of every invocation of the go compiler)?Note: this could also be a good "source-of-truth" and useful for cross-checking other ways of getting the project model. I.e. log the actual invocations of the go compiler to build a project model; we should get the same project model when obtained via other means, like when relying on the standard GOPATH directory structure.
Note: the compilation database /
compile_commands.json
spec currently does not have fields for storing environment variables, which I assume would be required for go.The text was updated successfully, but these errors were encountered: