summaryrefslogtreecommitdiff
path: root/server-beta
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2019-11-17 17:36:23 +0800
committer最萌小汐 <sumneko@hotmail.com>2019-11-17 17:36:23 +0800
commita139003e6f239650baaef69f747c7ee9558d0170 (patch)
tree79a1c1d821abe107f7060cd0c6214164539f5b7c /server-beta
parent6b25262260be44f3478d11b7bcb22bc22fba781b (diff)
downloadlua-language-server-a139003e6f239650baaef69f747c7ee9558d0170.zip
rename
Diffstat (limited to 'server-beta')
-rw-r--r--server-beta/src/proto/define.lua7
-rw-r--r--server-beta/src/provider/capability.lua2
-rw-r--r--server-beta/src/provider/init.lua29
3 files changed, 37 insertions, 1 deletions
diff --git a/server-beta/src/proto/define.lua b/server-beta/src/proto/define.lua
index a6ad7e47..2319a219 100644
--- a/server-beta/src/proto/define.lua
+++ b/server-beta/src/proto/define.lua
@@ -81,6 +81,13 @@ function m.locationLink(uri, range, selection, origin)
}
end
+function m.textEdit(range, newtext)
+ return {
+ range = range,
+ newText = newtext,
+ }
+end
+
--- 诊断等级
m.DiagnosticSeverity = {
Error = 1,
diff --git a/server-beta/src/provider/capability.lua b/server-beta/src/provider/capability.lua
index 5cefd0c5..b2b7ee3a 100644
--- a/server-beta/src/provider/capability.lua
+++ b/server-beta/src/provider/capability.lua
@@ -12,7 +12,7 @@ m.initer = {
hoverProvider = true,
definitionProvider = true,
referencesProvider = true,
- --renameProvider = true,
+ renameProvider = true,
--documentSymbolProvider = true,
documentHighlightProvider = true,
--codeActionProvider = true,
diff --git a/server-beta/src/provider/init.lua b/server-beta/src/provider/init.lua
index 0a70763e..1dc092c7 100644
--- a/server-beta/src/provider/init.lua
+++ b/server-beta/src/provider/init.lua
@@ -230,6 +230,35 @@ proto.on('textDocument/documentHighlight', function (params)
return response
end)
+proto.on('textDocument/rename', function (params)
+ local core = require 'core.rename'
+ local uri = params.textDocument.uri
+ if not files.exists(uri) then
+ return nil
+ end
+ local lines = files.getLines(uri)
+ local text = files.getText(uri)
+ local offset = define.offset(lines, text, params.position)
+ local result = core(uri, offset, params.newName)
+ if not result then
+ return nil
+ end
+ local workspaceEdit = {
+ changes = {},
+ }
+ for _, info in ipairs(result) do
+ local ruri = info.uri
+ local rlines = files.getLines(ruri)
+ local rtext = files.getText(ruri)
+ if not workspaceEdit.changes[ruri] then
+ workspaceEdit.changes[ruri] = {}
+ end
+ local textEdit = define.textEdit(define.range(rlines, rtext, info.start, info.finish), info.text)
+ workspaceEdit.changes[ruri][#workspaceEdit.changes[ruri]+1] = textEdit
+ end
+ return workspaceEdit
+end)
+
proto.on('textDocument/completion', function (params)
--log.info(util.dump(params))
return nil