summaryrefslogtreecommitdiff
path: root/src/method
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2018-11-19 16:16:27 +0800
committer最萌小汐 <sumneko@hotmail.com>2018-11-19 16:16:27 +0800
commited1bf904bc15c97344dc59745c32d3f741eb1449 (patch)
tree5996f587858d62241f2bd483c7bcc0affca6e4d8 /src/method
parent14f6d57ba711eb2d64470270ee7191181bfa25dc (diff)
downloadlua-language-server-ed1bf904bc15c97344dc59745c32d3f741eb1449.zip
转到定义
Diffstat (limited to 'src/method')
-rw-r--r--src/method/init.lua1
-rw-r--r--src/method/textDocument/definition.lua35
-rw-r--r--src/method/textDocument/didChange.lua5
-rw-r--r--src/method/textDocument/didOpen.lua4
4 files changed, 43 insertions, 2 deletions
diff --git a/src/method/init.lua b/src/method/init.lua
index 972c7e16..35a5a124 100644
--- a/src/method/init.lua
+++ b/src/method/init.lua
@@ -5,6 +5,7 @@ local function init(name)
end
init 'initialize'
+init 'textDocument/definition'
init 'textDocument/didOpen'
init 'textDocument/didChange'
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
diff --git a/src/method/textDocument/didChange.lua b/src/method/textDocument/didChange.lua
index f8fe4320..09c62a6f 100644
--- a/src/method/textDocument/didChange.lua
+++ b/src/method/textDocument/didChange.lua
@@ -1,5 +1,8 @@
return function (lsp, params)
+ local doc = params.textDocument
+ local change = params.contentChanges
+ log.debug('更新文件:', doc.uri)
-- TODO 支持差量更新
- lsp:saveText(params.url, params.version, params.text)
+ lsp:saveText(doc.uri, doc.version, change[1].text)
return true
end
diff --git a/src/method/textDocument/didOpen.lua b/src/method/textDocument/didOpen.lua
index 79392a79..8be4fa89 100644
--- a/src/method/textDocument/didOpen.lua
+++ b/src/method/textDocument/didOpen.lua
@@ -1,4 +1,6 @@
return function (lsp, params)
- lsp:saveText(params.url, params.version, arams.text)
+ local doc = params.textDocument
+ log.debug('打开文件:', doc.uri)
+ lsp:saveText(doc.uri, doc.version, doc.text)
return true
end