aboutsummaryrefslogtreecommitdiff
path: root/init.lua
diff options
context:
space:
mode:
Diffstat (limited to 'init.lua')
-rw-r--r--init.lua65
1 files changed, 46 insertions, 19 deletions
diff --git a/init.lua b/init.lua
index 865d35a..b433b12 100644
--- a/init.lua
+++ b/init.lua
@@ -34,6 +34,9 @@ local parser = dofile(source_path .. 'parser.lua')
-- initialise the util module
local util = dofile(source_path .. 'util.lua').init(lspc)
+-- initialise the settings module
+local settings = dofile(source_path .. 'settings.lua').init(lspc)
+
-- load a suitable json module
lspc.json = dofile(source_path .. 'json.lua')
@@ -85,7 +88,9 @@ end
-- map of known language servers per syntax
lspc.ls_map = dofile(source_path .. 'supported-servers.lua')
--- return the name of the language server for this syntax
+--- Return the name of the language server for this syntax
+-- @param syntax the syntax the language server should support
+-- @return the name of the languauge server configured for syntax
local function get_ls_name_for_syntax(syntax)
local ls_def = lspc.ls_map[syntax]
if not ls_def then
@@ -951,15 +956,24 @@ local function lspc_handle_initialize_response(ls, result)
-- According to nvim-lspconfig sendig the lsp server settings shortly after
-- initialization is an undocumented convention.
-- See https://github.com/neovim/nvim-lspconfig/blob/ed88435764d8b00442e66d39ec3d9c360e560783/CONTRIBUTING.md
- if ls.settings then
- ls:send_notification('workspace/didChangeConfiguration', {
- settings = ls.settings,
- })
- end
+ lspc:log('Loading settings for ' .. ls.name)
+ ls:send_default_settings()
vis.events.emit(lspc.events.LS_INITIALIZED, ls)
end
+--- Send didChangeConfiguration notification with the default settings
+function LanguageServer:send_default_settings()
+ -- Use the rootUri or the open file's path as scope for the initial settings
+ local scope = self.rootUri or vis.win.file and vis.win.file.path
+ local effective_ls_settings = settings.effective_settings(self, nil, scope)
+ if effective_ls_settings then
+ self:send_notification('workspace/didChangeConfiguration', {
+ settings = effective_ls_settings,
+ })
+ end
+end
+
--- Dispatch method response from the server
-- @param method_response the response send from the server
-- @param req the request causing this response
@@ -1027,20 +1041,15 @@ function LanguageServer:handle_method_response(method_response, req)
self.inflight[method_response.id] = nil
end
+--- Handle a workspace/configuration request from a server
+-- @param params the parameters send with the request
+-- @param response the response we are about to send
local function lspc_handle_workspace_configuration_call(ls, params, response)
local results = {}
for _, item in ipairs(params.items) do
- -- de-flatten the section and map it to our settings if one is present.
- if item.section then
- local t = ls.settings
- for k in item.section:gmatch('[^.]+') do
- if not t then
- break
- end
- t = t[k]
- end
- table.insert(results, t or lspc.json.null)
- end
+ local scope = item.scopeUri and uri_to_path(item.scopeUri)
+ local effective_settings = settings.effective_settings(ls, item.section, scope)
+ table.insert(results, effective_settings)
end
response.result = results
end
@@ -1161,8 +1170,11 @@ function LanguageServer:recv_data(data)
end
end
--- check if a language server is running and initialized
-local function lspc_get_usable_ls(win, explicit_syntax)
+--- Return a running language server
+-- @param win the window for which the language server might be running
+-- @param explicit_syntax the syntax if different from win.syntax
+-- @return a running language server or nil and an error message
+function lspc.get_running_ls(win, explicit_syntax)
local ls
local syntax = explicit_syntax or (win and win.syntax)
-- try to use the first language server managing the current file
@@ -1187,6 +1199,21 @@ local function lspc_get_usable_ls(win, explicit_syntax)
end
end
+ return ls
+end
+
+--- Return a running and initialized language server
+-- @param win the window for which the language server might be running
+-- @param explicit_syntax the syntax if different from win.syntax
+-- @return a running and initialized language server or nil and an error message
+local function lspc_get_usable_ls(win, explicit_syntax)
+ local ls, err = lspc.get_running_ls(win, explicit_syntax)
+
+ if err then
+ return nil, err
+ end
+
+ assert(ls)
if not ls.initialized then
return nil, 'Language server ' .. ls.name .. ' not initialized yet. Please try again'
end