summaryrefslogtreecommitdiff
path: root/src/matcher
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2018-11-20 14:01:23 +0800
committer最萌小汐 <sumneko@hotmail.com>2018-11-20 14:01:23 +0800
commit307700732c915fc81de4ff60513b89735f882567 (patch)
treeb9a9c910ba20d44316764cd0de84f8d03601c8d5 /src/matcher
parent8d5bc3299d3bc02f3ff295efc22d9b00f373af7f (diff)
downloadlua-language-server-307700732c915fc81de4ff60513b89735f882567.zip
跳过同级的逻辑分支
Diffstat (limited to 'src/matcher')
-rw-r--r--src/matcher/implementation.lua49
1 files changed, 40 insertions, 9 deletions
diff --git a/src/matcher/implementation.lua b/src/matcher/implementation.lua
index 3bb37d25..3e823d5b 100644
--- a/src/matcher/implementation.lua
+++ b/src/matcher/implementation.lua
@@ -9,6 +9,21 @@ local colonPos
local DUMMY_TABLE = {}
+local function logicPush()
+ local scope = scopes[#scopes]
+ scope.logicId = (scope.logicId or 0) + 1
+end
+
+local function logicFlush()
+ local scope = scopes[#scopes]
+ scope.logicId = nil
+end
+
+local function logicGet()
+ local scope = scopes[#scopes-1]
+ return scope and scope.logicId
+end
+
local function scopeInit()
scopes = {{}}
end
@@ -35,7 +50,17 @@ local function scopeSet(obj)
end
end
+local function scopePush()
+ scopes[#scopes+1] = {}
+end
+
+local function scopePop()
+ scopes[#scopes] = nil
+end
+
local function globalSet(obj)
+ obj.logicId = logicGet()
+ obj.scopeId = #scopes
local name = obj[1]
for i = #scopes, 1, -1 do
local scope = scopes[i]
@@ -49,14 +74,6 @@ local function globalSet(obj)
scope[name] = {obj}
end
-local function scopePush()
- scopes[#scopes+1] = {}
-end
-
-local function scopePop()
- scopes[#scopes] = nil
-end
-
local function checkImplementation(name, p)
if result ~= nil then
return
@@ -66,6 +83,8 @@ local function checkImplementation(name, p)
end
local list = scopeGet(name)
if list then
+ local logicId = logicGet()
+ local scopeId = #scopes
result = {}
for i = #list, 1, -1 do
local obj = list[i]
@@ -73,8 +92,13 @@ local function checkImplementation(name, p)
if not finish then
finish = start + #name - 1
end
+ -- 跳过同层的逻辑分支
+ if logicId and scopeId == obj.scopeId and logicId ~= obj.logicId then
+ goto CONTINUE
+ end
result[#result+1] = {start, finish}
- break
+ do break end
+ ::CONTINUE::
end
else
result = false
@@ -207,6 +231,7 @@ function defs.Do()
end
function defs.IfDef()
+ logicPush()
scopePush()
end
@@ -215,6 +240,7 @@ function defs.If()
end
function defs.ElseIfDef()
+ logicPush()
scopePush()
end
@@ -223,6 +249,7 @@ function defs.ElseIf()
end
function defs.ElseDef()
+ logicPush()
scopePush()
end
@@ -230,6 +257,10 @@ function defs.Else()
scopePop()
end
+function defs.EndIf()
+ logicFlush()
+end
+
function defs.LoopDef(name)
scopePush()
scopeSet(name)