Skip to content

Commit

Permalink
don't call exit directly
Browse files Browse the repository at this point in the history
  • Loading branch information
searls committed Feb 10, 2023
1 parent 3f30ac9 commit cbdcf3b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
10 changes: 10 additions & 0 deletions lib/standard/lsp/kills_server.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module Standard
module Lsp
class KillsServer
def call(&blk)
at_exit(&blk) unless blk.nil?
exit 0
end
end
end
end
17 changes: 11 additions & 6 deletions lib/standard/lsp/routes.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require_relative "kills_server"

module Standard
module Lsp
class Routes
Expand All @@ -7,6 +9,7 @@ def initialize(writer, logger, standardizer)
@standardizer = standardizer

@text_cache = {}
@kills_server = KillsServer.new
end

def self.handle(name, &block)
Expand Down Expand Up @@ -38,11 +41,11 @@ def for(name)
end

handle "shutdown" do |request|
@logger.puts "Client asked to shutdown Standard LSP server. Exiting..."
at_exit {
@logger.puts "Client asked to shutdown Standard LSP server."
@kills_server.call do
@logger.puts "Exiting..."
@writer.write(id: request[:id], result: nil)
}
exit 0
end
end

handle "textDocument/diagnostic" do |request|
Expand Down Expand Up @@ -73,8 +76,10 @@ def for(name)
end

handle "workspace/didChangeWatchedFiles" do |request|
@logger.puts "Configuration file changed; restart required"
exit 0
if request[:params][:changes].any? { |change| change[:uri].end_with?(".standard.yml") }
@logger.puts "Configuration file changed; restart required"
@kills_server.call
end
end

handle "workspace/executeCommand" do |request|
Expand Down

0 comments on commit cbdcf3b

Please sign in to comment.