Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix!: remove hacky pipe start and prefer stdio #120

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion lua/roslyn/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,11 @@ end
local roslyn_config = {
filewatching = true,
exe = default_exe(),
args = { "--logLevel=Information", "--extensionLogDirectory=" .. vim.fs.dirname(vim.lsp.get_log_path()) },
args = {
"--logLevel=Information",
"--extensionLogDirectory=" .. vim.fs.dirname(vim.lsp.get_log_path()),
"--stdio",
},
---@diagnostic disable-next-line: missing-fields
config = {
capabilities = default_capabilities(),
Expand Down Expand Up @@ -126,6 +130,15 @@ function M.setup(user_config)
end
end

if not vim.tbl_contains(roslyn_config.args, "--stdio") then
vim.notify(
"roslyn.nvim requires the `--stdio` argument to be present. Please add it to your configuration",
vim.log.levels.WARN,
{ title = "roslyn.nvim" }
)
table.insert(roslyn_config.args, "--stdio")
end

-- HACK: Enable filewatching to later just not watch any files
-- This is to not make the server watch files and make everything super slow in certain situations
if not roslyn_config.filewatching then
Expand Down
19 changes: 19 additions & 0 deletions lua/roslyn/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ end

local M = {}

---@type boolean
local roslyn_version_verified = false

---@param config? RoslynNvimConfig
function M.setup(config)
local roslyn_config = require("roslyn.config").setup(config)
Expand All @@ -33,6 +36,22 @@ function M.setup(config)
return
end

if not roslyn_version_verified then
-- TODO: Remove this in a few months or so
-- vim.system will fail with required args not provided if `--stdio` exists as an argument
-- to the version installed, so this should be safe
local cmd = vim.list_extend(vim.deepcopy(roslyn_config.exe), { "--stdio" })
local stderr = vim.system(cmd):wait().stderr
if stderr and string.find(stderr, "Unrecognized command or argument '--stdio'.", 0, true) then
return vim.notify(
"The roslyn language server needs to be updated. Refer to the README for installation steps",
vim.log.levels.INFO,
{ title = "roslyn.nvim" }
)
end
roslyn_version_verified = true
end

-- Lock the target and always start with the currently selected solution
if roslyn_config.lock_target and vim.g.roslyn_nvim_selected_solution then
local sln_dir = vim.fs.dirname(vim.g.roslyn_nvim_selected_solution)
Expand Down
13 changes: 6 additions & 7 deletions lua/roslyn/lsp.lua
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
local server = require("roslyn.server")

local M = {}

---@param bufnr integer
---@param root_dir string
---@param on_init fun(client: vim.lsp.Client)
function M.start(bufnr, root_dir, on_init)
local roslyn_config = require("roslyn.config").get()
local cmd = vim.list_extend(vim.deepcopy(roslyn_config.exe), vim.deepcopy(roslyn_config.args))

local config = vim.deepcopy(roslyn_config.config)
config.cmd = vim.list_extend(vim.deepcopy(roslyn_config.exe), vim.deepcopy(roslyn_config.args))
config.name = "roslyn"
config.root_dir = root_dir
config.handlers = vim.tbl_deep_extend("force", {
Expand All @@ -26,13 +24,15 @@ function M.start(bufnr, root_dir, on_init)
["workspace/projectInitializationComplete"] = function(_, _, ctx)
vim.notify("Roslyn project initialization complete", vim.log.levels.INFO, { title = "roslyn.nvim" })

---NOTE: This is used by rzls.nvim for init
vim.api.nvim_exec_autocmds("User", { pattern = "RoslynInitialized", modeline = false })
_G.roslyn_initialized = true

local buffers = vim.lsp.get_buffers_by_client_id(ctx.client_id)
for _, buf in ipairs(buffers) do
vim.lsp.util._refresh("textDocument/diagnostic", { bufnr = buf })
end

---NOTE: This is used by rzls.nvim for init
vim.api.nvim_exec_autocmds("User", { pattern = "RoslynInitialized", modeline = false })
end,
["workspace/_roslyn_projectHasUnresolvedDependencies"] = function()
vim.notify("Detected missing dependencies. Run dotnet restore command.", vim.log.levels.ERROR, {
Expand Down Expand Up @@ -107,7 +107,6 @@ function M.start(bufnr, root_dir, on_init)

config.on_exit = function(code, signal, client_id)
vim.g.roslyn_nvim_selected_solution = nil
server.stop_server(client_id)
vim.schedule(function()
vim.notify("Roslyn server stopped", vim.log.levels.INFO, { title = "roslyn.nvim" })
end)
Expand Down Expand Up @@ -161,7 +160,7 @@ function M.start(bufnr, root_dir, on_init)
end,
})

server.start_server(bufnr, cmd, config)
vim.lsp.start(config, { bufnr = bufnr })
end

---@param client vim.lsp.Client
Expand Down
108 changes: 0 additions & 108 deletions lua/roslyn/server.lua

This file was deleted.