summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2020-09-24 00:50:51 +0800
committer最萌小汐 <sumneko@hotmail.com>2020-09-24 00:50:51 +0800
commit179cff25bd6005c3408edc57baa5bb13aec60c29 (patch)
treec1f21ce1b86cf5d88c082d8a124f5ae0f4f95787
parentb522a2d357c35c5b6d4a89625d3cc0f4a98a19a4 (diff)
downloadlua-language-server-179cff25bd6005c3408edc57baa5bb13aec60c29.zip
接入文件符号
-rw-r--r--script-beta/await.lua8
-rw-r--r--script-beta/core/document-symbol.lua4
-rw-r--r--script-beta/provider/capability.lua2
-rw-r--r--script-beta/provider/provider.lua50
4 files changed, 55 insertions, 9 deletions
diff --git a/script-beta/await.lua b/script-beta/await.lua
index 4b63b8ef..00c2bcd0 100644
--- a/script-beta/await.lua
+++ b/script-beta/await.lua
@@ -64,14 +64,6 @@ function m.await(callback, ...)
end, ...)
end
---- 设置一个可继承的关闭器,在设置时,以及创建子协程时会调用
-function m.setCloser(callback, co)
- co = co or coroutine.running()
- local current = m.coMap[co]
- current[callback] = true
- callback(co)
-end
-
--- 设置一个id,用于批量关闭任务
function m.setID(id, co)
co = co or coroutine.running()
diff --git a/script-beta/core/document-symbol.lua b/script-beta/core/document-symbol.lua
index 32bb4940..2eb4eef6 100644
--- a/script-beta/core/document-symbol.lua
+++ b/script-beta/core/document-symbol.lua
@@ -213,6 +213,10 @@ return function (uri)
buildSource(source, used, symbols)
end)
+ if #symbols == 0 then
+ return nil
+ end
+
local packedSymbols = packSymbols(symbols)
return packedSymbols
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)