Skip to content

Commit 1a3a3f7

Browse files
committed
fix(mesonlsp): improved root detection
This commit enhances root directory detection of mesonlsp language server. Current behavior: root is set on first meson file user is opened New behavior: root is set to parent of meson.build with project function call
1 parent 8b0f47d commit 1a3a3f7

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

lsp/mesonlsp.lua

+26-1
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,33 @@
33
--- https://github.com/JCWasmx86/mesonlsp
44
---
55
--- An unofficial, unendorsed language server for meson written in C++
6+
7+
local meson_matcher = function(_, path)
8+
local pattern = 'meson.build'
9+
local f = vim.fn.glob(table.concat({ path, pattern }, '/'))
10+
if f == '' then
11+
return false
12+
end
13+
for line in io.lines(f) do
14+
-- skip meson comments
15+
if not line:match '^%s*#.*' then
16+
local str = line:gsub('%s+', '')
17+
if str ~= '' then
18+
if str:match '^project%(' then
19+
return true
20+
else
21+
break
22+
end
23+
end
24+
end
25+
end
26+
return false
27+
end
28+
629
return {
730
cmd = { 'mesonlsp', '--lsp' },
831
filetypes = { 'meson' },
9-
root_markers = { 'meson.build', 'meson_options.txt', 'meson.options', '.git' },
32+
root_dir = function(bufnr, on_dir)
33+
on_dir(vim.fs.root(bufnr, meson_matcher) or vim.fs.root(bufnr, '.git'))
34+
end,
1035
}

0 commit comments

Comments
 (0)