From 7b2478b42ce8bb9d63dd2dcd44dc373d19c90cc7 Mon Sep 17 00:00:00 2001 From: ttys3 Date: Mon, 22 Mar 2021 15:19:45 +0800 Subject: refactor(vala): refine vala project root detection --- lua/lspconfig/vala_ls.lua | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) (limited to 'lua/lspconfig/vala_ls.lua') diff --git a/lua/lspconfig/vala_ls.lua b/lua/lspconfig/vala_ls.lua index 3b19786c..f2aba74b 100644 --- a/lua/lspconfig/vala_ls.lua +++ b/lua/lspconfig/vala_ls.lua @@ -1,13 +1,34 @@ local configs = require 'lspconfig/configs' local util = require 'lspconfig/util' +local meson_matcher = function (path) + local pattern = "meson.build" + local f = vim.fn.glob(util.path.join(path, pattern)) + if f == '' then + return nil + 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 path + else + break + end + end + end + end +end + configs.vala_ls = { default_config = { cmd = {'vala-language-server'}, filetypes = {'vala', 'genie'}, - root_dir = function(fname) - return util.root_pattern("meson.build")(fname) - or util.find_git_ancestor(fname) + root_dir = function (fname) + local root = util.search_ancestors(fname, meson_matcher) + return root or util.find_git_ancestor(fname) end, }, docs = { -- cgit v1.2.3-70-g09d2