Using Nextflow Language Server in editors that support LSP but are not VSCode

Hi all,

First, just wanted to say fantastic work with the new VSCode language server. This is a game-changer for me and my lab’s productivity with the language, and will help shift us from Snakemake to Nextflow even more decisively.

I’ve become an avid user of the Helix editor and occasionally the Zed editor for collaborative editing, both of which support LSP out of the box. Would you have any advice on using the new Nextflow language server in these editors without going through the VSCode extension marketplace? In my perfect world, the language server would be installable through VSCode or a package manager like Homebrew or Nix, as language servers like Ruff are.

Thanks again for your great work!

–Nick

3 Likes

Update: I just saw this issue in the language-server repo, which addresses this exact question. I’ll post here again if and when I get a Helix and Zed configuration going for anyone who’s interested!

1 Like

Thanks so much for the kind words Nick! We passed your comments on to the team, and they were really excited to hear the language server is having a big impact on your lab’s producitivity. :smiley:

And thanks for being willing to report back on the Helix / Zed configuration if you get that to work!

Finally following up with my Helix configuration, which more or less exactly copies the configuration in this thread on GitHub.

Since the nextflow language server isn’t available on Homebrew or other package managers yet, your first step will need to be cloning the source and building it yourself with Gradle. As the README says, this will involve cloning the nextflow source too.

# download the source code
git clone https://github.com/nextflow-io/language-server.git

# change into the source root directory
cd language-server

# clone Nextflow repository
git clone https://github.com/nextflow-io/nextflow ../nextflow

# build language server
make

make assumes you have gradle installed. Once it has built, the language server can be run with java -jar build/libs/language-server-all.jar.

To make this accessible to Helix, I just put that a shell script called nextflow-language-server that looks like this:

#!/bin/bash

java -jar $HOME/language-server/build/libs/language-server-all.jar

After running chmod +x nextflow-language-server and placing it somewhere that’s on $PATH, it should be available to Helix (or whatever else).

In my Helix languages.toml, I can set it up like so:

[[language]]
file-types = ["nf", "nf.test", {glob = "nextflow.config"}]
auto-format = false
language-servers = ["nextflow-language-server"]
name = "nextflow"
grammar = "groovy"
scope = "source.nextflow"
comment-tokens = ["//"]
block-comment-tokens = { start = "/*", end = "*/"}
indent = { tab-width = 4, unit = "    " }

[language-server.nextflow-language-server]
command = "nextflow-language-server"

[language-server.nextflow-language-server.config.nextflow]
debug = true

[language-server.nextflow-language-server.config.nextflow.files]
exclude = [".pixi", ".git", ".nf-test", "work"]

[language-server.nextflow-language-server.config.nextflow.formatting]
harshilAlignment = true

(for anyone interested, my full Helix language config is here)

One of the more important lines is grammar = "groovy", which tells Helix to use the Groovy tree-sitter grammar for syntax highlighting. This only work if you’ve pulled and built available tree-sitter grammars with:

hx --grammar fetch
hx --grammar build

That should do it! In the near future, the Nextflow LS and a tree-sitter grammar will be available on package managers like Homebrew or Nixpkgs so folks don’t have to build source themselves, but for now, this system works!

1 Like

I’ve also attempted to write a similar setup for Zed, but it’s not working yet, with the key missing link being how to get tree-sitter grammar wired up correctly.

Here’s what I have so far in Zed’s settings.json:

    /// LSP setup for the language server
    "lsp": {
        "nextflow-language-server": {
            // in theory this calls the shell script I set up above
            "command": "nextflow-language-server",

            // probably an incorrect attempt to specify LS configs
            "config": {
                "nextflow": {
                    "debug": true,
                    "formatting": {
                        "harshilAlignment": true
                    }
                }
            }
        }
    },
    "languages": {
        "Nextflow": {
            "tab_size": 4,
            "preferred_line_length": 100,
            "format_on_save": "off",

            // plugging in the nextflow-language-server configured above here
            "language_servers": ["nextflow-language-server"]
        },
    }
1 Like

You can download the JAR from the releases page, no need to build from source

1 Like

Thanks @bentsherman - I will definitely use that moving forward!