diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2022-11-03 17:20:30 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2022-11-03 17:20:30 +0800 |
commit | 45ba0743c75d0f2b68765db0240f150681808205 (patch) | |
tree | 7dc6c8f4e4ca776abc6c87cc80b9859f3c08d17d /script/parser | |
parent | 213f5176ff3125feab1e743ef57abba0e18a44a5 (diff) | |
download | lua-language-server-45ba0743c75d0f2b68765db0240f150681808205.zip |
support `self` type
#1505
Diffstat (limited to 'script/parser')
-rw-r--r-- | script/parser/guide.lua | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/script/parser/guide.lua b/script/parser/guide.lua index b22c55f0..f7dcc116 100644 --- a/script/parser/guide.lua +++ b/script/parser/guide.lua @@ -1307,7 +1307,6 @@ function m.isBlockType(source) return blockTypes[source.type] == true end - ---@param source parser.object ---@return parser.object? function m.getSelfNode(source) @@ -1331,18 +1330,23 @@ function m.getSelfNode(source) return getmethod.node end if args.type == 'funcargs' then - local func = args.parent - if func.type ~= 'function' then - return nil - end - local setmethod = func.parent - if setmethod.type ~= 'setmethod' then - return nil - end - return setmethod.node + return m.getFunctionSelfNode(args.parent) end return nil end +---@param func parser.object +---@return parser.object? +function m.getFunctionSelfNode(func) + if func.type ~= 'function' then + return nil + end + local parent = func.parent + if parent.type == 'setmethod' + or parent.type == 'setfield' then + return parent.node + end + return nil +end return m |