-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,8 +3,35 @@ | |
--- https://github.com/JCWasmx86/mesonlsp | ||
--- | ||
--- An unofficial, unendorsed language server for meson written in C++ | ||
|
||
---Checks if a given path contains a valid Meson project root file | ||
---Looks for 'meson.build' file which contains 'project()' function | ||
local meson_matcher = function(_, path) | ||
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 | ||
Comment on lines
+15
to
+23
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
seems to return "meson" even if the file doesn't contain "project", which isn't what you want here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For mesonlsp root_dir is required to be at folder with 'project' file. If root will be in different place all file will be underlined with red. I just take code from vala_ls which finds project root perfectly. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yeah, I'm trying to find more concise patterns so that we don't have to maintain 10x as much code in all of these configs. |
||
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, | ||
} |
Uh oh!
There was an error while loading. Please reload this page.