diff options
-rw-r--r-- | script-beta/files.lua | 13 | ||||
-rw-r--r-- | script-beta/library.lua | 14 | ||||
-rw-r--r-- | script-beta/workspace/workspace.lua | 17 | ||||
-rw-r--r-- | test-beta.lua | 15 | ||||
-rw-r--r-- | test-beta/completion/init.lua | 4 |
5 files changed, 38 insertions, 25 deletions
diff --git a/script-beta/files.lua b/script-beta/files.lua index 06e598ee..2d2f00da 100644 --- a/script-beta/files.lua +++ b/script-beta/files.lua @@ -174,10 +174,12 @@ function m.removeAll() m.globalVersion = m.globalVersion + 1 await.close('files.version') for uri in pairs(m.fileMap) do - m.fileMap[uri] = nil - m.astMap[uri] = nil - m.linesMap[uri] = nil - m.onWatch('remove', uri) + if not m.libraryMap[uri] then + m.fileMap[uri] = nil + m.astMap[uri] = nil + m.linesMap[uri] = nil + m.onWatch('remove', uri) + end end --m.notifyCache = {} end @@ -187,7 +189,8 @@ function m.removeAllClosed() m.globalVersion = m.globalVersion + 1 await.close('files.version') for uri in pairs(m.fileMap) do - if not m.openMap[uri] then + if not m.openMap[uri] + and not m.libraryMap[uri] then m.fileMap[uri] = nil m.astMap[uri] = nil m.linesMap[uri] = nil diff --git a/script-beta/library.lua b/script-beta/library.lua index a4741fd1..c9cfe32d 100644 --- a/script-beta/library.lua +++ b/script-beta/library.lua @@ -310,19 +310,23 @@ end local function compileMetaDoc() local langID = lang.id local version = config.config.runtime.version - m.metapath = ROOT / 'meta' / config.config.runtime.meta:gsub('%$%{(.-)%}', { + local metapath = ROOT / 'meta' / config.config.runtime.meta:gsub('%$%{(.-)%}', { version = version, language = langID, }) - if fs.exists(m.metapath) then + if fs.exists(metapath) then --return end - fs.create_directory(m.metapath) + m.metaPath = metapath:string() + m.metaPaths = {} + fs.create_directory(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((m.metapath / filename):string(), metaDoc) + local filepath = metapath / filename + util.saveFile(filepath:string(), metaDoc) + m.metaPaths[#m.metaPaths+1] = filepath:string() end end @@ -373,7 +377,7 @@ local function initFromMetaDoc() end local function init() - if DEVELOP then + if DEVELOP or TEST then initFromMetaDoc() else initFromLni() diff --git a/script-beta/workspace/workspace.lua b/script-beta/workspace/workspace.lua index 0050e299..ce8cf161 100644 --- a/script-beta/workspace/workspace.lua +++ b/script-beta/workspace/workspace.lua @@ -125,8 +125,8 @@ function m.getLibraryMatchers() for path, pattern in pairs(config.config.workspace.library) do librarys[path] = pattern end - if library.metapath then - librarys[library.metapath] = true + if library.metaPath then + librarys[library.metaPath] = true end m.libraryMatchers = {} for path, pattern in pairs(librarys) do @@ -153,17 +153,6 @@ function m.isIgnored(uri) return ignore(path) end ---- 文件是否作为库被加载 -function m.isLibrary(uri) - local path = furi.decode(uri) - for _, library in ipairs(m.getLibraryMatchers()) do - if library.matcher(path) then - return true - end - end - return false -end - local function loadFileFactory(root, progress, isLibrary) return function (path) local uri = furi.encode(root .. '/' .. path) @@ -317,7 +306,7 @@ end files.watch(function (ev, uri) if ev == 'close' and m.isIgnored(uri) - and not m.isLibrary(uri) then + and not files.isLibrary(uri) then files.remove(uri) end end) diff --git a/test-beta.lua b/test-beta.lua index 18e33116..14d07650 100644 --- a/test-beta.lua +++ b/test-beta.lua @@ -7,6 +7,7 @@ package.path = package.path local fs = require 'bee.filesystem' ROOT = fs.path(rootPath) LANG = 'zh-CN' +TEST = true collectgarbage 'generational' @@ -15,7 +16,6 @@ log.init(ROOT, ROOT / 'log' / 'test.log') log.debug('测试开始') ac = {} -require 'utility' --dofile((ROOT / 'build_package.lua'):string()) local function loadAllLibs() @@ -27,6 +27,18 @@ local function loadAllLibs() assert(require 'lpeglabel') end +local function loadDocMetas() + local files = require 'files' + local library = require 'library' + local furi = require 'file-uri' + local fsu = require 'fs-utility' + for _, path in ipairs(library.metaPaths) do + local uri = furi.encode(path) + files.setText(uri, fsu.loadFile(path)) + files.setLibraryPath(uri, library.metaPath) + end +end + local function main() debug.setcstacklimit(1000) require 'parser.guide'.debugMode = true @@ -40,6 +52,7 @@ local function main() local config = require 'config' config.config.runtime.version = 'Lua 5.4' config.config.intelliSense.searchDepth = 5 + loadDocMetas() test 'references' test 'definition' diff --git a/test-beta/completion/init.lua b/test-beta/completion/init.lua index 2fc1a913..e11bd0fb 100644 --- a/test-beta/completion/init.lua +++ b/test-beta/completion/init.lua @@ -1498,6 +1498,10 @@ end label = 'deprecated', kind = define.CompletionItemKind.Event, }, + { + label = 'meta', + kind = define.CompletionItemKind.Event, + }, } TEST [[ |