diff options
-rw-r--r-- | server/src/matcher/definition.lua | 32 | ||||
-rw-r--r-- | server/src/matcher/vm.lua | 5 | ||||
-rw-r--r-- | server/src/method/textDocument/definition.lua | 4 | ||||
-rw-r--r-- | server/src/workspace.lua | 5 |
4 files changed, 32 insertions, 14 deletions
diff --git a/server/src/matcher/definition.lua b/server/src/matcher/definition.lua index 13015cac..4d739fba 100644 --- a/server/src/matcher/definition.lua +++ b/server/src/matcher/definition.lua @@ -1,18 +1,34 @@ local findResult = require 'matcher.find_result' -local function parseResult(result) +local function parseResult(vm, result) local positions = {} local tp = result.type if tp == 'local' then - for _, info in ipairs(result) do - if info.type == 'local' then - positions[#positions+1] = {info.source.start, info.source.finish} + if result.value.uri and result.value.uri ~= vm.uri then + positions[#positions+1] = { + result.value.source.start, + result.value.source.finish, + result.value.uri, + } + else + for _, info in ipairs(result) do + if info.type == 'local' then + positions[#positions+1] = {info.source.start, info.source.finish} + end end end elseif tp == 'field' then - for _, info in ipairs(result) do - if info.type == 'set' then - positions[#positions+1] = {info.source.start, info.source.finish} + if result.value.uri and result.value.uri ~= vm.uri then + positions[#positions+1] = { + result.value.source.start, + result.value.source.finish, + result.value.uri, + } + else + for _, info in ipairs(result) do + if info.type == 'set' then + positions[#positions+1] = {info.source.start, info.source.finish} + end end end elseif tp == 'label' then @@ -30,6 +46,6 @@ return function (vm, pos) if not result then return nil end - local positions = parseResult(result) + local positions = parseResult(vm, result) return positions end diff --git a/server/src/matcher/vm.lua b/server/src/matcher/vm.lua index eafe892c..87f0139a 100644 --- a/server/src/matcher/vm.lua +++ b/server/src/matcher/vm.lua @@ -37,13 +37,13 @@ end local function deepCopy(t, mark, new) mark = mark or {} - new = new or {} + new = new or orderTable() for k, v in pairs(t) do if type(v) == 'table' then if mark[v] then new[k] = mark[v] else - mark[v] = {} + mark[v] = orderTable() new[k] = deepCopy(v, mark, mark[v]) end else @@ -1183,6 +1183,7 @@ function mt:mergeRequire(value, destVM) mainValue = deepCopy(main.returns[1]) end self:mergeValue(value, mainValue) + value.uri = destVM.uri end function mt:loadRequires() diff --git a/server/src/method/textDocument/definition.lua b/server/src/method/textDocument/definition.lua index d2ff7c3f..6be93ff8 100644 --- a/server/src/method/textDocument/definition.lua +++ b/server/src/method/textDocument/definition.lua @@ -15,11 +15,11 @@ return function (lsp, params) local locations = {} for i, position in ipairs(positions) do - local start, finish = position[1], position[2] + local start, finish, valueUri = position[1], position[2], position[3] local start_row, start_col = lines:rowcol(start) local finish_row, finish_col = lines:rowcol(finish) locations[i] = { - uri = uri, + uri = valueUri or uri, range = { start = { line = start_row - 1, diff --git a/server/src/workspace.lua b/server/src/workspace.lua index 23b79525..81afeadd 100644 --- a/server/src/workspace.lua +++ b/server/src/workspace.lua @@ -30,10 +30,11 @@ local function uriEncode(path) while true do local name = cur:filename():string() if name == '' then - name = cur:string() + -- 盘符,去掉一个斜杠 + name = cur:string():sub(1, -2) end name = name:gsub([=[[^%w%-%_%.%~]]=], function (char) - return ('%02X'):format(string.byte(char)) + return ('%%%02X'):format(string.byte(char)) end) table.insert(names, 1, name) if cur == cur:parent_path() then |