Skip to content

Commit 3fc3ded

Browse files
authored
Merge pull request #178 from seblyng/vim.lsp.config
feat!: start using vim.lsp.config
2 parents 983702e + 301c12d commit 3fc3ded

File tree

16 files changed

+598
-708
lines changed

16 files changed

+598
-708
lines changed

.github/workflows/ci.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ jobs:
2323

2424
matrix:
2525
neovim_branch:
26-
- "v0.10.4"
2726
- "v0.11.0"
2827
- "nightly"
2928

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
export NVIM_RUNNER_VERSION := v0.10.4
2-
export NVIM_TEST_VERSION ?= v0.10.4
1+
export NVIM_RUNNER_VERSION := v0.11.0
2+
export NVIM_TEST_VERSION ?= v0.11.0
33

44
nvim-test:
55
git clone https://github.com/lewis6991/nvim-test

README.md

Lines changed: 34 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
This is an actively maintained & upgraded [fork](https://github.com/jmederosalvarado/roslyn.nvim) that interacts with the improved & open-source C# [Roslyn](https://github.com/dotnet/roslyn) language server, meant to replace the old and discontinued OmniSharp. This language server is currently used in the [Visual Studio Code C# Extension](https://github.com/dotnet/vscode-csharp), which is shipped with the standard C# Dev Kit.
44

5-
This standalone plugin was necessary because Roslyn uses a [non-standard](https://github.com/dotnet/roslyn/issues/72871) method of initializing communication with the client and requires additional custom integrations, unlike typical LSP setups in Neovim.
6-
75
## IMPORTANT
86

97
This plugin does not provide Razor support.
@@ -12,7 +10,7 @@ Check out https://github.com/tris203/rzls.nvim if you are using Razor.
1210

1311
## ⚡️ Requirements
1412

15-
- Neovim >= 0.10.0
13+
- Neovim >= 0.11.0
1614
- Roslyn language server downloaded locally
1715
- .NET SDK installed and `dotnet` command available
1816

@@ -42,6 +40,7 @@ require("mason").setup({
4240
```
4341

4442
You can then install it with `:MasonInstall roslyn` or through the popup menu by running `:Mason`. It is not available through [mason-lspconfig.nvim](https://github.com/williamboman/mason-lspconfig.nvim) and the `:LspInstall` interface
43+
When installing the server through mason, the cmd is automatically added to the LSP config, so no need to add it manually
4544

4645
**NOTE**
4746

@@ -58,16 +57,15 @@ There's currently an open [pull request](https://github.com/mason-org/mason-regi
5857
3. Check if it's working by running `dotnet Microsoft.CodeAnalysis.LanguageServer.dll --version` in the `<target>` directory.
5958
4. Configure it like this:
6059
```lua
61-
require("roslyn").setup({
62-
config = {
63-
cmd = {
64-
"dotnet",
65-
"<target>/Microsoft.CodeAnalysis.LanguageServer.dll",
66-
"--logLevel=Information",
67-
"--extensionLogDirectory=" .. vim.fs.dirname(vim.lsp.get_log_path()),
68-
"--stdio",
69-
},
60+
vim.lsp.config("roslyn", {
61+
cmd = {
62+
"dotnet",
63+
"<target>/Microsoft.CodeAnalysis.LanguageServer.dll",
64+
"--logLevel=Information",
65+
"--extensionLogDirectory=" .. vim.fs.dirname(vim.lsp.get_log_path()),
66+
"--stdio",
7067
},
68+
-- Add other options here
7169
})
7270
```
7371

@@ -81,15 +79,14 @@ require("roslyn").setup({
8179
### [lazy.nvim](https://github.com/folke/lazy.nvim)
8280

8381
```lua
84-
{
82+
return {
8583
"seblyng/roslyn.nvim",
8684
ft = "cs",
8785
---@module 'roslyn.config'
8886
---@type RoslynNvimConfig
8987
opts = {
9088
-- your configuration comes here; leave empty for default settings
91-
-- NOTE: You must configure `cmd` in `config.cmd` unless you have installed via mason
92-
}
89+
},
9390
}
9491
```
9592

@@ -98,15 +95,7 @@ require("roslyn").setup({
9895
The plugin comes with the following defaults:
9996

10097
```lua
101-
{
102-
---@type vim.lsp.ClientConfig
103-
config = {
104-
-- Here you can pass in any options that that you would like to pass to `vim.lsp.start`.
105-
-- Use `:h vim.lsp.ClientConfig` to see all possible options.
106-
-- The only options that are overwritten and won't have any effect by setting here:
107-
-- - `name`
108-
-- - `root_dir`
109-
},
98+
opts = {
11099
-- "auto" | "roslyn" | "off"
111100
--
112101
-- - "auto": Does nothing for filewatching, leaving everything as default
@@ -147,10 +136,29 @@ The plugin comes with the following defaults:
147136
-- This will always attach to the target in `vim.g.roslyn_nvim_selected_solution`.
148137
-- NOTE: You can use `:Roslyn target` to change the target
149138
lock_target = false,
150-
})
139+
}
151140
```
152141

153-
To configure language server specific settings sent to the server, you can modify the `config.settings` map.
142+
To configure language server specific settings sent to the server, you can use the `vim.lsp.config` interface with `roslyn` as the name of the server.
143+
144+
## Example
145+
146+
```lua
147+
vim.lsp.config("roslyn", {
148+
on_attach = function()
149+
print("This will run when the server attaches!")
150+
end,
151+
settings = {
152+
["csharp|inlay_hints"] = {
153+
csharp_enable_inlay_hints_for_implicit_object_creation = true,
154+
csharp_enable_inlay_hints_for_implicit_variable_types = true,
155+
},
156+
["csharp|code_lens"] = {
157+
dotnet_enable_references_code_lens = true,
158+
},
159+
},
160+
})
161+
```
154162

155163
Some tips and tricks that may be useful, but not in the scope of this plugin,
156164
are documented in the [wiki](https://github.com/seblyng/roslyn.nvim/wiki).
@@ -284,34 +292,6 @@ This setting controls how the language server should format code.
284292
Sort using directives on format alphabetically.
285293
Expected values: `true`, `false`
286294

287-
Example:
288-
289-
```lua
290-
opts = {
291-
config = {
292-
settings = {
293-
["csharp|inlay_hints"] = {
294-
csharp_enable_inlay_hints_for_implicit_object_creation = true,
295-
csharp_enable_inlay_hints_for_implicit_variable_types = true,
296-
csharp_enable_inlay_hints_for_lambda_parameter_types = true,
297-
csharp_enable_inlay_hints_for_types = true,
298-
dotnet_enable_inlay_hints_for_indexer_parameters = true,
299-
dotnet_enable_inlay_hints_for_literal_parameters = true,
300-
dotnet_enable_inlay_hints_for_object_creation_parameters = true,
301-
dotnet_enable_inlay_hints_for_other_parameters = true,
302-
dotnet_enable_inlay_hints_for_parameters = true,
303-
dotnet_suppress_inlay_hints_for_parameters_that_differ_only_by_suffix = true,
304-
dotnet_suppress_inlay_hints_for_parameters_that_match_argument_name = true,
305-
dotnet_suppress_inlay_hints_for_parameters_that_match_method_intent = true,
306-
},
307-
["csharp|code_lens"] = {
308-
dotnet_enable_references_code_lens = true,
309-
},
310-
},
311-
},
312-
}
313-
```
314-
315295
## 📚 Commands
316296

317297
- `:Roslyn restart` restarts the server

lsp/roslyn.lua

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
local utils = require("roslyn.sln.utils")
2+
3+
---@return string[]?
4+
local function default_cmd()
5+
local sysname = vim.uv.os_uname().sysname:lower()
6+
local iswin = not not (sysname:find("windows") or sysname:find("mingw"))
7+
8+
local mason_path = vim.fs.joinpath(vim.fn.stdpath("data"), "mason", "bin", "roslyn")
9+
local mason_cmd = iswin and string.format("%s.cmd", mason_path) or mason_path
10+
11+
if vim.uv.fs_stat(mason_cmd) == nil then
12+
return nil
13+
end
14+
15+
return {
16+
mason_cmd,
17+
"--logLevel=Information",
18+
"--extensionLogDirectory=" .. vim.fs.dirname(vim.lsp.get_log_path()),
19+
"--stdio",
20+
}
21+
end
22+
23+
---@type vim.lsp.Config
24+
return {
25+
name = "roslyn",
26+
filetypes = { "cs" },
27+
cmd = default_cmd(),
28+
cmd_env = {
29+
Configuration = vim.env.Configuration or "Debug",
30+
},
31+
capabilities = {
32+
textDocument = {
33+
-- HACK: Doesn't show any diagnostics if we do not set this to true
34+
diagnostic = {
35+
dynamicRegistration = true,
36+
},
37+
},
38+
},
39+
root_dir = function(bufnr, on_dir)
40+
local config = require("roslyn.config")
41+
local solutions = config.get().broad_search and utils.find_solutions_broad(bufnr) or utils.find_solutions(bufnr)
42+
local root_dir = utils.root_dir(bufnr, solutions)
43+
if root_dir then
44+
on_dir(root_dir)
45+
end
46+
end,
47+
on_init = {
48+
function(client)
49+
local on_init = require("roslyn.lsp.on_init")
50+
51+
local config = require("roslyn.config").get()
52+
local selected_solution = vim.g.roslyn_nvim_selected_solution
53+
if config.lock_target and selected_solution then
54+
return on_init.sln(client, selected_solution)
55+
end
56+
57+
local bufnr = vim.api.nvim_get_current_buf()
58+
local files = utils.find_files_with_extensions(client.config.root_dir, { ".sln", ".slnx", ".slnf" })
59+
60+
local solution = utils.predict_target(bufnr, files)
61+
if solution then
62+
return on_init.sln(client, solution)
63+
end
64+
65+
local csproj = utils.find_files_with_extensions(client.config.root_dir, { ".csproj" })
66+
if #csproj > 0 then
67+
return on_init.projects(client, csproj)
68+
end
69+
70+
if selected_solution then
71+
return on_init.sln(client, selected_solution)
72+
end
73+
end,
74+
},
75+
on_exit = {
76+
function()
77+
vim.g.roslyn_nvim_selected_solution = nil
78+
vim.schedule(function()
79+
require("roslyn.roslyn_emitter"):emit("stopped")
80+
vim.notify("Roslyn server stopped", vim.log.levels.INFO, { title = "roslyn.nvim" })
81+
end)
82+
end,
83+
},
84+
commands = require("roslyn.lsp.commands"),
85+
handlers = require("roslyn.lsp.handlers"),
86+
}

0 commit comments

Comments
 (0)