-
Notifications
You must be signed in to change notification settings - Fork 32
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: roslyn restart command not working #162
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting that it doesn't work🤔 Anyways, I like this idea since I don't like the restart code. I just copied something over from lspconfig if I remember correctly.
Just looked through this on mobile right now so haven't tested it yet, but I think the idea makes sense at least.
I don't remember why I didn't go with something like this or even if I testen something like this🤷♂️
lua/roslyn/roslyn_emitter.lua
Outdated
@@ -0,0 +1,20 @@ | |||
local EventEmitter = require "roslyn.event_emitter" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I would prefer if we didn't have this file. I think instead we can just use the interface directly which you created in event_emitter.lua
We should then add some emmylua hints to which events is available to on
and emit
.
I think for now it is okay to just have stopped
as an event, and then we can just add started
or other potential events when needed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did some refactorings to make a concrete implementation with the things we need. Please re-review this file and see if it looks okay to you. Trying to keep the exposed signature small and succinct.
Also added emmylua hints and examples
Please also test out the We can probably continue this in another thread but the reason for this PR is because everytime I create a new file or install a nuget package the Roslyn server wont pick it up for some reason. This causes me to run |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it mostly looks good now. Just a couple of questions really. The current restart actually works for me on main and I use it all the time, but we should of course fix it since it doesn't work for you👍
lua/roslyn/commands.lua
Outdated
) | ||
roslyn_emitter:on_stopped(restart_lsp) | ||
|
||
client.stop(true) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to force it? It works for me without, and it prints out this message of the server quit with exit code x which would be nice to avoid if possible
lua/roslyn/roslyn_emitter.lua
Outdated
events = {}, | ||
} | ||
|
||
local function on(event, callback) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was actually first thinking about making this and emit public and have the type of event be literal "stopped" to get some typing when using it. Then we could just add a new literal string as alternative to event to get hints if we add more events, instead of creating new methods.
However, I don't have that strong opinions on that after some thinking and am okay with this as well. What do you think?
lua/roslyn/roslyn_emitter.lua
Outdated
end) | ||
end | ||
|
||
on("stopped", wrapped) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we not just return on here since that is also returning a a cleanup function?
Not at the computer rn but will fix the comments shortly, for me it was kinda wonky when i stopped without forcing. That required me to do weird stuff like vim.api.nvim_feedkeys("j", "n"). Very strange its working for you, are you on windows or linux. Which version of roslyn lsp are you using? |
Okay I think I might've found it. I checked out latest main branch and add force stop to the client. Everything works perfectly. Wild guess, its a windows issue with delay during terminating processes? local client = vim.lsp.get_clients({ name = "roslyn" })[1]
if not client then
return
end
local attached_buffers = vim.tbl_keys(client.attached_buffers)
-- TODO: Change this to `client:request` when minimal version is `0.11`
---@diagnostic disable-next-line: missing-parameter
- client.stop()
+ client.stop(true)
local timer = vim.uv.new_timer()
timer:start(
500,
100,
vim.schedule_wrap(function()
-- TODO: Change this to `client:request` when minimal version is `0.11`
---@diagnostic disable-next-line: missing-parameter
if client.is_stopped() then
for _, buffer in ipairs(attached_buffers) do
vim.api.nvim_exec_autocmds("FileType", { group = "Roslyn", buffer = buffer })
end
end
if not timer:is_closing() then
timer:close()
end
end)
) |
Okay yes I am using mac so it's probably some windows issue then. Keep the force then so that it works for everyone👍 |
Okay so just to clarify, do you still want the rest of this PR with event emit stuff or just add |
I think I want this PR since I don't really like the timer stuff |
refactored the roslyn_emitter according to your wishes, I think it makes sense like this, using string literals. If your plan was to expose these events as part of the public API we should update readme, otherwise please re-review and lmk if I need to do changes |
Lastly I could make a is_windows() check to only force if on windows. Just to contain the tomfoolery. This would prevent Unix users from seeing the |
I think we can wait with this👍 looks good now!
Yes that sounds like a good idea! Otherwise looks good to me👍 |
Tested and verified on windows. Works like a charm🚀 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you very much!😄
I would've cleaned up my commits if I knew you were going to merge and not squash merge 🙈. Will remember to next time |
Woops😅 I didn't think about that, but it's no problem |
The
Roslyn restart
command does not work for me. When I execute it nothing happens and then I move my cursor and it logs outRoslyn server stopped
but never any start event after thatThis PR fixes the Roslyn restart command, atleast for me. It's kinda hacky but we can either forcestop the lsp server or do some yank with moving the cursor in the buffer. There might be other ways I experimented with
:redraw
andCursorHold
exec. Those didnt work