diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2020-11-16 14:07:10 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2020-11-16 14:07:10 +0800 |
commit | 7e97893e92f694b65f58630cba04d0732ca75e23 (patch) | |
tree | ea0cf3856fa419ad28f7fbb555d449aed41a248a /script-beta | |
parent | 8c464f8fa237d85d2c99c7b36d8a62d9bcecda81 (diff) | |
download | lua-language-server-7e97893e92f694b65f58630cba04d0732ca75e23.zip |
整理代码
Diffstat (limited to 'script-beta')
-rw-r--r-- | script-beta/core/completion.lua | 10 | ||||
-rw-r--r-- | script-beta/core/definition.lua | 10 | ||||
-rw-r--r-- | script-beta/core/hover/description.lua | 10 | ||||
-rw-r--r-- | script-beta/vm/getLibrary.lua | 8 |
4 files changed, 23 insertions, 15 deletions
diff --git a/script-beta/core/completion.lua b/script-beta/core/completion.lua index d2f53d8f..1939025d 100644 --- a/script-beta/core/completion.lua +++ b/script-beta/core/completion.lua @@ -670,11 +670,11 @@ local function checkUri(ast, text, offset, results) local call = callargs.parent local func = call.node local literal = guide.getLiteral(source) - local lib = vm.getLibrary(func) - if not lib then + local libName = vm.getLibraryName(func) + if not libName then return end - if lib.name == 'require' then + if libName == 'require' then for uri in files.eachFile() do uri = files.getOriginUri(uri) if files.eq(myUri, uri) then @@ -701,8 +701,8 @@ local function checkUri(ast, text, offset, results) end ::CONTINUE:: end - elseif lib.name == 'dofile' - or lib.name == 'loadfile' then + elseif libName == 'dofile' + or libName == 'loadfile' then for uri in files.eachFile() do uri = files.getOriginUri(uri) if files.eq(myUri, uri) then diff --git a/script-beta/core/definition.lua b/script-beta/core/definition.lua index 63af4034..19bab22d 100644 --- a/script-beta/core/definition.lua +++ b/script-beta/core/definition.lua @@ -64,14 +64,14 @@ local function checkRequire(source, offset) local call = callargs.parent local func = call.node local literal = guide.getLiteral(source) - local lib = vm.getLibrary(func) - if not lib then + local libName = vm.getLibraryName(func) + if not libName then return nil end - if lib.name == 'require' then + if libName == 'require' then return workspace.findUrisByRequirePath(literal) - elseif lib.name == 'dofile' - or lib.name == 'loadfile' then + elseif libName == 'dofile' + or libName == 'loadfile' then return workspace.findUrisByFilePath(literal) end return nil diff --git a/script-beta/core/hover/description.lua b/script-beta/core/hover/description.lua index 8192beec..badeade7 100644 --- a/script-beta/core/hover/description.lua +++ b/script-beta/core/hover/description.lua @@ -15,14 +15,14 @@ local function asStringInRequire(source, literal) local result, searchers local call = parent.parent local func = call.node - local lib = vm.getLibrary(func) - if not lib then + local libName = vm.getLibraryName(func) + if not libName then return end - if lib.name == 'require' then + if libName == 'require' then result, searchers = ws.findUrisByRequirePath(literal) - elseif lib.name == 'dofile' - or lib.name == 'loadfile' then + elseif libName == 'dofile' + or libName == 'loadfile' then result = ws.findUrisByFilePath(literal) end if result and #result > 0 then diff --git a/script-beta/vm/getLibrary.lua b/script-beta/vm/getLibrary.lua index 36d53c84..86f1ae58 100644 --- a/script-beta/vm/getLibrary.lua +++ b/script-beta/vm/getLibrary.lua @@ -55,6 +55,14 @@ function vm.getLibrary(source, deep) end end +function vm.getLibraryName(source, deep) + local lib = vm.getLibrary(source, deep) + if lib then + return lib.name + end + return nil +end + local globalLibraryNames = { 'arg', 'assert', 'collectgarbage', 'dofile', '_G', 'getfenv', 'getmetatable', 'ipairs', 'load', 'loadfile', 'loadstring', |