diff options
Diffstat (limited to 'script')
-rw-r--r-- | script/client.lua | 6 | ||||
-rw-r--r-- | script/proto/converter.lua | 41 | ||||
-rw-r--r-- | script/proto/define.lua | 32 | ||||
-rw-r--r-- | script/provider/diagnostic.lua | 4 | ||||
-rw-r--r-- | script/provider/provider.lua | 14 |
5 files changed, 53 insertions, 44 deletions
diff --git a/script/client.lua b/script/client.lua index c539a0f7..e77eaaae 100644 --- a/script/client.lua +++ b/script/client.lua @@ -216,15 +216,15 @@ function m.setConfig(changes, onlyMemory) end end ----@alias textEdit {start: integer, finish: integer, text: string} +---@alias textEditor {start: integer, finish: integer, text: string} ---@param uri uri ----@param edits textEdit[] +---@param edits textEditor[] function m.editText(uri, edits) local files = require 'files' local textEdits = {} for i, edit in ipairs(edits) do - textEdits[i] = define.textEdit(converter.packRange(uri, edit.start, edit.finish), edit.text) + textEdits[i] = converter.textEdit(converter.packRange(uri, edit.start, edit.finish), edit.text) end proto.request('workspace/applyEdit', { edit = { diff --git a/script/proto/converter.lua b/script/proto/converter.lua index 4b4b9f5d..b8744181 100644 --- a/script/proto/converter.lua +++ b/script/proto/converter.lua @@ -18,6 +18,7 @@ end ---@param uri uri ---@param position position +---@return integer function m.unpackPosition(uri, position) local pos = guide.positionOf(position.line, position.character) return pos @@ -47,4 +48,44 @@ function m.unpackRange(uri, range) return start, finish end +---@alias location {uri: uri, range: range} + +---@param uri string +---@param range range +---@return location +function m.location(uri, range) + return { + uri = uri, + range = range, + } +end + +---@alias locationLink {targetUri:uri, targetRange: range, targetSelectionRange: range, originSelectionRange: range} + +---@param uri string +---@param range range +---@param selection range +---@param origin range +---@return locationLink +function m.locationLink(uri, range, selection, origin) + return { + targetUri = uri, + targetRange = range, + targetSelectionRange = selection, + originSelectionRange = origin, + } +end + +---@alias textEdit {range: range, newText: string} + +---@param range range +---@param newtext string +---@return textEdit +function m.textEdit(range, newtext) + return { + range = range, + newText = newtext, + } +end + return m diff --git a/script/proto/define.lua b/script/proto/define.lua index 2e61bc3e..0cdc6406 100644 --- a/script/proto/define.lua +++ b/script/proto/define.lua @@ -1,37 +1,5 @@ local m = {} ----@alias location table ----@param uri string ----@param range range ----@return location -function m.location(uri, range) - return { - uri = uri, - range = range, - } -end - ----@alias locationLink table ----@param uri string ----@param range range ----@param selection range ----@param origin range -function m.locationLink(uri, range, selection, origin) - return { - targetUri = uri, - targetRange = range, - targetSelectionRange = selection, - originSelectionRange = origin, - } -end - -function m.textEdit(range, newtext) - return { - range = range, - newText = newtext, - } -end - --- 诊断等级 m.DiagnosticSeverity = { Error = 1, diff --git a/script/provider/diagnostic.lua b/script/provider/diagnostic.lua index ec579428..37c25cf9 100644 --- a/script/provider/diagnostic.lua +++ b/script/provider/diagnostic.lua @@ -49,7 +49,7 @@ local function buildSyntaxError(uri, err) local relUri = rel.uri relatedInformation[#relatedInformation+1] = { message = rmessage, - location = define.location(relUri, converter.packRange(relUri, rel.start, rel.finish)), + location = converter.location(relUri, converter.packRange(relUri, rel.start, rel.finish)), } end end @@ -76,7 +76,7 @@ local function buildDiagnostic(uri, diag) local rtext = files.getText(rel.uri) relatedInformation[#relatedInformation+1] = { message = rel.message or rtext:sub(rel.start, rel.finish), - location = define.location(rel.uri, converter.packRange(rel.uri, rel.start, rel.finish)) + location = converter.location(rel.uri, converter.packRange(rel.uri, rel.start, rel.finish)) } end end diff --git a/script/provider/provider.lua b/script/provider/provider.lua index af62372b..938b3102 100644 --- a/script/provider/provider.lua +++ b/script/provider/provider.lua @@ -217,13 +217,13 @@ proto.on('textDocument/definition', function (params) if targetUri then if files.exists(targetUri) then if client.getAbility 'textDocument.definition.linkSupport' then - response[i] = define.locationLink(targetUri + response[i] = converter.locationLink(targetUri , converter.packRange(targetUri, info.target.start, info.target.finish) , converter.packRange(targetUri, info.target.start, info.target.finish) , converter.packRange(uri, info.source.start, info.source.finish) ) else - response[i] = define.location(targetUri + response[i] = converter.location(targetUri , converter.packRange(targetUri, info.target.start, info.target.finish) ) end @@ -252,13 +252,13 @@ proto.on('textDocument/typeDefinition', function (params) if targetUri then if files.exists(targetUri) then if client.getAbility 'textDocument.typeDefinition.linkSupport' then - response[i] = define.locationLink(targetUri + response[i] = converter.locationLink(targetUri , converter.packRange(targetUri, info.target.start, info.target.finish) , converter.packRange(targetUri, info.target.start, info.target.finish) , converter.packRange(uri, info.source.start, info.source.finish) ) else - response[i] = define.location(targetUri + response[i] = converter.location(targetUri , converter.packRange(targetUri, info.target.start, info.target.finish) ) end @@ -284,7 +284,7 @@ proto.on('textDocument/references', function (params) local response = {} for i, info in ipairs(result) do local targetUri = info.uri - response[i] = define.location(targetUri + response[i] = converter.location(targetUri , converter.packRange(targetUri, info.target.start, info.target.finish) ) end @@ -333,7 +333,7 @@ proto.on('textDocument/rename', function (params) if not workspaceEdit.changes[ruri] then workspaceEdit.changes[ruri] = {} end - local textEdit = define.textEdit(converter.packRange(ruri, info.start, info.finish), info.text) + local textEdit = converter.textEdit(converter.packRange(ruri, info.start, info.finish), info.text) workspaceEdit.changes[ruri][#workspaceEdit.changes[ruri]+1] = textEdit end return workspaceEdit @@ -656,7 +656,7 @@ proto.on('workspace/symbol', function (params) end local function convert(symbol) - symbol.location = define.location( + symbol.location = converter.location( symbol.uri, converter.packRange( symbol.uri, |