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

Does not find system or local VAPIs #293

Open
rrthomas opened this issue May 27, 2023 · 7 comments
Open

Does not find system or local VAPIs #293

rrthomas opened this issue May 27, 2023 · 7 comments
Labels

Comments

@rrthomas
Copy link

rrthomas commented May 27, 2023

Describe the bug

I am fairly new to VLS/vala-vscode (I was trying them in Codium to upgrade my Vala editing experience).

I cannot see where the VAPI path is set: I can't find any sort of configuration or command-line option I could be passing to vala-language-server.

I am getting warnings from Codium that "Posix" cannot be found, which baffles me, as of course it is installed as part of Vala; and there's no problem finding "GLib":

The namespace name `Posix' could not be found

Also, a few VAPIs in the same directory as my source code are not found.

After some more research, I tried turning on debug in VLS, which gave me the following:

(vala-language-server:2227031): vls-DEBUG: 22:00:02.724: girdocumentation.vala:50: adding GIR GLib-2.0 for package glib-2.0
(vala-language-server:2227031): vls-DEBUG: 22:00:02.724: girdocumentation.vala:50: adding GIR GObject-2.0 for package gobject-2.0

It does not find any other GIR information, and I notice that it only seems to find namespaces mentioned in GIRs, not in VAPIs. I also found this issue: #220 but the symptoms I am getting are not the same: my Vala source file is being built, just VLS is not (apparently) finding the namespace information.

Software
OS and version (e.g. Ubuntu 20.04): Ubuntu 22.04
Code editor (e.g. VSCode): Codium
Vala Language Server (e.g. git commit, or PPA/AUR version): 3b5fe94
Vala version (valac --version): 0.56.0

To Reproduce
Source code repo: https://github.com/rrthomas/mmv/tree/vala

Steps to reproduce the behavior:

  1. Open the workspace
  2. Go to mmv.vala.
  3. See errors in Problems pane.

Thanks very much for VLS! I already did some useful refactoring.

@rrthomas rrthomas changed the title Does not find my VAPIs Does not find system or local VAPIs May 27, 2023
@Prince781
Copy link
Member

VLS needs a way of understanding your project's compiler flags and we get this through meson.build or compile_commands.json. Makefiles aren't currently supported.

@rrthomas
Copy link
Author

Thanks; did I miss that being documented somewhere?

Also, that doesn't explain to me why VAPIs installed with the compiler (like Posix) are not found.

@Prince781
Copy link
Member

Without compiler flags, libvala doesn't know whether you're using Posix profile, so the VAPI won't be included. In this case, the errors you see should be exactly the same as if you ran valac on the file with no other arguments.

@Prince781
Copy link
Member

Prince781 commented May 27, 2023

Thanks; did I miss that being documented somewhere?

It may not be documented as well as it could be:

- [ ] supported projects
- [x] meson
- [x] `compile_commands.json`
- [x] Vala script (file beginning with `#!/usr/bin/env -S vala` shebang)
- [ ] cmake
- [ ] autotools

https://github.com/vala-lang/vala-language-server/blob/master/README.md#editors

We try to emit warnings in your editor if we can't find your compiler args. This could be improved:

if (backend_project == null) {
var cmake_file = root_dir.get_child ("CMakeLists.txt");
var autogen_sh = root_dir.get_child ("autogen.sh");
if (cmake_file.query_exists (cancellable))
show_message (client, @"CMake build system is not currently supported. Only Meson is. See https://github.com/vala-lang/vala-language-server/issues/73", MessageType.Warning);
if (autogen_sh.query_exists (cancellable))
show_message (client, @"Autotools build system is not currently supported. Consider switching to Meson.", MessageType.Warning);
} else {

@rrthomas
Copy link
Author

Ah yes, good point about the compiler flags. Thanks for the documentation pointers. Is there some way I can pass the compiler flags to VLS manually? (So then I could set them in my Codium workspace, potentially.)

@Prince781
Copy link
Member

Prince781 commented May 28, 2023

Is there some way I can pass the compiler flags to VLS manually?

You can write your own compile_commands.json file and stick it in your project root. But you might find that a bit cumbersome.

Outside of switching to Meson (which is what the vast majority of Vala projects use), this would be a feature request. I can think of a few possibilities:

  1. Add the ability to pass options in the vscode plugin. Downsides: doesn't help users of other IDEs.
  2. Support a valac_flags.txt file like what clang does. Downsides: isn't very robust and will only work with very simple projects.
  3. Add a flag to valac to spit out a compile_commands.json when run. So you can just add -gencc to your build script. Downsides: as this would be an upstream change, it wouldn't solve your problem until the next Vala release.
  4. Add a new project backend for Autotools. Downsides: this is likely far more complicated than analyzing Meson, since Autotools lacks an introspection API. We already have to use a lot of hacks for Meson. It's do-able, just a lot of work that won't benefit most projects.

@rrthomas
Copy link
Author

rrthomas commented May 28, 2023

Something simple would be nice, like 2. In this case I would have been quite happy to write a quick per-project config file, and have that minor maintenance burden. I think at this stage there probably won't be many new autotools Vala projects (although automake has good Vala support).

You might be interested to know that in the end I decided to use Python instead of Vala for this project: I started translating C into Vala, but while this was as easy as ever, I realised that in this case it would be no harder to rewrite the code from scratch than to translate some highly-involved C into "good" Vala (translating it into "bad, C-style" Vala would be easy, but not great progress). The final choice (of Python), was just because I am more familiar with writing this kind of (command-line, POSIXy) code in (typed) Python right now, and I find it quicker to write than Vala.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants