summaryrefslogtreecommitdiff
path: root/server/src
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2018-12-18 14:54:35 +0800
committer最萌小汐 <sumneko@hotmail.com>2018-12-18 14:54:35 +0800
commitf5f6a8df0cd377eaf72e89f5edca4260794f60b0 (patch)
tree6ead5a881019490142024ed84135680084995b91 /server/src
parenta064ab3a5c024b02235e041a2d0941fd094843cd (diff)
downloadlua-language-server-f5f6a8df0cd377eaf72e89f5edca4260794f60b0.zip
整理代码
Diffstat (limited to 'server/src')
-rw-r--r--server/src/rpc.lua24
-rw-r--r--server/src/service.lua11
2 files changed, 20 insertions, 15 deletions
diff --git a/server/src/rpc.lua b/server/src/rpc.lua
index 559853e0..728cf74f 100644
--- a/server/src/rpc.lua
+++ b/server/src/rpc.lua
@@ -5,18 +5,26 @@ local TIMEOUT = 1.0
local ID = 0
local BUF = {}
-local function notify(self, data)
- data.jsonrpc = '2.0'
- local content = json.encode(data)
+local function notify(self, method, params)
+ local pack = {
+ jsonrpc = '2.0',
+ method = method,
+ params = params,
+ }
+ local content = json.encode(pack)
local buf = ('Content-Length: %d\r\n\r\n%s'):format(#content, content)
io.write(buf)
end
-local function request(self, data, callback)
+local function request(self, method, params, callback)
ID = ID + 1
- data.jsonrpc = '2.0'
- data.id = ID
- local content = json.encode(data)
+ local pack = {
+ jsonrpc = '2.0',
+ id = ID,
+ method = method,
+ params = params,
+ }
+ local content = json.encode(pack)
local buf = ('Content-Length: %d\r\n\r\n%s'):format(#content, content)
BUF[ID] = {
callback = callback,
@@ -36,8 +44,8 @@ end
local function recieve(self, proto)
local id = proto.id
local data = BUF[id]
- log.warn('Recieve id not found: ', table.dump(proto))
if not data then
+ log.warn('Recieve id not found: ', table.dump(proto))
return
end
BUF[id] = nil
diff --git a/server/src/service.lua b/server/src/service.lua
index fd748a96..9a53804d 100644
--- a/server/src/service.lua
+++ b/server/src/service.lua
@@ -93,13 +93,10 @@ function mt:_doDiagnostic()
local name = 'textDocument/publishDiagnostics'
local res = self:_callMethod(name, data)
if res then
- rpc:notify {
- method = name,
- params = {
- uri = uri,
- diagnostics = res,
- },
- }
+ rpc:notify(name, {
+ uri = uri,
+ diagnostics = res,
+ })
end
end
local passed = os.clock() - clock