diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2020-11-13 13:02:54 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2020-11-13 13:02:54 +0800 |
commit | c3e280a5bc556cb8ff87a6b0fc6f7a7c48292d4d (patch) | |
tree | 6c94b4cee3af77af9f6eb5dda47826d821200663 /script-beta | |
parent | 27034b3d99b31be96865e50d70a776fb3caac088 (diff) | |
download | lua-language-server-c3e280a5bc556cb8ff87a6b0fc6f7a7c48292d4d.zip |
加载 meta
Diffstat (limited to 'script-beta')
-rw-r--r-- | script-beta/core/semantic-tokens.lua | 30 | ||||
-rw-r--r-- | script-beta/library.lua | 25 | ||||
-rw-r--r-- | script-beta/vm/getLibrary.lua | 21 | ||||
-rw-r--r-- | script-beta/workspace/workspace.lua | 10 |
4 files changed, 61 insertions, 25 deletions
diff --git a/script-beta/core/semantic-tokens.lua b/script-beta/core/semantic-tokens.lua index 0aceca92..351e544a 100644 --- a/script-beta/core/semantic-tokens.lua +++ b/script-beta/core/semantic-tokens.lua @@ -7,27 +7,19 @@ local util = require 'utility' local Care = {} Care['setglobal'] = function (source, results) - results[#results+1] = { - start = source.start, - finish = source.finish, - type = define.TokenTypes.namespace, - modifieres = define.TokenModifiers.deprecated, - } + local isLib = vm.isGlobalLibraryName(source[1]) + if not isLib then + results[#results+1] = { + start = source.start, + finish = source.finish, + type = define.TokenTypes.namespace, + modifieres = define.TokenModifiers.deprecated, + } + end end Care['getglobal'] = function (source, results) - local lib = vm.getLibrary(source) - if lib then - if source[1] == '_G' then - return - else - results[#results+1] = { - start = source.start, - finish = source.finish, - type = define.TokenTypes.namespace, - modifieres = define.TokenModifiers.static, - } - end - else + local isLib = vm.isGlobalLibraryName(source[1]) + if not isLib then results[#results+1] = { start = source.start, finish = source.finish, diff --git a/script-beta/library.lua b/script-beta/library.lua index bbd540cd..78321d6a 100644 --- a/script-beta/library.lua +++ b/script-beta/library.lua @@ -310,23 +310,23 @@ end local function compileMetaDoc() local langID = lang.id local version = config.config.runtime.version - local metaDir = ROOT / 'meta' / config.config.runtime.meta:gsub('%$%{(.-)%}', { + m.metapath = ROOT / 'meta' / config.config.runtime.meta:gsub('%$%{(.-)%}', { version = version, language = langID, }) - if fs.exists(metaDir) then + if fs.exists(m.metapath) then return end - fs.create_directory(metaDir) + fs.create_directory(m.metapath) local templateDir = ROOT / 'meta' / 'template' for fullpath in templateDir:list_directory() do local filename = fullpath:filename() local metaDoc = compileSingleMetaDoc(util.loadFile(fullpath:string())) - util.saveFile((metaDir / filename):string(), metaDoc) + util.saveFile((m.metapath / filename):string(), metaDoc) end end -local function init() +local function initFromLni() local id = lang.id m.global = util.container() m.library = util.container() @@ -361,10 +361,25 @@ local function init() markLibrary(m.object) markLibrary(m.other) markLibrary(m.custom) +end +local function initFromMetaDoc() + m.global = util.container() + m.library = util.container() + m.object = util.container() + m.other = util.container() + m.custom = util.container() compileMetaDoc() end +local function init() + if DEVELOP then + initFromMetaDoc() + else + initFromLni() + end +end + function m.reload() init() end diff --git a/script-beta/vm/getLibrary.lua b/script-beta/vm/getLibrary.lua index 91d7c2e4..36d53c84 100644 --- a/script-beta/vm/getLibrary.lua +++ b/script-beta/vm/getLibrary.lua @@ -54,3 +54,24 @@ function vm.getLibrary(source, deep) return cache end end + +local globalLibraryNames = { + 'arg', 'assert', 'collectgarbage', 'dofile', '_G', 'getfenv', + 'getmetatable', 'ipairs', 'load', 'loadfile', 'loadstring', + 'module', 'next', 'pairs', 'pcall', 'print', 'rawequal', + 'rawget', 'rawlen', 'rawset', 'select', 'setfenv', + 'setmetatable', 'tonumber', 'tostring', 'type', '_VERSION', + 'warn', 'xpcall', 'require', 'unpack', 'bit32', 'coroutine', + 'debug', 'io', 'math', 'os', 'package', 'string', 'table', + 'utf8', +} +local globalLibraryNamesMap +function vm.isGlobalLibraryName(name) + if not globalLibraryNamesMap then + globalLibraryNamesMap = {} + for _, v in ipairs(globalLibraryNames) do + globalLibraryNamesMap[v] = true + end + end + return globalLibraryNamesMap[name] or false +end diff --git a/script-beta/workspace/workspace.lua b/script-beta/workspace/workspace.lua index 543a63a9..0050e299 100644 --- a/script-beta/workspace/workspace.lua +++ b/script-beta/workspace/workspace.lua @@ -9,6 +9,7 @@ local await = require 'await' local rpath = require 'workspace.require-path' local proto = require 'proto.proto' local lang = require 'language' +local library = require 'library' local m = {} m.type = 'workspace' @@ -120,8 +121,15 @@ function m.getLibraryMatchers() return m.libraryMatchers end - m.libraryMatchers = {} + local librarys = {} for path, pattern in pairs(config.config.workspace.library) do + librarys[path] = pattern + end + if library.metapath then + librarys[library.metapath] = true + end + m.libraryMatchers = {} + for path, pattern in pairs(librarys) do local nPath = fs.absolute(fs.path(path)):string() local matcher = glob.gitignore(pattern, m.matchOption) if platform.OS == 'Windows' then |