Skip to content
This repository was archived by the owner on Mar 25, 2022. It is now read-only.

Commit

Permalink
fix ws methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikolay Mendyaev authored and KlonD90 committed Feb 21, 2020
1 parent 7028cd1 commit bbdc7b2
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 9 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Changelog

## Unreleased

- Fix ws shutdown
- Fix ws method with no return answer

## 0.0.1

Initial release
8 changes: 4 additions & 4 deletions tarantool-lsp/methods.lua
Original file line number Diff line number Diff line change
Expand Up @@ -829,13 +829,13 @@ method_handlers["workspace/didChangeConfiguration"] = function(config, params)
log.info("Config loaded, new config: %t", config)
end

function method_handlers.shutdown(_, id)
Shutdown = true
function method_handlers.shutdown(config, _, id)
config.Shutdown = true
return rpc.respond(id, json.null)
end

function method_handlers.exit(_)
if Shutdown then
function method_handlers.exit(config, _)
if config.Shutdown then
os.exit(0)
else
os.exit(1)
Expand Down
14 changes: 9 additions & 5 deletions tarantool-lsp/websocket-lib.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ local handshake = require('websocket.handshake')
local fio = require('fio')
local log = require('log')

--_G.Globals = _G.Globals or nil -- defined in analyze.lua
--_G.Types = _G.Types or {}

local DETACHED = 101

local initalized = false
Expand All @@ -21,7 +18,9 @@ local create_handler = function(options)
log.info('Path: %s', path)

if not initalized then
local ok, err = docs:init({ completions_dir = fio.pathjoin(path, 'completions') })
local ok, err = docs:init({
completions_dir = options and options.completion_root or fio.pathjoin(path, 'completions')
})
if err ~= nil then
log.info("Docs subsystem error: %s", err)
end
Expand Down Expand Up @@ -54,6 +53,9 @@ local create_handler = function(options)
local data = json.decode(message.data)
if data.method then
-- request
if data.method == 'exit' then
return DETACHED
end
if not method_handlers[data.method] then
-- log.verbose("confused by %t", data)
err = string.format("%q: Not found/NYI", tostring(data.method))
Expand All @@ -66,7 +68,9 @@ local create_handler = function(options)
local ok
ok, err = xpcall(function()
local response = method_handlers[data.method](config, data.params, data.id)
ws_peer:write(response)
if response then
ws_peer:write(response)
end
end, debug.traceback)
if not ok then
if data.id then
Expand Down

0 comments on commit bbdc7b2

Please sign in to comment.