philippejer / vala-language-server-alpha

Basic Vala Language Server
GNU Lesser General Public License v2.1
22 stars 1 forks source link

Basic Language Server for Vala (deprecated)

Note: this project is very loosely maintained, please use and contribute to this project which is actively developed. See paragraph below for more details on the state of Vala language servers.

About the state of Vala Language Servers (2019-11-27)

I have started this project around july 2019 because I could not find a working language server on my setup (VSCode and MinGW). This project from Ben Iofel seemed like a good starting point, so I have started modifying it with the intent of improving a few things (mostly wanted to get "go to definition" working correctly on my setup).

Since then, I have added quite a few features like basic completion support (in a very quick & dirty mode), and have been quite happy with the result. So I finally decided to publish it here in the hope that it would be useful to someone else.

However since then, two language server projects have seen a lot of activity:

I have not yet had the time to check these projects out and see at what stage of maturity they are. GVls in particular has seen a lot of activity recently and the code looks very clean and professional, also the author clearly has a lot of experience in the Vala/GNOME ecosystem.

Since I do not intend to develop this project much further (aside from simple bug fixes and maybe some experiments), I would strongly advise to look at these two projects first and only use this one if they do not work for you.

Prerequisites

Please note that this tool primarily targets VSCode as the client IDE and the project should ideally use Meson 0.50+ (the server will search for a valid meson-info/intro-targets.json file to determine the sources and compiler flags). It should also be built against a recent version of Vala (currently using version 0.46.3), since the Vala compiler API can change across versions (I have provided some step-by-step Ubuntu and MinGW-64 instructions below).

2019-10-20: A fallback is now available by adding a vala-language-server.json configuration file under the project root directory. This file will be detected and used to configure the list of sources files and/or directories and the compiler parameters (it is possible to simply copy the Vala compiler command line from e.g. compile_commands.json). An example configuration can be found here.

2019-11-14: Committed workaround for issue when starting Meson under Windows ("Meson did not return an array of targets...").

Description

This is a basic language server for the Vala language, which is relatively limited in scope and mostly tailored to my specific setup (see requirements). I do not intend to polish it much further, however it feels usable enough that I have decided to publish the source code (the current Vala IDEs seem very limited and/or obsolete).

I am actually quite happy with the results as initially I only intended to improve the code navigation from the original Vala language server (see background section for details).

Note: the code uses many hacks and tricks (especially completion related stuff), this is quite deliberate as making a language server has never been a goal in itself for me, I have mostly used it as an opportunity to learn the language from the inside.

Currently it has only been "tested" with a specific setup:

I have written a quick step-by-step guide on how to compile the language server starting from a vanilla Ubuntu distribution (18.04) and the same with MinGW-64 under Windows.

Supported language server features

Demo

The following features work reasonably well (for my requirements anyway):

Limitations and known bugs

Experimental compiler branch

Note that this branch contains a few experimental compiler switches (disabled by default), one in particular is a small modification of the parser to enable code navigation in the presence of trivial syntax errors like a missing semicolon (by default the syntax tree is not built in the presence of syntax errors).

The support of this "mode" in the compiler is detected by looking at the compiler version (see meson.build).

How to compile for Linux (tested with Ubuntu 20.04)

Quick steps on how to compile and setup everything (last tested with fresh install of Ubuntu 20.04 on 11 august 2020).

Install dependencies

Compile the language server

How to compile for Windows (MSYS2-MinGW-64)

The general steps are quite similar with MSYS2-MinGW-64 (this is actually my main setup).

Install MSYS2-MinGW-64

Install Meson

Vversion 0.50+ is required by the language server for build file introspection (there is also a fallback possible to use a plain vala-language-server.json file as explained above).

Compile and install Vala from source (optional)

This is only useful if the current Vala compiler provided by the package is too out-of-date (currently version 0.48.6 is already provided).

Compile and install json-glib

Important: a recent master branch of this library (after 2020-01-14) is required to compile the language server (see this commit for more info).

Compile and install jsonrpc-glib

Compile the language server

Install the client extension in VS Code

Terminal popup issue under Windows / MSYS2-MinGW-64

It is likely that you'll have some annoying terminal popup issues under Windows / MSYS2-MinGW-64.

A recent bugfix in the Vala compiler (https://gitlab.gnome.org/GNOME/vala/blob/2ad4a6e8a6c7bf6b2a9fd5d825ad639c420df489/vala/valasourcefile.vala) has had the side effect that the Vala compiler will now properly check the package versions (this is apparently used to check for things like deprecated APIs in VAPIs etc.).

The problem under MSYS2-MinGW-64 is that this requires a call to the shell with g_spawn () and since the language server is apparently seen by GLib as a UI application (as launched by VSCode anyway), GLib uses a "helper" to open a terminal and get the output of the command, which leads to these annoying terminal popups.

For now, my quick-and-dirty solution is to replace the non-console version of the helper with the console version of the helper with something like this (the call to the shell by the Vala compiler will still work for some reason):

cp /mingw64/bin/gspawn-win64-helper.exe /mingw64/bin/gspawn-win64-helper.exe.bak && cp /mingw64/bin/gspawn-win64-helper-console.exe /mingw64/bin/gspawn-win64-helper.exe

WARNING: this will probably many uses of g_spawn () (not really sure, I mostly use MSYS2 for Vala development currently). Maybe playing with the PATH variable when starting the language server from the IDE would allow to do this properly (?).

TODOs

Background

I have originally started this as a fork of this Vala Language Server (around june 2019), which did not seem actively developped at the time. Initially I only wanted to see if I could improve on a few things but ended up adding quite a few features (and many hacks...).

Since then it seems the original repository has seen much more activity and is quite ambitious, for example with the goal of adding a "language server" mode to the Vala parser to properly implement code completion instead of relying on ugly text-based hacks like here. This is not an attempt to replicate this effort, the goal of this project has only been to make it usable for my specific use case with no other ambition (although I believe it is good enough to be useful to someone else).