From f1c1debb06035e2b9c11cb0a8486d14561bfc066 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Tue, 12 Mar 2019 12:58:43 +0800 Subject: =?UTF-8?q?=E4=BF=AE=E6=AD=A3bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/src/core/document_symbol.lua | 4 ++-- server/test/document_symbol/init.lua | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) (limited to 'server') diff --git a/server/src/core/document_symbol.lua b/server/src/core/document_symbol.lua index dd18ac23..18af9ceb 100644 --- a/server/src/core/document_symbol.lua +++ b/server/src/core/document_symbol.lua @@ -57,7 +57,7 @@ local function buildLocal(vm, source, callback) -- 由于范围不允许交叉,为了支持 local x, y, z = 1, 2, 3 的形式 -- 范围只能限定在变量上 -- 而 local function xx() 的形式范围会包含整个 function - if source.start > valueSource.start then + if source.start > valueSource.start and source.finish < valueSource.finish then callback { name = name, detail = hvr.label:gsub('[\r\n]', ''), @@ -111,7 +111,7 @@ local function buildSet(vm, source, callback) -- 由于范围不允许交叉,为了支持 x, y, z = 1, 2, 3 的形式 -- 范围只能限定在变量上 -- 而 function xx() 的形式范围会包含整个 function - if source.start > valueSource.start then + if source.start > valueSource.start and source.finish < valueSource.finish then callback { name = name, -- 前端不支持多行 diff --git a/server/test/document_symbol/init.lua b/server/test/document_symbol/init.lua index f73cd6ba..fb75c3a7 100644 --- a/server/test/document_symbol/init.lua +++ b/server/test/document_symbol/init.lua @@ -61,6 +61,19 @@ local function eq(a, b) return a == b end +local function checkArcoss(symbols) + local lastFinish = 0 + for _, symbol in ipairs(symbols) do + assert(symbol.range[1] <= symbol.selectionRange[1]) + assert(symbol.range[2] >= symbol.selectionRange[2]) + assert(symbol.range[2] > lastFinish) + lastFinish = symbol.range[2] + if symbol.children then + checkArcoss(symbol.children) + end + end +end + function TEST(script) return function (expect) local ast = parser:ast(script) @@ -68,6 +81,7 @@ function TEST(script) assert(vm) local result = core.documentSymbol(vm) assert(eq(expect, result)) + checkArcoss(result) end end -- cgit v1.2.3