aboutsummaryrefslogtreecommitdiffstats
path: root/lua
diff options
context:
space:
mode:
authorMichael Lingelbach <m.j.lbach@gmail.com>2022-02-18 18:55:57 -0800
committerGitHub <noreply@github.com>2022-02-18 18:55:57 -0800
commit5b1ee3237a7952e7877765f1be077364d1639e6c (patch)
tree8d08335c509bb25ed62a067d65aa6fc7a18c08a5 /lua
parentdocs: update server_configurations.md (diff)
parentfix(leanls): move legacy_cmd -> options.non_lake_lsp_cmd (diff)
downloadnvim-lspconfig-5b1ee3237a7952e7877765f1be077364d1639e6c.tar
nvim-lspconfig-5b1ee3237a7952e7877765f1be077364d1639e6c.tar.gz
nvim-lspconfig-5b1ee3237a7952e7877765f1be077364d1639e6c.tar.bz2
nvim-lspconfig-5b1ee3237a7952e7877765f1be077364d1639e6c.tar.lz
nvim-lspconfig-5b1ee3237a7952e7877765f1be077364d1639e6c.tar.xz
nvim-lspconfig-5b1ee3237a7952e7877765f1be077364d1639e6c.tar.zst
nvim-lspconfig-5b1ee3237a7952e7877765f1be077364d1639e6c.zip
Merge pull request #1727 from Julian/leanls3
fix(leanls): only use lake serve if lakefile.lean exists
Diffstat (limited to 'lua')
-rw-r--r--lua/lspconfig/server_configurations/leanls.lua44
1 files changed, 29 insertions, 15 deletions
diff --git a/lua/lspconfig/server_configurations/leanls.lua b/lua/lspconfig/server_configurations/leanls.lua
index 924805eb..208598af 100644
--- a/lua/lspconfig/server_configurations/leanls.lua
+++ b/lua/lspconfig/server_configurations/leanls.lua
@@ -1,9 +1,5 @@
local util = require 'lspconfig.util'
--- Only Lake 3.0+ supports lake serve, so for old enough Lean 4,
--- we fallback to the builtin LSP.
-local legacy_cmd = { 'lean', '--server' }
-
return {
default_config = {
cmd = { 'lake', 'serve', '--' },
@@ -13,6 +9,12 @@ return {
fname = util.path.sanitize(fname)
local stdlib_dir
do
+ local _, endpos = fname:find '/src/lean'
+ if endpos then
+ stdlib_dir = fname:sub(1, endpos)
+ end
+ end
+ if not stdlib_dir then
local _, endpos = fname:find '/lib/lean'
if endpos then
stdlib_dir = fname:sub(1, endpos)
@@ -23,20 +25,32 @@ return {
or stdlib_dir
or util.find_git_ancestor(fname)
end,
+ options = {
+ -- Only Lake 3.0+ supports lake serve, so for old enough Lean 4,
+ -- or core Lean itself, this command (typically using the in-built
+ -- Lean 4 language server) will be used instead.
+ no_lake_lsp_cmd = { 'lean', '--server' },
+ },
on_new_config = function(config, root_dir)
- local lake_version = ''
- local lake_job = vim.fn.jobstart({ 'lake', '--version' }, {
- on_stdout = function(_, d, _)
- lake_version = table.concat(d, '\n')
- end,
- stdout_buffered = true,
- })
- if lake_job > 0 and vim.fn.jobwait({ lake_job })[1] == 0 then
- local major = lake_version:match 'Lake version (%d).'
- if major and tonumber(major) < 3 then
- config.cmd = legacy_cmd
+ local use_lake_serve = false
+ if util.path.exists(util.path.join(root_dir, 'lakefile.lean')) then
+ local lake_version = ''
+ local lake_job = vim.fn.jobstart({ 'lake', '--version' }, {
+ on_stdout = function(_, d, _)
+ lake_version = table.concat(d, '\n')
+ end,
+ stdout_buffered = true,
+ })
+ if lake_job > 0 and vim.fn.jobwait({ lake_job })[1] == 0 then
+ local major = lake_version:match 'Lake version (%d).'
+ if major and tonumber(major) >= 3 then
+ use_lake_serve = true
+ end
end
end
+ if not use_lake_serve then
+ config.cmd = config.options.no_lake_lsp_cmd
+ end
-- add root dir as command-line argument for `ps aux`
table.insert(config.cmd, root_dir)
end,