Skip to content

Commit 1bdf0b2

Browse files
committed
Correct the root directory when editing files in .lake/packages
The correct scope is the entire project it sits inside of.
1 parent fdc3ef4 commit 1bdf0b2

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

lsp/leanls.lua

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,16 @@ return {
169169
root_dir = function(bufnr, on_dir)
170170
local fname = vim.api.nvim_buf_get_name(bufnr)
171171
fname = vim.fs.normalize(fname)
172+
173+
local packages_dir
174+
local packages_suffix = '/.lake/packages/'
175+
do
176+
local _, endpos = fname:find(packages_suffix)
177+
if endpos then
178+
packages_dir = fname:sub(1, endpos - packages_suffix:len())
179+
end
180+
end
181+
172182
-- check if inside lean stdlib
173183
local stdlib_dir
174184
do
@@ -185,7 +195,8 @@ return {
185195
end
186196

187197
on_dir(
188-
vim.fs.root(fname, { 'lakefile.toml', 'lakefile.lean', 'lean-toolchain' })
198+
packages_dir
199+
or vim.fs.root(fname, { 'lakefile.toml', 'lakefile.lean', 'lean-toolchain' })
189200
or stdlib_dir
190201
or vim.fs.dirname(vim.fs.find('.git', { path = fname, upward = true })[1])
191202
)

spec/helpers.lua

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,13 @@ function helpers.wait_for_async_elements(iv)
9393
end
9494

9595
function helpers.wait_for_ready_lsp()
96+
local client
9697
local succeeded, _ = vim.wait(15000, function()
97-
local client = lsp.client_for(0)
98+
client = lsp.client_for(0)
9899
return client and client.initialized or false
99100
end)
100101
assert.message('LSP server was never ready.').True(succeeded)
102+
return client
101103
end
102104

103105
---Wait until a window that isn't one of the known ones shows up.

spec/lsp_spec.lua

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,11 @@ describe('LSP', function()
2929
assert.is.empty(vim.lsp.get_clients { bufnr = 0, name = 'leanls', _uninitialized = true })
3030
vim.cmd.close { bang = true }
3131
end)
32+
33+
it('uses project root dir for files in .lake/packages', function()
34+
vim.cmd.edit(fixtures.with_widgets:child '.lake/packages/Qq/Qq.lean')
35+
local client = helpers.wait_for_ready_lsp()
36+
local project_root = vim.uv.fs_realpath(fixtures.with_widgets._root)
37+
assert.is.same(project_root, vim.uv.fs_realpath(client.config.root_dir))
38+
end)
3239
end)

0 commit comments

Comments
 (0)