A reimplementation of my Meson language server in Swift.
Sources/MesonDocs
directory due to ShareAlike)textDocument/didChange
notification, the entire tree is newly typechecked. ASTs without type annotations are cached.set_variable
/get_variable
with non-constant variable name will fail in more complex cases. See here for working patternssubdir
with non-constant subdir name will fail in more complex cases. See here for working patternsThe first version, written in Vala, had some code maintenance problems because basically everything was done in one file. I had the choice between untangling that mess or rewriting it as cleanly as possible. I have chosen the latter because I wanted to learn Swift.
I made a matrix channel: #mesonlsp:matrix.org Feel free to join in case you want to ask questions, get support or contribute.
sudo dnf install swift-lang libstdc++-static
sudo dnf install git vala meson gcc libgee-devel json-glib-devel gtk4-devel gtksourceview5-devel libadwaita-devel libpeas-devel template-glib-devel g++ libsoup3-devel
TBD: For the moment, just follow what the docker files do:
You can either download the file from the releases or build it yourself.
git clone https://github.com/JCWasmx86/Swift-MesonLSP
cd Swift-MesonLSP
swift build -c release --static-swift-stdlib
sudo cp .build/release/Swift-MesonLSP /usr/local/bin
Or you can use podman (Maybe even docker, but only podman is tested):
DOCKER_BUILDKIT=1 podman build --file Dockerfile --output out --no-cache .
# If you want to use Ubuntu as docker image
DOCKER_BUILDKIT=1 podman build --file Dockerfile.ubuntu --output out --no-cache .
This will place a file "Fedora37.zip" (Or Ubuntu22.04.zip) in the directory out
. It contains
two statically linked binaries. Copy Swift-MesonLSP
to /usr/local/bin
.
A debug build is provided, too. Just rename it from Swift-MesonLSP.debug
to Swift-MesonLSP
and copy it to the right destination.
git clone https://github.com/JCWasmx86/GNOME-Builder-Plugins
cd GNOME-Builder-Plugins
# The other plugins in the repo
# get disabled
meson -Dplugin_clangd=disabled \
-Dplugin_gitgui=disabled \
-Dplugin_icon_installer=disabled \
-Dplugin_scriptdir=disabled \
-Dplugin_shfmt=disabled \
-Dplugin_swift_templates=disabled \
-Dplugin_texlab=disabled \
_build
cd _build
# Don't do "sudo ninja install"
ninja -j $(nproc) install
Add this JSON to ~/.config/kate/lspclient/settings.json
:
{
"servers": {
"meson": {
"command": [
"Swift-MesonLSP",
"--lsp"
],
"rootIndicationFileNames": [
"meson.build",
"meson_options.txt"
],
"url": "https://github.com/JCWasmx86/Swift-MesonLSP",
"highlightingModeRegex": "^Meson$"
}
}
}
After that, a dialog should be shown asking you to confirm that the language server may be started.
Add this JSON to :CocConfig
:
{
"languageserver": {
"meson": {
"command": "Swift-MesonLSP",
"args": ["--lsp"],
"rootPatterns": ["meson.build"],
"filetypes": ["meson"]
}
}
}
Install this fork of vscode-meson: https://github.com/JCWasmx86/vscode-meson
On Fedora, you can use the install.sh
script. It will automatically install all dependencies. (It will ask you for
your root password using sudo
, but don't execute the script using sudo
)
Take an item from the TODO list in PROGRESS.md and work on it. Feel free to join the matrix channel #mesonlsp:matrix.org
The language server is measuring the duration needed by certain operations and exposes it using a HTTP-Server on http://localhost:65000
(Or any higher port, if 65000 is already used)
This picture shows an example of the rendered timing information. The project used is mesa and it
got fully parsed 35 times.
analyzingTypes
is the section in which all nodes of the AST are annotated with their possible type(s)sendingDiagnostics
is the section, where all diagnostics are sent back to the editor/clientrebuildTree
is responsible for clearing all diagnostics, parsing all meson files, annotating the types, sending the newdiagnosticsparsingEntireTree
is the section for parsing the entire project, patching the ASTs, etc.SelectionStatementTypeMerge
is part of the type analyzer. It is responsible for merging the possible types after different branches.patchingAST
is the section in which all subdir('foo')
calls are replaced by nodes referencing the corresponding source files.buildingAST
is the section in which the tree sitter nodes are converted to easier to use objectsparsing
is the section for just parsing a file using tree-sittercheckCall
is for checking the arguments of the call (Except type checking at the moment)clearingDiagnostics
is the section in that all diagnostics are cleared before rebuilding the tree.checkIdentifier
checks, if an identifier follows snake_case
guessingMethod
is a method that attempts to deduce the possible methods that are called on an any
object.evalStack
is responsible for getting types of variables that were overwritten in previous branches of selection statements.In this example, it took around half-second to parse the entire mesa meson files, deduce the types and emit diagnostics.
swift build -c release --static-swift-stdlib -Xswiftc -profile-generate -Xswiftc -profile-coverage-mapping
cp default.profraw /somedir
llvm-profdata merge -sparse default.profraw -o default.profdata
llvm-cov export --instr-profile default.profdata ~/Projects/Swift-MesonLSP/.build/release/Swift-MesonLSP -format lcov|swift demangle > out.lcov
genhtml --ignore-errors source out.lcov --legend --output-directory=/tmp/somepath
link |
Stars: 4 |
Last commit: 37 minutes ago |
compiler.get_id
, compiler.get_argument_syntax
, compiler.get_linker_id
, build_machine.cpu_family
and build_machine.system
against known values.Additionally, experimental Windows support was added. It is not tested as thoroughly as on Linux/macOS.
Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics