-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
No problems are shown for non-Cargo projects #15963
Comments
This is expected behavior, yes. |
I humbly suggest to clarify this in the docs, I spent quite a bit of time thinking the issue was on my end. On another note, is there any way I can make this work? Lots of people using Meson, probably, so maybe there's some workaround already in place? |
Could rust-analyser use compile_commands.json for that? |
Example of what you get in that file when using Meson to build Mesa rust code:
|
There is also the issue of whether rustc can itself emit JSON or if this is something done by Cargo |
Pretty sure it can: https://doc.rust-lang.org/rustc/json.html, unless that's not what RA needs? |
Sorry, was (correctly) yanked away from the computer by my spouse over the holiday.
Probably not a bad idea.
I've never used Meson before, but a decent chunk of my dayjob is supporting using rust-analyzer with buck2. Depending on whether Meson requires you to specify a build target for each command or not (where buck/bazel is an example of the former and Cargo is an example of the latter), you might be able to make use of the
@xclaesse I'm assuming that you're referring clangd's
Yes, that is the output that rust-analyzer expects from the build system/compiler. |
Yes, that file is created by Ninja (and thus meson, but also cmake) and is used for example by vscode C/C++ analysers. I think it would be a nice addition for rust-analyser to use the same file, it's somewhat "the standard". My understanding is it should be pretty easy to find the rustc command from that file and just append |
Seems there is already request to support that db in buck2 as well: facebook/buck2#194. |
While it is certainly the standard in C++, I don't believe it's the standard. At the risk of coming off as being afflicted with NIH, I think that any build system integration into rust-analyzer would either take the form of collaborating with a companion extension (such as a
For Meson? I don't know. If it possible to do a In the future, Meson could emit a
For what it's worth, my colleagues already make use of the compilation database in C++ with some FB-internal rules. The request there is to add the same functionality in the open source release, but because C++ toolchains at FB are, uh, complicated, that hasn't happened yet. Footnotes
|
Nothing against creating new format if it can be justified. However, it's not clear why RA cannot work that way in this case, that seems pretty easy and would give a build system independent solution. Why do you even want to go through
That's fine, you don't need to extend rust-project.json format. All you need to do is cross checking with compile_commands.json to find the missing information: rust-project.json: "root_module": "/home/xclaesse/programmation/mesa/src/gallium/frontends/rusticl/mesa/lib.rs", compile_commands.json: "directory": "/home/xclaesse/programmation/mesa/builddir",
"command": "rustc ...",
"file": "../src/gallium/frontends/rusticl/mesa/lib.rs", From root_module, you find the command (you need to join "directory" and "file" for matching), append |
Note that I'm a dev of vscode-meson, that's exactly why I'm trying to see how this could be done. meson itself does not support adding |
We generally don't want to implement a build system into rust-analyzer (using compile commands would still involve figuring out what needs to be rebuilt in what order when things change, etc.). The whole check-on-save functionality is just a stopgap while RA doesn't emit most diagnostics natively yet. A wrapper script called from |
That's a valid concern. I think in C/C++ case it just assume that dependencies are up to date, which is reasonable for a check when saving a single file in the editor.
What I'm suggesting would be a build system agnostic solution, specifically for not having to add support for different build systems.
I'm not sure what can be done at vscode-meson extension level. Can |
Another use-case for using compile_commands.json is the Linux kernel, I got told. |
At the risk of overexplaining, this is not sufficient for Rust. All dependencies of a file need to be built first in order to get meaningful diagnostics. That's why I strongly recommend running
How difficult would it be to change this behavior in Meson? |
Which is not different from any language, rust has nothing special here. In C you can also have generated headers as dependency, until you build them you'll get some diagnostic errors. I agree it's not optimal, but it's already a nice first step. To build dependencies, you would have to first call ninja with the "output" value of compile_commands.json to build it with it's deps. Then you can run the rustc command with the extra
That's just not possible at all. Meson generates a ninja file which contains every commands to run and their dependencies. It won't be able to add |
If I'm understanding what you're saying correctly, the diagnostics will not be functional or useful to users, requiring them to have a deep understanding of the build system to resolve said issues. In my personal view and experience, that is a non-starter and I strongly recommend that you do not go down this path.
Is your vision that rust-analyzer would do this on the user's behalf, or...? For what it's worth, when I referred to a companion extension, the thinking was that instead of sending the flycheck parameters to the language server, they would instead be sent to extensions—such as
Why would this not be possible? I'm sorry, I'm trying to determine what the specific blocker is on Meson/Ninja. I ask because the diagnostic parsing machinery in rust-analyzer will attempt to read |
To add to this in regards to current cargo check running for diagnostics. We might consider in the future to remove that from rust-analyzer, moving it out into a separate extension that can hook into the rust-analyzer extension to fetch the information required to run |
Is clicking the build button, or running Not saying this is ideal, we certainly can do better with a little bit of build system integration, but I don't see why that would be a showstopper.
I'm not sure to understand, I'm not expert in vscode extensions. Does that mean that extensions can talk to each other via some API? If RA can tell vscode-meson extension "compile $file and return me the json" then that's something we can definitely work in our side. I still believe it would be better done in RA itself because that would work for other build systems instead of duplicating the work in many extensions, but we can definitely at least experiment first in vscode-meson side.
Meson generates a ninja file which is similar to a Makefile, a serie of rules and commands to run. Rust targets commands won't have But to be fair, maybe I'm misunderstanding what needs to be done. Correct me if I'm wrong but I think the sequence of events is something like that:
When using Meson, or any other build system than Cargo, I think something like that needs to happen:
Steps, 4 is indeed build system specific and RA would probably need a command to run in its settings. Step 5 is actually pretty agnostic to the build system if we rely on largely adopted compile_commands.json format, and thus would be better done in RA to avoid code duplication, especially since it involves editing a rustc command line which is much more RA's domain. Also spawning a new command wrapper each time means re-parsing compile_commands.json every time, while that could be cached if done in the extension. If I misunderstood something, please explain what you think should happen. |
Hi there,
No
problems
are shown when using RA for non-Cargo projects in VScode. My linkedProjects points to a validrust-project.json
file, and other features are working (hints, code completion, etc).I tried debugging RA and apparently
CargoActor::run
expects the command to output some kind of JSON as per the documentation. The problem is that my project is being built by Meson/Ninja, and thus, whatever JSON is expected is simply not produced by these tools.Is this expected behavior? I was under the impression that the whole point of
rust-project.json
was to cater to non-Cargo projects and that RA would manage to invokerustc
and then parse whatever compilation errors on its own.The text was updated successfully, but these errors were encountered: