Skip to content

Commit 19273e5

Browse files
StamesJamesBenedict Christian Smit
andauthored
fix(leanls): migrate to vim.lsp.config #4084
Co-authored-by: Benedict Christian Smit <[email protected]>
1 parent ef73a4f commit 19273e5

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

lsp/leanls.lua

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
---@brief
2+
--- https://github.com/leanprover/lean4
3+
---
4+
--- Lean installation instructions can be found
5+
--- [here](https://leanprover-community.github.io/get_started.html#regular-install).
6+
---
7+
--- The Lean language server is included in any Lean installation and
8+
--- does not require any additional packages.
9+
---
10+
--- Note: that if you're using [lean.nvim](https://github.com/Julian/lean.nvim),
11+
--- that plugin fully handles the setup of the Lean language server,
12+
--- and you shouldn't set up `leanls` both with it and `lspconfig`.
13+
14+
---@type vim.lsp.Config
15+
return {
16+
cmd = function(dispatchers, config)
17+
local local_cmd = { 'lake', 'serve', '--', config.root_dir }
18+
return vim.lsp.rpc.start(local_cmd, dispatchers)
19+
end,
20+
filetypes = { 'lean' },
21+
root_dir = function(bufnr, on_dir)
22+
local fname = vim.api.nvim_buf_get_name(bufnr)
23+
fname = vim.fs.normalize(fname)
24+
-- check if inside lean stdlib
25+
local stdlib_dir
26+
do
27+
local _, endpos = fname:find '/lean/library'
28+
if endpos then
29+
stdlib_dir = fname:sub(1, endpos)
30+
end
31+
end
32+
if not stdlib_dir then
33+
local _, endpos = fname:find '/lib/lean'
34+
if endpos then
35+
stdlib_dir = fname:sub(1, endpos)
36+
end
37+
end
38+
39+
on_dir(
40+
vim.fs.root(fname, { 'lakefile.toml', 'lakefile.lean', 'lean-toolchain' })
41+
or stdlib_dir
42+
or vim.fs.dirname(vim.fs.find('.git', { path = fname, upward = true })[1])
43+
)
44+
end,
45+
}

0 commit comments

Comments
 (0)