From 80fc5c27b861f24277ccf8db5eb8bc2841dbfca4 Mon Sep 17 00:00:00 2001 From: russoul Date: Wed, 27 Nov 2024 17:31:54 +0400 Subject: [PATCH 1/2] Implement setIpkg LSP command; Add config option to run the LSP server configured with a specified ipkg file --- lua/idris2/init.lua | 18 +++++++++++++++++- lua/idris2/set_ipkg.lua | 8 ++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 lua/idris2/set_ipkg.lua diff --git a/lua/idris2/init.lua b/lua/idris2/init.lua index 1cd21f0..8a2b502 100644 --- a/lua/idris2/init.lua +++ b/lua/idris2/init.lua @@ -44,6 +44,12 @@ end local function setup_lsp() local root_dir_error = function(startpath) + + -- If ipkg file is specified in the user config, assume default startpath + if config.options.ipkg then + return startpath + end + local path = nvim_lsp.util.root_pattern("*.ipkg")(startpath) if path ~= nil then return path @@ -57,7 +63,17 @@ local function setup_lsp() vim.log.levels.WARN ) end - local server = vim.tbl_deep_extend("force", config.options.server, { root_dir = root_dir_error }) + + -- If ipkg file is specified in user config, pass it down to lspconfig as idris2-lsp command argument + local cmd + if config.options.ipkg + then + cmd = { "idris2-lsp", config.options.ipkg } + else + cmd = { "idris2-lsp" } + end + + local server = vim.tbl_deep_extend("force", config.options.server, { cmd = cmd, root_dir = root_dir_error }) nvim_lsp.idris2_lsp.setup(server) -- Goto... commands may jump to non package-local files, e.g. base or contrib diff --git a/lua/idris2/set_ipkg.lua b/lua/idris2/set_ipkg.lua new file mode 100644 index 0000000..4cc7a2e --- /dev/null +++ b/lua/idris2/set_ipkg.lua @@ -0,0 +1,8 @@ +local M = {} + +-- Send "setIpkg" command to LSP +function M.send(ipkg) + vim.lsp.buf_request(0, 'workspace/executeCommand', {command = "setIpkg", arguments = {ipkg}}, function() end) +end + +return M From e4637df5b08996b333c136358e50b60fb4a6bdc2 Mon Sep 17 00:00:00 2001 From: russoul Date: Fri, 29 Nov 2024 19:07:17 +0400 Subject: [PATCH 2/2] Simplify --- lua/idris2/init.lua | 22 +++++----------------- lua/idris2/set_ipkg.lua | 8 -------- 2 files changed, 5 insertions(+), 25 deletions(-) delete mode 100644 lua/idris2/set_ipkg.lua diff --git a/lua/idris2/init.lua b/lua/idris2/init.lua index 8a2b502..d9c223e 100644 --- a/lua/idris2/init.lua +++ b/lua/idris2/init.lua @@ -44,12 +44,6 @@ end local function setup_lsp() local root_dir_error = function(startpath) - - -- If ipkg file is specified in the user config, assume default startpath - if config.options.ipkg then - return startpath - end - local path = nvim_lsp.util.root_pattern("*.ipkg")(startpath) if path ~= nil then return path @@ -63,17 +57,7 @@ local function setup_lsp() vim.log.levels.WARN ) end - - -- If ipkg file is specified in user config, pass it down to lspconfig as idris2-lsp command argument - local cmd - if config.options.ipkg - then - cmd = { "idris2-lsp", config.options.ipkg } - else - cmd = { "idris2-lsp" } - end - - local server = vim.tbl_deep_extend("force", config.options.server, { cmd = cmd, root_dir = root_dir_error }) + local server = vim.tbl_deep_extend("force", config.options.server, { root_dir = root_dir_error }) nvim_lsp.idris2_lsp.setup(server) -- Goto... commands may jump to non package-local files, e.g. base or contrib @@ -139,4 +123,8 @@ function M.hide_namespace() vim.lsp.buf_notify(0, "workspace/didChangeConfiguration", { settings = { fullNamespace = false } }) end +function M.set_ipkg_path(path) + vim.lsp.buf_notify(0, "workspace/didChangeConfiguration", { settings = { ipkgPath = path } }) +end + return M diff --git a/lua/idris2/set_ipkg.lua b/lua/idris2/set_ipkg.lua deleted file mode 100644 index 4cc7a2e..0000000 --- a/lua/idris2/set_ipkg.lua +++ /dev/null @@ -1,8 +0,0 @@ -local M = {} - --- Send "setIpkg" command to LSP -function M.send(ipkg) - vim.lsp.buf_request(0, 'workspace/executeCommand', {command = "setIpkg", arguments = {ipkg}}, function() end) -end - -return M