diff options
| author | Alex <47825679+SpikedPaladin@users.noreply.github.com> | 2025-04-28 16:13:15 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-04-28 06:13:15 -0700 |
| commit | 48003b3dec9305b9ae900c967c0c8b72bb14c5c9 (patch) | |
| tree | abbc986ad03e2e2bcdf739086e0c92a180d4e216 /lsp/mesonlsp.lua | |
| parent | fix(eslint): check nil before on_dir #3800 (diff) | |
| download | nvim-lspconfig-48003b3dec9305b9ae900c967c0c8b72bb14c5c9.tar nvim-lspconfig-48003b3dec9305b9ae900c967c0c8b72bb14c5c9.tar.gz nvim-lspconfig-48003b3dec9305b9ae900c967c0c8b72bb14c5c9.tar.bz2 nvim-lspconfig-48003b3dec9305b9ae900c967c0c8b72bb14c5c9.tar.lz nvim-lspconfig-48003b3dec9305b9ae900c967c0c8b72bb14c5c9.tar.xz nvim-lspconfig-48003b3dec9305b9ae900c967c0c8b72bb14c5c9.tar.zst nvim-lspconfig-48003b3dec9305b9ae900c967c0c8b72bb14c5c9.zip | |
fix(mesonlsp): improved root detection #3775
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
Diffstat (limited to 'lsp/mesonlsp.lua')
| -rw-r--r-- | lsp/mesonlsp.lua | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/lsp/mesonlsp.lua b/lsp/mesonlsp.lua index 01b53e43..c4470438 100644 --- a/lsp/mesonlsp.lua +++ b/lsp/mesonlsp.lua @@ -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 + 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, } |
