Skip to content

Commit 28a3982

Browse files
Add omnisharp language server (#291)
* first pass at adding omnisharp lsp * Using globpath to expand root_patterns * updated command * make run executable * strip whitespace
1 parent 725eb45 commit 28a3982

File tree

2 files changed

+85
-1
lines changed

2 files changed

+85
-1
lines changed

lua/nvim_lsp/omnisharp.lua

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
local configs = require 'nvim_lsp/configs'
2+
local util = require 'nvim_lsp/util'
3+
local server_name = 'omnisharp'
4+
local bin_name = 'run'
5+
6+
local function make_installer()
7+
local install_dir = util.path.join{util.base_install_dir, server_name}
8+
9+
local url = 'linux-x64'
10+
11+
if vim.fn.has('win32') == 1 then
12+
url = 'win-x64'
13+
bin_name = 'Omnisharp.exe'
14+
elseif vim.fn.has('mac') == 1 then
15+
url = 'osx'
16+
end
17+
local bin_path = util.path.join{install_dir, bin_name}
18+
19+
local download_target = util.path.join{install_dir, string.format("omnisharp-%s.zip", url)}
20+
local extract_cmd = string.format("unzip '%s' -d '%s'", download_target, install_dir)
21+
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)
22+
local make_executable_cmd = string.format("chmod u+x '%s'", bin_path)
23+
24+
local X = {}
25+
function X.install()
26+
local install_info = X.info()
27+
if install_info.is_installed then
28+
print(server_name, "is already installed")
29+
return
30+
end
31+
if not (util.has_bins("curl")) then
32+
error('Need "curl" to install this.')
33+
return
34+
end
35+
vim.fn.mkdir(install_dir, 'p')
36+
vim.fn.system(download_cmd)
37+
vim.fn.system(extract_cmd)
38+
vim.fn.system(make_executable_cmd)
39+
end
40+
function X.info()
41+
return {
42+
is_installed = util.path.exists(bin_path);
43+
install_dir = install_dir;
44+
cmd = { bin_path, "--languageserver" };
45+
}
46+
end
47+
function X.configure(config)
48+
local install_info = X.info()
49+
if install_info.is_installed then
50+
config.cmd = install_info.cmd
51+
end
52+
end
53+
return X
54+
end
55+
56+
local installer = make_installer()
57+
58+
configs[server_name] = {
59+
default_config = {
60+
cmd = installer.info().cmd;
61+
filetypes = {"cs", "vb"};
62+
root_dir = util.root_pattern("*.csproj", "*.sln");
63+
on_new_config = function(config)
64+
installer.configure(config)
65+
end;
66+
init_options = {
67+
};
68+
};
69+
-- on_new_config = function(new_config) end;
70+
-- on_attach = function(client, bufnr) end;
71+
docs = {
72+
description = [[
73+
https://github.com/omnisharp/omnisharp-roslyn
74+
OmniSharp server based on Roslyn workspaces
75+
]];
76+
default_config = {
77+
root_dir = [[root_pattern(".csproj", ".sln", ".git")]];
78+
};
79+
};
80+
}
81+
82+
configs[server_name].install = installer.install
83+
configs[server_name].install_info = installer.info
84+
-- vim:et ts=2 sw=2

lua/nvim_lsp/util.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ function M.root_pattern(...)
290290
local patterns = vim.tbl_flatten {...}
291291
local function matcher(path)
292292
for _, pattern in ipairs(patterns) do
293-
if M.path.exists(M.path.join(path, pattern)) then
293+
if M.path.exists(vim.fn.glob(M.path.join(path, pattern))) then
294294
return path
295295
end
296296
end

0 commit comments

Comments
 (0)