diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2020-09-24 00:50:51 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2020-09-24 00:50:51 +0800 |
commit | 179cff25bd6005c3408edc57baa5bb13aec60c29 (patch) | |
tree | c1f21ce1b86cf5d88c082d8a124f5ae0f4f95787 /script-beta/provider | |
parent | b522a2d357c35c5b6d4a89625d3cc0f4a98a19a4 (diff) | |
download | lua-language-server-179cff25bd6005c3408edc57baa5bb13aec60c29.zip |
接入文件符号
Diffstat (limited to 'script-beta/provider')
-rw-r--r-- | script-beta/provider/capability.lua | 2 | ||||
-rw-r--r-- | script-beta/provider/provider.lua | 50 |
2 files changed, 51 insertions, 1 deletions
diff --git a/script-beta/provider/capability.lua b/script-beta/provider/capability.lua index 29261b77..b5ae8e8b 100644 --- a/script-beta/provider/capability.lua +++ b/script-beta/provider/capability.lua @@ -15,7 +15,7 @@ m.initer = { renameProvider = { prepareProvider = true, }, - --documentSymbolProvider = true, + documentSymbolProvider = true, documentHighlightProvider = true, --codeActionProvider = true, signatureHelpProvider = { diff --git a/script-beta/provider/provider.lua b/script-beta/provider/provider.lua index 656ff278..36f42033 100644 --- a/script-beta/provider/provider.lua +++ b/script-beta/provider/provider.lua @@ -13,6 +13,7 @@ local client = require 'provider.client' local furi = require 'file-uri' local pub = require 'pub' local fs = require 'bee.filesystem' +local lang = require 'language' local function updateConfig() local configs = proto.awaitRequest('workspace/configuration', { @@ -475,3 +476,52 @@ proto.on('textDocument/signatureHelp', function (params) signatures = infos, } end) + +proto.on('textDocument/documentSymbol', function (params) + local core = require 'core.document-symbol' + await.close('textDocument/documentSymbol') + await.setID('textDocument/documentSymbol') + local uri = params.textDocument.uri + local lines = files.getLines(uri) + local text = files.getText(uri) + while not lines or not text do + await.sleep(0.1) + lines = files.getLines(uri) + text = files.getText(uri) + end + + local symbols = core(uri) + if not symbols then + return nil + end + + local function convert(symbol) + await.delay() + symbol.range = define.range( + lines, + text, + symbol.range[1], + symbol.range[2] + ) + symbol.selectionRange = define.range( + lines, + text, + symbol.selectionRange[1], + symbol.selectionRange[2] + ) + if symbol.name == '' then + symbol.name = lang.script.SYMBOL_ANONYMOUS + end + if symbol.children then + for _, child in ipairs(symbol.children) do + convert(child) + end + end + end + + for _, symbol in ipairs(symbols) do + convert(symbol) + end + + return symbols +end) |