diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2018-11-19 16:16:27 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2018-11-19 16:16:27 +0800 |
commit | ed1bf904bc15c97344dc59745c32d3f741eb1449 (patch) | |
tree | 5996f587858d62241f2bd483c7bcc0affca6e4d8 /src/method/textDocument/definition.lua | |
parent | 14f6d57ba711eb2d64470270ee7191181bfa25dc (diff) | |
download | lua-language-server-ed1bf904bc15c97344dc59745c32d3f741eb1449.zip |
转到定义
Diffstat (limited to 'src/method/textDocument/definition.lua')
-rw-r--r-- | src/method/textDocument/definition.lua | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/src/method/textDocument/definition.lua b/src/method/textDocument/definition.lua new file mode 100644 index 00000000..ef9f4c17 --- /dev/null +++ b/src/method/textDocument/definition.lua @@ -0,0 +1,35 @@ +local parser = require 'parser' +local matcher = require 'matcher' + +return function (lsp, params) + log.debug(table.dump(params)) + local uri = params.textDocument.uri + local text = lsp:loadText(uri) + if not text then + return nil, '找不到文件:' .. uri + end + -- lua是从1开始的,因此都要+1 + local pos = parser.calcline.position(text, params.position.line + 1, params.position.character + 1) + local suc, start, finish = matcher.definition(text, pos) + if not suc then + return nil, start + end + + local start_row, start_col = parser.calcline.rowcol(text, start) + local finish_row, finish_col = parser.calcline.rowcol(text, finish) + + local response = { + uri = uri, + range = { + start = { + line = start_row - 1, + character = start_col - 1, + }, + ['end'] = { + line = finish_row - 1, + character = finish_col - 1, + }, + }, + } + return response +end |