Skip to content

fix(mesonlsp): improved root detection #3775

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion lsp/mesonlsp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,33 @@
--- https://github.com/JCWasmx86/mesonlsp
---
--- An unofficial, unendorsed language server for meson written in C++

local meson_matcher = function(_, path)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

docstring should give an example of the line this is trying to find. shouldn't have to study the code to figure that out.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand what you mean, can you explain in more detail please?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
local meson_matcher = function(_, path)
--- Decides if a file is a meson file by looking for lines like:
--- "foo.bar" or "baz"
local meson_matcher = function(_, path)

replace "foo.bar" with an actual example

local pattern = 'meson.build'
local f = vim.fn.glob(table.concat({ path, pattern }, '/'))
if f == '' then
return false
end
for line in io.lines(f) do
-- skip meson comments
if not line:match '^%s*#.*' then
local str = line:gsub('%s+', '')
if str ~= '' then
if str:match '^project%(' then
return true
else
break
end
end
end
end
return false
end

return {
cmd = { 'mesonlsp', '--lsp' },
filetypes = { 'meson' },
root_markers = { 'meson.build', 'meson_options.txt', 'meson.options', '.git' },
root_dir = function(bufnr, on_dir)
on_dir(vim.fs.root(bufnr, meson_matcher) or vim.fs.root(bufnr, '.git'))
end,
}
Loading