omp packages

pi-nvim-lsp0.1.0

Pi uses the language servers, file types and settings from your Neovim configuration.

xeind Published 3 hours ago MIT ~0 downloads/mo

Untested on omp

This is a pi package. No one has reported whether it works on omp yet. If you try it, add your result below.

Did it work for you?

Result

One report per person. A new report replaces your old one.

Reports 0

No reports yet.

Readme

pi-nvim-lsp

Pi uses the language servers and formatters from your Neovim configuration. You set a server up once, in Neovim, and Pi gets it too: the same servers, settings and file types, started from wherever Neovim finds them (Mason, your PATH, a project's node_modules).

What Pi gets

Tool What it does
lsp_diagnostics Errors and warnings for a file, from every server Neovim attaches to it
lsp_hover Type and documentation for a symbol
lsp_definition Where a symbol is defined
lsp_references Every reference to a symbol across the project
lsp_symbols Outline of a file
nvim_format Formats files with your conform.nvim formatters and saves the ones that changed

After each edit or write, Pi adds up to ten language server errors for that file to the result, so the model sees a broken build at once. Servers start on first use, one per project root, and stop when the session ends.

/nvim-lsp lists the servers read from Neovim and the ones running. /nvim-lsp refresh reads the Neovim configuration again.

Requirements

  • Neovim 0.11 or newer on PATH.
  • The servers your configuration enables, installed by Mason or on PATH. Mason's bin folder is added to Pi's PATH ($MASON/bin when $MASON is set).
  • For nvim_format: conform.nvim in your configuration, and the formatters it names installed.
  • Tested on macOS with lazy.nvim. Linux should work the same way.

Install

git clone https://github.com/xeind/pi-nvim-lsp ~/dev/pi-nvim-lsp
cd ~/dev/pi-nvim-lsp && npm install

Then add the folder to packages in ~/.pi/agent/settings.json. A relative path is read from ~/.pi/agent:

{ "packages": ["../../dev/pi-nvim-lsp"] }

Run /reload in Pi, or start a new session.

How it works

The first time Pi needs a server, the extension starts a headless Neovim with your own configuration and asks it which servers it would start: everything vim.lsp.is_enabled reports (from vim.lsp.config, lsp/*.lua files or mason-lspconfig) and servers set up with nvim-lspconfig's older require("lspconfig").<name>.setup{}. Plugins that load when a file opens are loaded first. File types come from Neovim's own tables, including whole file names such as .bashrc, and a .sh file follows its #! line as in Neovim, so a zsh script does not go to bashls. Pi then runs the servers itself, with the settings Neovim would send.

nvim_format starts one headless Neovim for a batch of files, opens each, and runs require("conform").format().

Neither run may install anything. During the export no process may start at all; while formatting, formatters may run, but installers (npm, curl, cargo and the like) may not, and git may read but not clone, fetch or check out. Your plugin lockfile and Mason folder stay as they are. A configuration can test vim.g.pi_nvim_lsp_export or vim.g.pi_nvim_lsp_format to skip work during these runs.

The export takes about half a second for a configuration with 14 servers.

Limits

  • Code that only runs inside Neovim does not reach Pi: on_attach hooks, and root_dir functions. Pi finds a project root from the server's root_markers; servers set up with lspconfig's older setup{} have none and use Pi's working folder.
  • Diagnostics come from language servers only, not from linters that run through none-ls.
  • Formatting needs conform.nvim; formatting through a language server is not supported.

Related

@inobit/pi-nvim does this the other way round: it keeps a headless Neovim running and asks it for diagnostics and formatting, so it sees everything Neovim attaches, none-ls included. It runs on Linux only.

Development

npm run check   # typecheck, unit tests, and integration tests against real Neovim configurations

The integration tests need Neovim 0.11+. The language server tests also need typescript-language-server and lua-language-server; the tests that load nvim-lspconfig or conform.nvim from lazy.nvim's folder skip when it is missing.

License

MIT