diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2018-11-19 13:53:29 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2018-11-19 13:53:29 +0800 |
commit | edde29d07854ab60588f2236674b087ea699760a (patch) | |
tree | 734611a33967fa37a401ae58001a32af08aa8537 /src | |
parent | ce07013ddc6d932289ee8ba5a01f0e2d9c169164 (diff) | |
download | lua-language-server-edde29d07854ab60588f2236674b087ea699760a.zip |
hello loli
Diffstat (limited to 'src')
-rw-r--r-- | src/json/decode.lua | 4 | ||||
-rw-r--r-- | src/lsp/init.lua | 19 | ||||
-rw-r--r-- | src/service/init.lua | 2 |
3 files changed, 17 insertions, 8 deletions
diff --git a/src/json/decode.lua b/src/json/decode.lua index 42510cab..6a93d127 100644 --- a/src/json/decode.lua +++ b/src/json/decode.lua @@ -110,8 +110,8 @@ local Token = P String = '"' * Cs(V'Char'^0) * '"', Char = V'Esc' + (1 - P'"' - P'\t' - V'Nl'), Esc = P'\\' * C(S'tnr"\\') / EscMap, - Hash = V'Spnl' * '{' * V'Spnl' * HashTable(V'Object'^-1 * (P',' * V'Object')^0) * V'Spnl' * P'}'^-1 * V'Spnl', - Array = V'Spnl' * '[' * V'Spnl' * Ct(V'Value'^-1 * (P',' * V'Spnl' * V'Value')^0) * V'Spnl' * P']'^-1 * V'Spnl', + Hash = V'Spnl' * '{' * V'Spnl' * HashTable(V'Object'^-1 * (P',' * V'Object')^0) * V'Spnl' * P'}' * V'Spnl', + Array = V'Spnl' * '[' * V'Spnl' * Ct(V'Value'^-1 * (P',' * V'Spnl' * V'Value')^0) * V'Spnl' * P']' * V'Spnl', Object = V'Spnl' * V'Key' * V'Spnl' * V'Value' * V'Spnl', Key = V'String' * V'Spnl' * ':', Value = V'Hash' + V'Array' + V'Bool' + V'Null' + V'String' + V'Float' + V'Int', diff --git a/src/lsp/init.lua b/src/lsp/init.lua index 5af4d876..a0816e73 100644 --- a/src/lsp/init.lua +++ b/src/lsp/init.lua @@ -38,8 +38,9 @@ function mt:_send(data) if not f then return end + data.jsonrpc = '2.0' local content = json.encode(data) - local buf = ('Content-Length: %d\r\n\r\n%s'):format(#content + 2, content) + local buf = ('Content-Length: %d\r\n\r\n%s'):format(#content, content) f(buf) end @@ -49,7 +50,7 @@ function mt:_readAsContent(header) log.error('错误的协议头:', header) return end - local buf = self:read(len) + local buf = self:read(len+2) local suc, res = pcall(json.decode, buf) if not suc then log.error('错误的协议:', buf) @@ -65,12 +66,19 @@ function mt:_readAsContent(header) end local response, err = f(self, params) if response then - self._send { + self:_send { id = id, result = response, } + self:_send { + method = 'window/showMessage', + params = { + type = 3, + message = 'hello loli', + } + } else - self._send { + self:_send { id = id, error = { code = ErrorCodes.UnknownErrorCode, @@ -98,7 +106,8 @@ end function mt:start(method) self._method = method while true do - local header = self:read 'L' + local header = self:read 'l' + log.debug('header:', header) if not header then return end diff --git a/src/service/init.lua b/src/service/init.lua index 5e54b5b3..196ae023 100644 --- a/src/service/init.lua +++ b/src/service/init.lua @@ -26,8 +26,8 @@ local function listen(self, input, output) io.output(io.open(output:string(), 'wb')) else ext.set_filemode(io.stdout, 'b') - io.stdout:setvbuf 'no' end + io.output():setvbuf 'no' local session = lsp() session:setInput(function (mode) |