-
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
Changes from 4 commits
6083527
41d02f3
d4d6f4b
07752aa
d8fa16e
9d46789
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
local M = { | ||
events = {}, | ||
} | ||
|
||
local function on(event, callback) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? |
||
if not M.events[event] then | ||
M.events[event] = {} | ||
end | ||
table.insert(M.events[event], callback) | ||
return function() | ||
M:off(event, callback) | ||
end | ||
end | ||
|
||
local function emit(event, ...) | ||
if M.events[event] then | ||
for _, callback in ipairs(M.events[event]) do | ||
callback(...) | ||
end | ||
end | ||
end | ||
|
||
local function off(event, callback) | ||
if not M.events[event] then | ||
return | ||
end | ||
for i, cb in ipairs(M.events[event]) do | ||
if cb == callback then | ||
table.remove(M.events[event], i) | ||
break | ||
end | ||
end | ||
end | ||
|
||
---@param callback fun(remove_listener: fun()) # Callback function that is invoked when the Roslyn server is stopped. Accepts a function parameter for removing the event listener. | ||
---@return fun() # Returns a cleanup function for removing the listener manually. | ||
---```lua | ||
--- local remove_listener = M:on_stopped(function(remove_listener2) | ||
--- --For oneshot jobs | ||
--- remove_listener2() | ||
--- end) | ||
--- | ||
--- remove_listener() | ||
---``` | ||
function M:on_stopped(callback) | ||
local wrapped | ||
wrapped = function() | ||
callback(function() | ||
off("stopped", wrapped) | ||
end) | ||
end | ||
|
||
on("stopped", wrapped) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? |
||
return function() | ||
off("stopped", wrapped) | ||
end | ||
end | ||
|
||
--- Emits a stop event notifying all the M:on_stopped subscribers | ||
function M:emit_stopped(...) | ||
emit("stopped", ...) | ||
end | ||
|
||
return M |
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