summaryrefslogtreecommitdiff
path: root/server/src/method
diff options
context:
space:
mode:
Diffstat (limited to 'server/src/method')
-rw-r--r--server/src/method/initialize.lua2
-rw-r--r--server/src/method/textDocument/definition.lua13
2 files changed, 10 insertions, 5 deletions
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,