Skip to content

Language Server support

Many text editors support "Intellisense" (error reporting, smart autocompletion, formatting, linting) out-of-the-box with a language server client. Language Server Protocol is a protocol developed by Microsoft to facilitate creating tooling that are separate from editors — unlike in a traditional IDE where tooling is directly integrated into the editor.

Lite XL does not provide a language server client, but the functionality is available via the LSP plugin. In this article, we will discuss how to properly set up language servers for use with the plugin.

Installation

The LSP plugin can be installed like any other Lite XL plugins.

The LSP plugin depends on the widget and optionally lint+ and lsp_snippets plugin for rendering UI elements. When installing the plugin manually, you must also install these plugins as well.

To install LPM via the command line, run:

$ lpm plugin install lsp

To install LSP via Miq, add lite-xl/lite-xl-lsp into your config.plugins.miq.plugins:

local config = require "core.config"
config.plugins.miq.plugins = {
-- this allows Miq to manage itself
'TorchedSammy/Miq',

-- install lsp
'lite-xl/lite-xl-lsp',
}

Afterwards, run the command miq:install to begin installation.

To install the LSP plugin manually, run these commands:

$ cd ~/.config/lite-xl/
$ git clone https://github.com/lite-xl/lite-xl-lsp plugins/lsp
$ git clone https://github.com/lite-xl/lite-xl-widgets libraries/widget
$ git clone https://github.com/liquidev/lintplus plugins/lintplus
$ wget https://raw.githubusercontent.com/vqns/lite-xl-snippets/main/snippets.lua \
    -O plugins/snippets.lua
$ wget https://raw.githubusercontent.com/vqns/lite-xl-snippets/main/lsp_snippets.lua \
    -O plugins/lsp_snippets.lua

They install the plugin with all its dependencies.

Installing Language Servers

The LSP plugin requires languages servers to be installed on the system to function. Some editors such as Visual Studio Code and Neovim tends to have this process abstracted by plugins. Luckily, Lite XL provides commonly-used language servers as plugins as well, prefixed with lsp_.

PluginLanguage(s)ServerPlatforms
lsp_cC, C++, Objective-CclangdLinux, macOS, Windows
lsp_luaLuaLuaLSLinux, macOS, Windows
lsp_pythonPythonPyrightLinux, macOS, Windows
lsp_quicklintjsJavaScriptquick-lint-jsLinux, macOS, Windows
lsp_rustRustrust-analyzerLinux, macOS, Windows
lsp_texTeXtexlabLinux, macOS, Windows
lsp_zigZigzlsLinux, macOS, Windows

Manual Installation

The LSP plugin expects language servers to be accessible in PATH. If you have installed the language server from package managers such as npm and pip, please ensure that their local installation directory is in PATH.

Important

Even more care needs to be given to those who uses a node.js version manager such as nvm, as the npm prefix changes when switching node.js versions. You should always launch Lite XL after sourcing nvm (do this for any Lite XL's desktop entries as well).

Set Up

If you installed the language servers via plugins, then you should skip this step.

The LSP plugin provides default configuration for most language servers, based on nvim-lspconfig. These configurations are available by requiring plugins.lsp.config in your user module. For example, to configure typescript-language-server, you can do:

local lspconfig = require "plugins.lsp.config"

-- set up typescript-language-server with default configuration (enough for most people)
lspconfig.tsserver.setup()

-- override the default configuration
lspconfig.tsserver.setup {
    verbose = false
}

Features

After configuring your language server, you should see a log message in the form of [LSP] starting (language server name) followed by [(language server name)] Initialized when opening a file supported by the language server. These messages indicate that the language server is properly set up and is running for the document.

Enhanced Autocomplete

One of the most prominent features of a language server is to provide autocomplete suggestions. The LSP plugin integrates with the autocomplete plugin to provide this functionality.

lsp-autocomplete

Snippets

When installed with lsp_snippets, the LSP plugin is able to provide snippets from language servers. The snippets are also integrated with the autocomplete plugin.

lsp-snippets

Inline Diagnostics

When installed with lint+, the LSP plugin will show diagnostics on the affected lines. You can disable this with lsp:toggle-diagnostics (Shift+Alt+E).

lsp-inline-diagnostics

To view all symbols in a file, you can use lsp:view-document-symbols (Alt+S). You can use lsp:find-workspace-symbol (Shift+Alt+S) to find a symbol in the current workspace.

lsp-view-symbol lsp-search-symbol

Tooltips

You can hover on symbols to check their types and descriptions.

lsp-hover

Tooltips will also appear when entering function arguments.

lsp-args

Go to Definition

Press Alt+D to jump to definition.

lsp-goto-definition

Find References

Press Alt+F to find references to a symbol.

lsp-find-references

Document Formatting

Press Alt+Shift+F to format the current document.

lsp-format

Diagnostics

Press Alt+E to view diagnostics messages for the current document. Press Ctrl+Alt+E to view diagnostics messages for the workspace.

lsp-view-doc-diagnostics lsp-view-all-diagnostics

Troubleshooting

We are constantly updating the LSP plugin to fix bugs, add features and improve performance. If you encounter any issues, you should always update to the latest version before trying other steps.

Enable Debug Logging

If you encounter an error message such as [LSP] (language server name) was shutdown, revise your configuration, you should try to enable debug logging to see what is happening when the language server is run.

This is very useful on Windows as the plugin runs the language server with cmd.exe (to work around wrappers like those provided by npm) and this can cause errors to never propagate back to the plugin.

In your user module, add:

config.plugins.lsp.log_server_stderr = true

Navigate to the "Plugins" tab. Under the "Language Server Protocol" section, enable "Log Standard Error".

lsp-debug-logging

Language Servers not starting

There are many reasons why a language server will not launch, the most common being the plugin cannot find the language server in PATH.

On Windows, this often manifests as (language server name) is not recognized as an internal or external command, operable program or batch file.. The LSP plugin uses cmd.exe on Windows to launch the language server in order to work around different file extensions such as .cmd, .bat and .exe.

To solve this issue, make sure that the language server is on PATH. For non-native language servers (e.g. typescript-language-server), make sure their installation path with respect to the package managers are on PATH as well. For npm, this is usually AppData\Roaming\npm on Windows.

jdt.ls launches Microsoft Store

If you've installed jdt.ls from their website, you might run into issues where Microsoft Store is launched instead of running the language server properly.

jdt.ls seems to expect users to have Python installed, and Windows has app execution aliases built in to redirect python.exe and python3.exe to Microsoft Store.

win-execution-alias

To fix this, install Python. Alternatively, you can follow the instructions from jdt.ls to run the language server without Python at all.