From b306a3150cdb67ab3977aa4b882cf957107c2519 Mon Sep 17 00:00:00 2001 From: Damien Pontifex Date: Sun, 28 Jun 2020 22:07:20 +0800 Subject: [PATCH 1/5] first pass at adding omnisharp lsp --- lua/nvim_lsp/omnisharp.lua | 83 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 lua/nvim_lsp/omnisharp.lua diff --git a/lua/nvim_lsp/omnisharp.lua b/lua/nvim_lsp/omnisharp.lua new file mode 100644 index 0000000000..d361d8690c --- /dev/null +++ b/lua/nvim_lsp/omnisharp.lua @@ -0,0 +1,83 @@ +local configs = require 'nvim_lsp/configs' +local util = require 'nvim_lsp/util' +local server_name = 'omnisharp' +local bin_name = 'run' + +local function make_installer() + local install_dir = util.path.join{util.base_install_dir, server_name} + + local url = 'linux-x64' + local extracted_dir = "linux" + + if vim.fn.has('win32') == 1 then + url = 'win-x64' + extracted_dir = 'win32' + bin_name = 'Omnisharp.exe' + elseif vim.fn.has('mac') == 1 then + url = 'osx' + extracted_dir = 'darwin' + end + + local download_target = util.path.join{install_dir, string.format("omnisharp-%s.zip", url)} + local extract_cmd = string.format("unzip '%s' -d '%s'", download_target, install_dir) + local download_cmd = string.format('curl -fLo "%s" --create-dirs "https://github.com/OmniSharp/omnisharp-roslyn/releases/latest/download/omnisharp-%s.zip"', download_target, url) + + local bin_path = util.path.join{install_dir, extracted_dir, bin_name} + local X = {} + function X.install() + local install_info = X.info() + if install_info.is_installed then + print(server_name, "is already installed") + return + end + if not (util.has_bins("curl")) then + error('Need "curl" to install this.') + return + end + vim.fn.mkdir(install_dir, 'p') + vim.fn.system(download_cmd) + vim.fn.system(extract_cmd) + end + function X.info() + return { + is_installed = util.path.exists(bin_path); + install_dir = install_dir; + cmd = { bin_path }; + } + end + function X.configure(config) + local install_info = X.info() + if install_info.is_installed then + config.cmd = install_info.cmd + end + end + return X +end + +local installer = make_installer() + +configs[server_name] = { + default_config = { + cmd = {bin_name, "--languageserver", "--verbose"}; + filetypes = {"cs", "vb"}; + root_dir = util.root_pattern(".csproj", ".sln", ".git"); + message_level = vim.lsp.protocol.MessageType.Log; + init_options = { + }; + }; + -- on_new_config = function(new_config) end; + -- on_attach = function(client, bufnr) end; + docs = { + description = [[ +https://github.com/omnisharp/omnisharp-roslyn +OmniSharp server based on Roslyn workspaces +]]; + default_config = { + root_dir = [[root_pattern(".csproj", ".sln", ".git")]]; + }; + }; +} + +configs[server_name].install = installer.install +configs[server_name].install_info = installer.info +-- vim:et ts=2 sw=2 From 4f3cab6e4b236aab75fc3894c5c914dd02f69c94 Mon Sep 17 00:00:00 2001 From: Damien Pontifex Date: Sat, 4 Jul 2020 12:46:55 +0800 Subject: [PATCH 2/5] Using globpath to expand root_patterns --- lua/nvim_lsp/omnisharp.lua | 4 ++-- lua/nvim_lsp/util.lua | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/lua/nvim_lsp/omnisharp.lua b/lua/nvim_lsp/omnisharp.lua index d361d8690c..728e938045 100644 --- a/lua/nvim_lsp/omnisharp.lua +++ b/lua/nvim_lsp/omnisharp.lua @@ -58,9 +58,9 @@ local installer = make_installer() configs[server_name] = { default_config = { - cmd = {bin_name, "--languageserver", "--verbose"}; + cmd = {installer.info().cmd[1], "--languageserver", "--verbose"}; filetypes = {"cs", "vb"}; - root_dir = util.root_pattern(".csproj", ".sln", ".git"); + root_dir = util.root_pattern("*.csproj", "*.sln"); message_level = vim.lsp.protocol.MessageType.Log; init_options = { }; diff --git a/lua/nvim_lsp/util.lua b/lua/nvim_lsp/util.lua index 83e3632194..20d2bb15fb 100644 --- a/lua/nvim_lsp/util.lua +++ b/lua/nvim_lsp/util.lua @@ -290,6 +290,9 @@ function M.root_pattern(...) local patterns = vim.tbl_flatten {...} local function matcher(path) for _, pattern in ipairs(patterns) do + if fn.globpath(path, pattern) ~= "" then + return path + end if M.path.exists(M.path.join(path, pattern)) then return path end From 0c6cab79d3f8ca28a5a4d143419e800e66d6bc9d Mon Sep 17 00:00:00 2001 From: Damien Pontifex Date: Sat, 25 Jul 2020 11:54:07 +0800 Subject: [PATCH 3/5] updated command --- lua/nvim_lsp/omnisharp.lua | 13 ++++++------- lua/nvim_lsp/util.lua | 5 +---- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/lua/nvim_lsp/omnisharp.lua b/lua/nvim_lsp/omnisharp.lua index 728e938045..9069daae1c 100644 --- a/lua/nvim_lsp/omnisharp.lua +++ b/lua/nvim_lsp/omnisharp.lua @@ -7,22 +7,19 @@ local function make_installer() local install_dir = util.path.join{util.base_install_dir, server_name} local url = 'linux-x64' - local extracted_dir = "linux" if vim.fn.has('win32') == 1 then url = 'win-x64' - extracted_dir = 'win32' bin_name = 'Omnisharp.exe' elseif vim.fn.has('mac') == 1 then url = 'osx' - extracted_dir = 'darwin' end local download_target = util.path.join{install_dir, string.format("omnisharp-%s.zip", url)} local extract_cmd = string.format("unzip '%s' -d '%s'", download_target, install_dir) local download_cmd = string.format('curl -fLo "%s" --create-dirs "https://github.com/OmniSharp/omnisharp-roslyn/releases/latest/download/omnisharp-%s.zip"', download_target, url) - local bin_path = util.path.join{install_dir, extracted_dir, bin_name} + local bin_path = util.path.join{install_dir, bin_name} local X = {} function X.install() local install_info = X.info() @@ -42,7 +39,7 @@ local function make_installer() return { is_installed = util.path.exists(bin_path); install_dir = install_dir; - cmd = { bin_path }; + cmd = { bin_path, "--languageserver" }; } end function X.configure(config) @@ -58,10 +55,12 @@ local installer = make_installer() configs[server_name] = { default_config = { - cmd = {installer.info().cmd[1], "--languageserver", "--verbose"}; + cmd = installer.info().cmd; filetypes = {"cs", "vb"}; root_dir = util.root_pattern("*.csproj", "*.sln"); - message_level = vim.lsp.protocol.MessageType.Log; + on_new_config = function(config) + installer.configure(config) + end; init_options = { }; }; diff --git a/lua/nvim_lsp/util.lua b/lua/nvim_lsp/util.lua index 20d2bb15fb..00ba156368 100644 --- a/lua/nvim_lsp/util.lua +++ b/lua/nvim_lsp/util.lua @@ -290,10 +290,7 @@ function M.root_pattern(...) local patterns = vim.tbl_flatten {...} local function matcher(path) for _, pattern in ipairs(patterns) do - if fn.globpath(path, pattern) ~= "" then - return path - end - if M.path.exists(M.path.join(path, pattern)) then + if M.path.exists(vim.fn.glob(M.path.join(path, pattern))) then return path end end From d49cd40e9292f2113c6477f72f8ba266b2e884ba Mon Sep 17 00:00:00 2001 From: Damien Pontifex Date: Sat, 25 Jul 2020 11:59:04 +0800 Subject: [PATCH 4/5] make run executable --- lua/nvim_lsp/omnisharp.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lua/nvim_lsp/omnisharp.lua b/lua/nvim_lsp/omnisharp.lua index 9069daae1c..1aaaf83a70 100644 --- a/lua/nvim_lsp/omnisharp.lua +++ b/lua/nvim_lsp/omnisharp.lua @@ -14,12 +14,13 @@ local function make_installer() elseif vim.fn.has('mac') == 1 then url = 'osx' end + local bin_path = util.path.join{install_dir, bin_name} local download_target = util.path.join{install_dir, string.format("omnisharp-%s.zip", url)} local extract_cmd = string.format("unzip '%s' -d '%s'", download_target, install_dir) local download_cmd = string.format('curl -fLo "%s" --create-dirs "https://github.com/OmniSharp/omnisharp-roslyn/releases/latest/download/omnisharp-%s.zip"', download_target, url) + local make_executable_cmd = string.format("chmod u+x '%s'", bin_path) - local bin_path = util.path.join{install_dir, bin_name} local X = {} function X.install() local install_info = X.info() @@ -34,6 +35,7 @@ local function make_installer() vim.fn.mkdir(install_dir, 'p') vim.fn.system(download_cmd) vim.fn.system(extract_cmd) + vim.fn.system(make_executable_cmd) end function X.info() return { From 3acadb5a11c879dd54da8dad93135172394fdbc1 Mon Sep 17 00:00:00 2001 From: Damien Pontifex Date: Sat, 25 Jul 2020 12:03:49 +0800 Subject: [PATCH 5/5] strip whitespace --- lua/nvim_lsp/util.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/nvim_lsp/util.lua b/lua/nvim_lsp/util.lua index 00ba156368..c125c33f02 100644 --- a/lua/nvim_lsp/util.lua +++ b/lua/nvim_lsp/util.lua @@ -290,7 +290,7 @@ function M.root_pattern(...) local patterns = vim.tbl_flatten {...} local function matcher(path) for _, pattern in ipairs(patterns) do - if M.path.exists(vim.fn.glob(M.path.join(path, pattern))) then + if M.path.exists(vim.fn.glob(M.path.join(path, pattern))) then return path end end