diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2019-09-23 12:35:55 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2019-09-23 12:35:55 +0800 |
commit | 93a19c3772c8f0c0f01c0f9669a3cb0ba7393986 (patch) | |
tree | 226b04d00db0fb2f02f6b437ede80dfc6423f18e /server-beta/src/proto | |
parent | ce6c767448b82dc26faf06e2956f5327aebd8f5e (diff) | |
download | lua-language-server-93a19c3772c8f0c0f01c0f9669a3cb0ba7393986.zip |
修正一些bug
Diffstat (limited to 'server-beta/src/proto')
-rw-r--r-- | server-beta/src/proto/interface.lua | 18 | ||||
-rw-r--r-- | server-beta/src/proto/provider.lua | 34 |
2 files changed, 37 insertions, 15 deletions
diff --git a/server-beta/src/proto/interface.lua b/server-beta/src/proto/interface.lua index 21be1cdf..ddba623a 100644 --- a/server-beta/src/proto/interface.lua +++ b/server-beta/src/proto/interface.lua @@ -11,7 +11,7 @@ local m = {} function m.offset(lines, text, position) local row = position.line local start = guide.lineRange(lines, row) - local col = utf8.offset(text, position.character, start) + local col = utf8.offset(text, position.character + 1, start) local offset = guide.offsetOf(lines, row, col) return offset end @@ -25,7 +25,7 @@ end function m.position(lines, text, offset) local row, col = guide.positionOf(lines, offset) local start = guide.lineRange(lines, row) - local ucol = utf8.len(text, start, col, true) + local ucol = utf8.len(text, start + 1, col, true) return { line = row, character = ucol, @@ -56,4 +56,18 @@ function m.location(uri, range) } end +---@alias locationLink table +---@param uri string +---@param range range +---@param selection range +---@param origin range +function m.locationLink(uri, range, selection, origin) + return { + targetUri = uri, + targetRange = range, + targetSelectionRange = selection, + originSelectionRange = origin, + } +end + return m diff --git a/server-beta/src/proto/provider.lua b/server-beta/src/proto/provider.lua index 41b41fdd..9e3fe019 100644 --- a/server-beta/src/proto/provider.lua +++ b/server-beta/src/proto/provider.lua @@ -1,10 +1,10 @@ -local util = require 'utility' -local cap = require 'proto.capability' -local pub = require 'pub' -local task = require 'task' -local files = require 'files' -local proto = require 'proto.proto' -local interface = require 'proto.interface' +local util = require 'utility' +local cap = require 'proto.capability' +local pub = require 'pub' +local task = require 'task' +local files = require 'files' +local proto = require 'proto.proto' +local inte = require 'proto.interface' proto.on('initialize', function (params) --log.debug(util.dump(params)) @@ -59,14 +59,22 @@ proto.on('textDocument/hover', function () end) proto.on('textDocument/definition', function (params) - local clock = os.clock() local core = require 'core.definition' local uri = params.textDocument.uri local ast = files.getAst(uri) local text = files.getText(uri) - local offset = interface.offset(ast.lines, text, params.position) - local result, correct - repeat - result, correct = core(ast, text, offset) - until correct or os.clock() - clock >= 1.0 + local offset = inte.offset(ast.lines, text, params.position) + local result = core(ast, text, offset) + if not result then + return nil + end + local response = {} + for i, info in ipairs(result) do + response[i] = inte.locationLink(info.uri + , inte.range(ast.lines, text, info.target.start, info.target.finish) + , inte.range(ast.lines, text, info.target.start, info.target.finish) + , inte.range(ast.lines, text, info.source.start, info.source.finish) + ) + end + return response end) |