From 9992c649cde19d4db8c9a9a7b47eb71bb2eaa283 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Thu, 29 Nov 2018 16:55:59 +0800 Subject: =?UTF-8?q?=E9=99=A4=E4=BA=86=E8=A1=A8=E4=BB=A5=E5=A4=96=E7=9A=84?= =?UTF-8?q?=E8=BD=AC=E5=88=B0=E5=AE=9A=E4=B9=89=E8=83=BD=E7=94=A8=E4=BA=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/src/matcher/definition.lua | 19 +++++++++++++++---- server/src/method/initialize.lua | 2 +- server/src/method/textDocument/definition.lua | 13 +++++++++---- 3 files changed, 25 insertions(+), 9 deletions(-) (limited to 'server/src') 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, -- cgit v1.2.3