summaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2019-03-27 17:25:11 +0800
committer最萌小汐 <sumneko@hotmail.com>2019-03-27 17:25:11 +0800
commit0583a7dd28bb21012ac8334b5b2479a378263b6f (patch)
tree18138246ce52b0a8c5f040844aa0a401877c04d1 /server
parente3094b286a53df93368204ff0f8267b261fd3002 (diff)
downloadlua-language-server-0583a7dd28bb21012ac8334b5b2479a378263b6f.zip
挖坑
Diffstat (limited to 'server')
-rw-r--r--server/src/method/init.lua1
-rw-r--r--server/src/method/initialize.lua10
-rw-r--r--server/src/method/textDocument/documentHighlight.lua44
3 files changed, 46 insertions, 9 deletions
diff --git a/server/src/method/init.lua b/server/src/method/init.lua
index 764df987..588129be 100644
--- a/server/src/method/init.lua
+++ b/server/src/method/init.lua
@@ -13,6 +13,7 @@ init 'textDocument/definition'
init 'textDocument/didOpen'
init 'textDocument/didChange'
init 'textDocument/didClose'
+init 'textDocument/documentHighlight'
init 'textDocument/documentSymbol'
init 'textDocument/hover'
init 'textDocument/implementation'
diff --git a/server/src/method/initialize.lua b/server/src/method/initialize.lua
index ba183c5e..538a8f9c 100644
--- a/server/src/method/initialize.lua
+++ b/server/src/method/initialize.lua
@@ -11,19 +11,13 @@ return function (lsp)
lsp._inited = true
return {
capabilities = {
- -- 支持“悬浮”
hoverProvider = true,
- -- 支持“转到定义”
definitionProvider = true,
- -- 支持“转到实现”
implementationProvider = true,
- -- 支持“查找引用”
referencesProvider = true,
- -- 支持“重命名”
renameProvider = true,
- -- 支持“大纲”
documentSymbolProvider = true,
- -- 支持“签名帮助”
+ --documentHighlightProvider = true,
signatureHelpProvider = {
triggerCharacters = { '(', ',' },
},
@@ -34,12 +28,10 @@ return function (lsp)
-- 文本改变时完全通知 TODO 支持差量更新(2)
change = 1,
},
- -- 自动完成
completionProvider = {
resolveProvider = false,
triggerCharacters = allWords(),
},
- -- 工作目录
workspace = {
workspaceFolders = {
supported = true,
diff --git a/server/src/method/textDocument/documentHighlight.lua b/server/src/method/textDocument/documentHighlight.lua
new file mode 100644
index 00000000..95ee0cfe
--- /dev/null
+++ b/server/src/method/textDocument/documentHighlight.lua
@@ -0,0 +1,44 @@
+local core = require 'core'
+
+return function (lsp, params)
+ local uri = params.textDocument.uri
+ local newName = params.newName
+ local vm, lines = lsp:loadVM(uri)
+ if not vm then
+ return {}
+ end
+ local position = lines:positionAsChar(params.position.line + 1, params.position.character)
+ local positions = core.rename(vm, position, newName)
+ if not positions then
+ return {}
+ end
+
+ local TextEdit = {}
+ for i, position in ipairs(positions) do
+ local start, finish = position[1], position[2]
+ local start_row, start_col = lines:rowcol(start)
+ local finish_row, finish_col = lines:rowcol(finish)
+ TextEdit[i] = {
+ newText = newName,
+ range = {
+ start = {
+ line = start_row - 1,
+ character = start_col - 1,
+ },
+ ['end'] = {
+ line = finish_row - 1,
+ -- 这里不用-1,因为前端期待的是匹配完成后的位置
+ character = finish_col,
+ },
+ }
+ }
+ end
+
+ local response = {
+ changes = {
+ [uri] = TextEdit,
+ },
+ }
+
+ return response
+end