vala-lang / vala-language-server

Code Intelligence for Vala & Genie
GNU Lesser General Public License v2.1
291 stars 43 forks source link

CMake support #73

Open LecrisUT opened 4 years ago

LecrisUT commented 4 years ago

I am trying to get a homebrew + VS Code setup to work. So far I have managed to install the server. I am not sure how to run vls-testclient to confirm the installation was successful or not.

Running VS Code I get the following errors (trimmed down for readability, hope I didn't miss something important):

vls: compilation.vala:60: dirty context, rebuilding
Error: `null' is not a supported generic type argument, use `?' to box value types
...
vls: main.vala:415: [initialize] failed to add `/usr/local/share/vala-0.48/vapi/gobject-2.0.vapi' to shared_vapis: file:///usr/local/share/vala-0.48/vapi/gobject-2.0.vapi is already in the compilation
...
vls: girdocumentation.vala:43: could not enumerate file:///usr/share/gir-1.0: Error opening directory '/usr/share/gir-1.0': No such file or directory

...
(process:29345): vala-CRITICAL **: 12:03:07.305: vala_source_reference_construct: assertion '_file != NULL' failed
...
glib-2.0.vapi:35.1-35.18: error: The root namespace already contains a definition for `bool'
note: previous definition of `bool' was here
...

The cross-reference barely works, and it doesn't seem to reference different files in the workspace. Let me know if you need any more debug information or testing

Prince781 commented 4 years ago

I am not sure how to run vls-testclient to confirm the installation was successful or not.

Right now you don't have to worry much about this. We will be using it later as we develop tests for VLS. If you're curious you can run ./vls-testclient --help to find usage.

The cross-reference barely works, and it doesn't seem to reference different files in the workspace.

Sorry, could you explain this more? Are you saying that clicking "goto references" doesn't list all references in the project? Or something else?

LecrisUT commented 4 years ago

Sorry, could you explain this more? Are you saying that clicking "goto references" doesn't list all references in the project? Or something else?

Here's an example from pdfpc which I want to get it to work with: pdfpc.vala

namespace pdfpc {
    public class Application: GLib.Object {
        private PresentationController controller;
        ...

The class PresentationController is not recognized:

{
    "resource": "/***/pdfpc/src/pdfpc.vala",
    "owner": "_generated_diagnostic_collection_name_#2",
    "severity": 8,
    "message": "The type name `PresentationController' could not be found",
}

Even though there is a file: presentation_controller.vala with

namespace pdfpc {
    public class PresentationController : Object {
    ...

Go to reference, peek, nothing works, since intellisense cannot pick it up. This is not limited to local definitions. For example Gtk is not recognized either, even though it is installed with homebrew.

With C files I am able to add the paths to c_cpp_properties.json, and it can take me to the lib files. Is there an equivalent for vala?

Prince781 commented 4 years ago

@LecrisUT Ah! Is this your project: https://github.com/pdfpc/pdfpc ?

It looks like this project is CMake-based, which is a backend we intend to support in the future but don't currently. At first, we've chosen to support Meson, since the vast majority (perhaps >90%) of Vala projects use Meson, and the rest almost all use automake/autoconf. This in fact is the first Vala project I've seen that uses CMake, and this will be a useful test-case for when we're implementing CMake support.

If VLS can't detect a meson project, it will simply treat every folder as a separate compilation unit, so this is probably why you're not seeing references to files across different directories.

LecrisUT commented 4 years ago

Ok. I've confirmed that it does work like that for local files. So I guess the gtk libraries are not found because they couldn't be resolved from cmake?

I have tested benwaffle/vala-starter. It does indeed take me to the appropriate links when using meson.

Prince781 commented 4 years ago

@LecrisUT yes, without knowledge of compile arguments, the libraries you need will not be included.

Prince781 commented 4 years ago

It looks like this is how we can introspect a CMake project in a similar fashion to what we do for Meson: https://cmake.org/cmake/help/latest/manual/cmake-file-api.7.html

Cogitri commented 4 years ago

@LecrisUT yes, without knowledge of compile arguments, the libraries you need will not be included.

Wouldn't it be possible to just use compile_commands.json ? That should work for both meson and CMake (and possibly for future build systems too).

Prince781 commented 4 years ago

@Cogitri no, because compile_commands.json only includes compile commands, not things like g-ir-scanner or build tasks that convert .in files, or other things, which produce all sorts of files that may be fed into Vala targets.

Prince781 commented 4 years ago

Basically, there's a lot of useful information left out in compile_commands.json files that you need to get more than just a basic project with a few files to work.

Prince781 commented 3 years ago

It seems that Vala projects using CMake rely on unofficial macros from here: https://github.com/jakobwesthoff/Vala_CMake/

CMake's file API allows a program to get the list of targets and their sources in a JSON file. The unofficial Vala CMake macros above use add_custom_command() to create a valac task but it turns out you need to use add_custom_target() since that will register it as a target so it will be visible in the introspection JSON. Otherwise it's impossible to introspect.

I've made some initial changes to these macros here. This seems to work with a single Vala target, but I want to see how this works with multiple Vala targets: in particular, whether we can get the JSON output in such a way that the dependency graph can be reconstructed.

Prince781 commented 3 years ago

Also, it would help to know of more Vala projects that use CMake. pdfpc seems like the only one I could find.

Prince781 commented 3 years ago

If pdfpc is the only major Vala codebase that uses CMake, perhaps it would be better to encourage they switch to Meson.

Prince781 commented 3 years ago

Hmm... it looks like Dino, another very popular (1.5k stars) project, uses CMake too.

chances commented 3 years ago

Though not anymore, the elementary OS project's Vala applications were built with CMake. Many projects on GitHub use CMake (code search for the "FindVala" CMake module).

Prince781 commented 3 years ago

@chances most of those projects are dead, save a handful.

chances commented 3 years ago

That doesn't mean none of them will be revived in the future.

Prince781 commented 3 years ago

@chances well I still have to prioritize support for the things that people are currently using. If and when what you said happens, then CMake will become a higher priority.