diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2018-11-19 17:42:28 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2018-11-19 17:42:28 +0800 |
commit | c25e44113af96356dddf8098c375e2537ebb1b4d (patch) | |
tree | a0b643f5d2e7a483feeb7670481c45cae448f3bd /src/matcher/definition.lua | |
parent | 229dfbac9f2b97c8aca3c565504d3aa0e99d5ab5 (diff) | |
download | lua-language-server-c25e44113af96356dddf8098c375e2537ebb1b4d.zip |
支持 self
Diffstat (limited to 'src/matcher/definition.lua')
-rw-r--r-- | src/matcher/definition.lua | 41 |
1 files changed, 29 insertions, 12 deletions
diff --git a/src/matcher/definition.lua b/src/matcher/definition.lua index 2054afc3..9ac0e047 100644 --- a/src/matcher/definition.lua +++ b/src/matcher/definition.lua @@ -5,28 +5,26 @@ local defs = {} local scopes local result local namePos +local colonPos local DUMMY_TABLE = {} -local function getResult(name, p) - result = {name, p} -end - local function scopeInit() scopes = {{}} end -local function scopeSet(name) +local function scopeSet(obj) local scope = scopes[#scopes] - scope[name[1]] = name[2] + local name = obj[1] + scope[name] = obj end local function scopeGet(name) for i = #scopes, 1, -1 do local scope = scopes[i] - local p = scope[name] - if p then - return p + local obj = scope[name] + if obj then + return obj end end return nil @@ -44,7 +42,7 @@ local function checkDifinition(name, p) if pos < p or pos > p + #name then return end - getResult(name, scopeGet(name)) + result = scopeGet(name) end function defs.NamePos(p) @@ -65,6 +63,15 @@ function defs.DOTS(str) return {str, namePos} end +function defs.COLONPos(p) + colonPos = p +end + +function defs.ColonName(name) + name.colon = colonPos + return name +end + function defs.LocalVar(names) for _, name in ipairs(names) do scopeSet(name) @@ -96,6 +103,13 @@ function defs.FunctionDef(names, args) scopeSet(names[1]) end scopePush() + -- 判断隐藏的局部变量self + if #names > 0 then + local name = names[#names] + if name.colon then + scopeSet {'self', name.colon, name.colon} + end + end for _, arg in ipairs(args) do scopeSet(arg) end @@ -191,9 +205,12 @@ return function (buf, pos_) if not result then return false, 'No word' end - local name, start = result[1], result[2] + local name, start, finish = result[1], result[2], result[3] if not start then return false, 'No match' end - return true, start, start + #name - 1 + if not finish then + finish = start + #name - 1 + end + return true, start, finish end |