diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2018-11-29 16:55:59 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2018-11-29 16:55:59 +0800 |
commit | 9992c649cde19d4db8c9a9a7b47eb71bb2eaa283 (patch) | |
tree | 1c85e8f75ad10c9c5febea94d837a5cfce773072 /server/src | |
parent | b13e39260cc47b90c9b5b095964ea56c1a3d7cd5 (diff) | |
download | lua-language-server-9992c649cde19d4db8c9a9a7b47eb71bb2eaa283.zip |
除了表以外的转到定义能用了
Diffstat (limited to 'server/src')
-rw-r--r-- | server/src/matcher/definition.lua | 19 | ||||
-rw-r--r-- | server/src/method/initialize.lua | 2 | ||||
-rw-r--r-- | server/src/method/textDocument/definition.lua | 13 |
3 files changed, 25 insertions, 9 deletions
diff --git a/server/src/matcher/definition.lua b/server/src/matcher/definition.lua index 0a774a25..9897bcbc 100644 --- a/server/src/matcher/definition.lua +++ b/server/src/matcher/definition.lua @@ -35,7 +35,7 @@ end function mt:searchCall(call) for _, exp in ipairs(call) do - searchExp(exp) + self:searchExp(exp) end return nil end @@ -47,15 +47,12 @@ function mt:searchSimple(simple) local tp = obj.type if tp == 'call' then self:searchCall(obj) - elseif tp == ':' then - self:markLocal(obj) else if obj.index then self:searchExp(obj) end end end - return nil end function mt:searchBinary(exp) @@ -94,6 +91,16 @@ function mt:searchReturn(action) end end +function mt:markSimple(simple) + for i = 2, #simple do + local obj = simple[i] + local tp = obj.type + if tp == ':' then + self:createLocal('self', obj) + end + end +end + function mt:markSet(simple) if simple.type == 'name' then local str = simple[1] @@ -114,6 +121,7 @@ function mt:markSet(simple) self:checkName(simple) else self:searchSimple(simple) + self:markSimple(simple) end end @@ -233,6 +241,7 @@ end function mt:searchFunction(func) self.env:push() + self.env:cut 'dots' if func.name then self:markSet(func.name) end @@ -270,6 +279,8 @@ function mt:searchAction(action) self:markSets(action) elseif tp == 'local' then self:markLocals(action) + elseif tp == 'simple' then + self:searchSimple(action) elseif tp == 'if' then self:searchIfs(action) elseif tp == 'loop' then diff --git a/server/src/method/initialize.lua b/server/src/method/initialize.lua index 0bdd1b7c..ea5bb3c4 100644 --- a/server/src/method/initialize.lua +++ b/server/src/method/initialize.lua @@ -3,7 +3,7 @@ return function (lsp, data) return { capabilities = { -- 支持“转到定义” - --definitionProvider = true, + definitionProvider = true, -- 支持“转到实现” --implementationProvider = true, -- 文本同步方式 diff --git a/server/src/method/textDocument/definition.lua b/server/src/method/textDocument/definition.lua index 3a17b463..0878e29c 100644 --- a/server/src/method/textDocument/definition.lua +++ b/server/src/method/textDocument/definition.lua @@ -8,9 +8,14 @@ return function (lsp, params) return nil, '找不到文件:' .. uri end local start_clock = os.clock() + local ast, err = parser:ast(text) + local lines = parser:lines(text) + if not ast then + return nil, err + end -- lua是从1开始的,因此都要+1 - local pos = parser.calcline.position_utf8(text, params.position.line + 1, params.position.character + 1) - local suc, start, finish = matcher.definition(text, pos) + local position = lines:position(params.position.line + 1, params.position.character + 1) + local suc, start, finish = matcher.definition(ast, position, 'utf8') if not suc then if finish then log.debug(start, uri) @@ -20,8 +25,8 @@ return function (lsp, params) return {} end - local start_row, start_col = parser.calcline.rowcol_utf8(text, start) - local finish_row, finish_col = parser.calcline.rowcol_utf8(text, finish) + local start_row, start_col = lines:rowcol(start, 'utf8') + local finish_row, finish_col = lines:rowcol(finish, 'utf8') local response = { uri = uri, |