summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--script/files.lua1
-rw-r--r--script/workspace/require-path.lua34
-rw-r--r--script/workspace/scope.lua24
-rw-r--r--script/workspace/workspace.lua8
-rw-r--r--test.lua8
-rw-r--r--test/code_action/init.lua6
-rw-r--r--test/command/auto-require.lua8
-rw-r--r--test/completion/init.lua10
-rw-r--r--test/crossfile/completion.lua8
-rw-r--r--test/definition/init.lua8
-rw-r--r--test/diagnostics/init.lua8
-rw-r--r--test/document_symbol/init.lua6
-rw-r--r--test/full/example.lua8
-rw-r--r--test/highlight/init.lua6
-rw-r--r--test/hover/init.lua6
-rw-r--r--test/references/init.lua6
-rw-r--r--test/rename/init.lua10
-rw-r--r--test/signature/init.lua6
-rw-r--r--test/type_formatting/init.lua6
-rw-r--r--test/type_inference/init.lua10
20 files changed, 98 insertions, 89 deletions
diff --git a/script/files.lua b/script/files.lua
index 5172340f..545c6735 100644
--- a/script/files.lua
+++ b/script/files.lua
@@ -465,6 +465,7 @@ function m.getAllUris(suri)
files[i] = uri
end
end
+ table.sort(files)
return files
end
diff --git a/script/workspace/require-path.lua b/script/workspace/require-path.lua
index 1e7c81e5..02b1996d 100644
--- a/script/workspace/require-path.lua
+++ b/script/workspace/require-path.lua
@@ -170,30 +170,24 @@ function mt:findUrisByRequireName(suri, name)
for _, searcher in ipairs(searchers) do
local fspath = searcher:gsub('%?', (path:gsub('%%', '%%%%')))
- local fullPath = workspace.getAbsolutePath(self.scp.uri, fspath)
- if fullPath then
- local fullUri = furi.encode(fullPath)
- if files.exists(fullUri)
- and fullUri ~= suri then
- results[#results+1] = fullUri
- searcherMap[fullUri] = searcher
- end
- end
+ fspath = workspace.normalize(fspath)
local tail = '/' .. furi.encode(fspath):gsub('^file:[/]*', '')
for uri in files.eachFile(self.scp.uri) do
- if not searcherMap[uri]
+ if not searcherMap[uri]
and suri ~= uri
and util.stringEndWith(uri, tail) then
- local parentUri = files.getLibraryUri(self.scp.uri, uri) or self.scp.uri
- if parentUri == nil or parentUri == '' then
- parentUri = furi.encode ''
- end
- local relative = uri:sub(#parentUri + 1):sub(1, - #tail)
- if not strict or relative == "/" then
- results[#results+1] = uri
- end
- searcherMap[uri] = workspace.normalize(relative .. searcher)
- end
+ local parentUri = files.getLibraryUri(self.scp.uri, uri) or self.scp.uri
+ if parentUri == nil or parentUri == '' then
+ parentUri = furi.encode '/'
+ end
+ local relative = uri:sub(#parentUri + 1):sub(1, - #tail)
+ if not strict
+ or relative == '/'
+ or relative == '' then
+ results[#results+1] = uri
+ searcherMap[uri] = workspace.normalize(relative .. searcher)
+ end
+ end
end
end
diff --git a/script/workspace/scope.lua b/script/workspace/scope.lua
index e6fcfeb7..da72a1eb 100644
--- a/script/workspace/scope.lua
+++ b/script/workspace/scope.lua
@@ -37,6 +37,12 @@ function mt:removeAllLinks()
self._links = {}
end
+---@return fun(): uri
+---@return table<uri, true>
+function mt:eachLink()
+ return next, self._links
+end
+
---@param uri uri
---@return boolean
function mt:isChildUri(uri)
@@ -46,14 +52,14 @@ function mt:isChildUri(uri)
if not self.uri then
return false
end
- if self.uri == '' then
- return true
- end
if self.uri == uri then
return true
end
- if uri:sub(1, #self.uri) == self.uri
- and uri:sub(#self.uri + 1, #self.uri + 1) == '/' then
+ if uri:sub(1, #self.uri) ~= self.uri then
+ return false
+ end
+ if uri:sub(#self.uri, #self.uri) == '/'
+ or uri:sub(#self.uri + 1, #self.uri + 1) == '/' then
return true
end
return false
@@ -69,10 +75,14 @@ function mt:isLinkedUri(uri)
if uri == linkUri then
return true
end
- if uri:sub(1, #linkUri) == linkUri
- and uri:sub(#linkUri + 1, #linkUri + 1) == '/' then
+ if uri:sub(1, #linkUri) ~= linkUri then
+ goto CONTINUE
+ end
+ if uri:sub(#linkUri, #linkUri) == '/'
+ or uri:sub(#linkUri + 1, #linkUri + 1) == '/' then
return true
end
+ ::CONTINUE::
end
return false
end
diff --git a/script/workspace/workspace.lua b/script/workspace/workspace.lua
index a1b54f24..45fd6595 100644
--- a/script/workspace/workspace.lua
+++ b/script/workspace/workspace.lua
@@ -49,13 +49,13 @@ function m.create(uri)
uri = furi.normalize(uri)
end
log.info('Workspace create: ', uri)
+ local scp = scope.createFolder(uri)
+ m.folders[#m.folders+1] = scp
if uri == furi.encode '/'
or uri == furi.encode(os.getenv 'HOME' or '') then
client.showMessage('Error', lang.script('WORKSPACE_NOT_ALLOWED', furi.decode(uri)))
- return
+ scp:set('bad root', true)
end
- local scp = scope.createFolder(uri)
- m.folders[#m.folders+1] = scp
end
function m.remove(uri)
@@ -306,7 +306,7 @@ function m.awaitPreload(scp)
local native = m.getNativeMatcher(scp)
local librarys = m.getLibraryMatchers(scp)
- if scp.uri then
+ if scp.uri and not scp:get('bad root') then
log.info('Scan files at:', scp:getName())
local count = 0
---@async
diff --git a/test.lua b/test.lua
index 5af942ea..2a8d97c7 100644
--- a/test.lua
+++ b/test.lua
@@ -76,17 +76,21 @@ local function main()
local lclient = require 'lclient'
local ws = require 'workspace'
+ local furi = require 'file-uri'
--log.print = true
+ TESTURI = furi.encode('/unittest.lua')
+
---@async
lclient():start(function (client)
client:registerFakers()
+ local rootUri = furi.encode '/'
client:initialize {
- rootUri = '',
+ rootUri = rootUri,
}
- ws.awaitReady('')
+ ws.awaitReady(rootUri)
print('Loaded files in', os)
for uri in files.eachFile() do
diff --git a/test/code_action/init.lua b/test/code_action/init.lua
index 67528d59..2329ce4c 100644
--- a/test/code_action/init.lua
+++ b/test/code_action/init.lua
@@ -39,11 +39,11 @@ end
function TEST(script)
return function (expect)
local newScript, catched = catch(script, '?')
- files.setText('', newScript)
- local results = core('', catched['?'][1][1], catched['?'][1][2])
+ files.setText(TESTURI, newScript)
+ local results = core(TESTURI, catched['?'][1][1], catched['?'][1][2])
assert(results)
assert(eq(expect, results))
- files.remove('')
+ files.remove(TESTURI)
end
end
diff --git a/test/command/auto-require.lua b/test/command/auto-require.lua
index 38cc0012..c55fd334 100644
--- a/test/command/auto-require.lua
+++ b/test/command/auto-require.lua
@@ -19,12 +19,12 @@ end
function TEST(text)
return function (name)
return function (expect)
- files.setText('', text)
+ files.setText(TESTURI, text)
EditResult = nil
- local row, fmt = findInsertRow('')
- applyAutoRequire('', row, name, name, fmt)
+ local row, fmt = findInsertRow(TESTURI)
+ applyAutoRequire(TESTURI, row, name, name, fmt)
assert(util.equal(EditResult, expect))
- files.remove('')
+ files.remove(TESTURI)
end
end
end
diff --git a/test/completion/init.lua b/test/completion/init.lua
index 4ae185ca..1ac7fd4b 100644
--- a/test/completion/init.lua
+++ b/test/completion/init.lua
@@ -68,8 +68,8 @@ function TEST(script)
---@diagnostic disable: await-in-sync
local newScript, catched = catch(script, '?')
- files.setText('', newScript)
- local state = files.getState('')
+ files.setText(TESTURI, newScript)
+ local state = files.getState(TESTURI)
local inputPos = catched['?'][1][2]
if ContinueTyping then
local triggerCharacter = script:sub(inputPos - 1, inputPos - 1)
@@ -77,7 +77,7 @@ function TEST(script)
or triggerCharacter:find '%w_' then
triggerCharacter = nil
end
- core.completion('', inputPos, triggerCharacter)
+ core.completion(TESTURI, inputPos, triggerCharacter)
end
local offset = guide.positionToOffset(state, inputPos)
local triggerCharacter = script:sub(offset, offset)
@@ -85,7 +85,7 @@ function TEST(script)
or triggerCharacter:find '%w_' then
triggerCharacter = nil
end
- local result = core.completion('', inputPos, triggerCharacter)
+ local result = core.completion(TESTURI, inputPos, triggerCharacter)
if not expect then
assert(result == nil)
@@ -131,7 +131,7 @@ function TEST(script)
assert(eq(expect, result))
end
end
- files.remove('')
+ files.remove(TESTURI)
end
end
diff --git a/test/crossfile/completion.lua b/test/crossfile/completion.lua
index 4e573c0e..24a5f6c9 100644
--- a/test/crossfile/completion.lua
+++ b/test/crossfile/completion.lua
@@ -376,7 +376,7 @@ config.set(nil, 'Lua.runtime.path', {
TEST {
{
- path = 'D:/xxxx/1.lua',
+ path = 'tt/xxxx/1.lua',
content = '',
},
{
@@ -386,7 +386,7 @@ TEST {
},
completion = {
{
- label = 'D:.xxxx',
+ label = 'tt.xxxx',
kind = CompletionItemKind.File,
textEdit = EXISTS,
},
@@ -402,12 +402,12 @@ config.set(nil, 'Lua.runtime.path', originRuntimePath)
local originRuntimePath = config.get(nil, 'Lua.runtime.path')
config.set(nil, 'Lua.runtime.path', {
- 'D:/?/1.lua',
+ 'tt/?/1.lua',
})
TEST {
{
- path = 'D:/xxxx/1.lua',
+ path = 'tt/xxxx/1.lua',
content = '',
},
{
diff --git a/test/definition/init.lua b/test/definition/init.lua
index 3badaadf..7e0a7989 100644
--- a/test/definition/init.lua
+++ b/test/definition/init.lua
@@ -24,14 +24,14 @@ end
function TEST(script)
local newScript, catched = catch(script, '!?')
- files.setText('', newScript)
+ files.setText(TESTURI, newScript)
- local results = core('', catched['?'][1][1])
+ local results = core(TESTURI, catched['?'][1][1])
if results then
local positions = {}
for i, result in ipairs(results) do
if not vm.isMetaFile(result.uri) then
- positions[i] = { result.target.start, result.target.finish }
+ positions[#positions+1] = { result.target.start, result.target.finish }
end
end
assert(founded(catched['!'], positions))
@@ -39,7 +39,7 @@ function TEST(script)
assert(#catched['!'] == 0)
end
- files.remove('')
+ files.remove(TESTURI)
end
require 'definition.local'
diff --git a/test/diagnostics/init.lua b/test/diagnostics/init.lua
index 2c5dba11..2d2374a5 100644
--- a/test/diagnostics/init.lua
+++ b/test/diagnostics/init.lua
@@ -29,11 +29,11 @@ end
---@diagnostic disable: await-in-sync
function TEST(script, ...)
local newScript, catched = catch(script, '!')
- files.setText('', newScript)
- files.open('')
+ files.setText(TESTURI, newScript)
+ files.open(TESTURI)
local origins = {}
local results = {}
- core('', false, function (result)
+ core(TESTURI, false, function (result)
results[#results+1] = { result.start, result.finish }
origins[#origins+1] = result
end)
@@ -46,7 +46,7 @@ function TEST(script, ...)
assert(#catched['!'] == 0)
end
- files.remove('')
+ files.remove(TESTURI)
end
require 'diagnostics.common'
diff --git a/test/document_symbol/init.lua b/test/document_symbol/init.lua
index 66babc9b..157ba372 100644
--- a/test/document_symbol/init.lua
+++ b/test/document_symbol/init.lua
@@ -48,11 +48,11 @@ end
---@diagnostic disable: await-in-sync
function TEST(script)
return function (expect)
- files.setText('', script)
- local result = core('')
+ files.setText(TESTURI, script)
+ local result = core(TESTURI)
assert(eq(expect, result))
checkArcoss(result)
- files.remove('')
+ files.remove(TESTURI)
end
end
diff --git a/test/full/example.lua b/test/full/example.lua
index 7740d23c..de32d60b 100644
--- a/test/full/example.lua
+++ b/test/full/example.lua
@@ -51,15 +51,15 @@ local function testIfExit(path)
local max = 100
local need
for i = 1, max do
- files.open('')
- files.setText('', buf)
- diag('', false, function () end)
+ files.open(TESTURI)
+ files.setText(TESTURI, buf)
+ diag(TESTURI, false, function () end)
local passed = os.clock() - clock
if passed >= 1.0 or i == max then
need = passed / i
break
end
- files.remove('')
+ files.remove(TESTURI)
end
print(('基准诊断测试[%s]单次耗时:%.10f'):format(path:filename():string(), need))
end
diff --git a/test/highlight/init.lua b/test/highlight/init.lua
index 0cca79f1..399012a8 100644
--- a/test/highlight/init.lua
+++ b/test/highlight/init.lua
@@ -21,18 +21,18 @@ end
function TEST(script)
local newScript, catched = catch(script, '!')
- files.setText('', newScript)
+ files.setText(TESTURI, newScript)
for _, enter in ipairs(catched['!']) do
local start, finish = enter[1], enter[2]
local pos = (start + finish) // 2
- local positions = core('', pos)
+ local positions = core(TESTURI, pos)
local results = {}
for _, position in ipairs(positions) do
results[#results+1] = { position.start, position.finish }
end
assert(founded(catched['!'], results))
end
- files.remove('')
+ files.remove(TESTURI)
end
TEST [[
diff --git a/test/hover/init.lua b/test/hover/init.lua
index 6d58f051..c9e1ecdb 100644
--- a/test/hover/init.lua
+++ b/test/hover/init.lua
@@ -9,13 +9,13 @@ rawset(_G, 'TEST', true)
function TEST(script)
return function (expect)
local newScript, catched = catch(script, '?')
- files.setText('', newScript)
- local hover = core.byUri('', catched['?'][1][1])
+ files.setText(TESTURI, newScript)
+ local hover = core.byUri(TESTURI, catched['?'][1][1])
assert(hover)
expect = expect:gsub('^[\r\n]*(.-)[\r\n]*$', '%1'):gsub('\r\n', '\n')
local label = hover:string():gsub('\r\n', '\n'):match('```lua[\r\n]*(.-)[\r\n]*```')
assert(expect == label)
- files.remove('')
+ files.remove(TESTURI)
end
end
diff --git a/test/references/init.lua b/test/references/init.lua
index 1b1cc73b..eee0ac61 100644
--- a/test/references/init.lua
+++ b/test/references/init.lua
@@ -21,11 +21,11 @@ end
function TEST(script)
local newScript, catched = catch(script, '!?~')
- files.setText('', newScript)
+ files.setText(TESTURI, newScript)
local input = catched['?'] + catched['~']
local expect = catched['!'] + catched['~']
- local results = core('', input[1][1])
+ local results = core(TESTURI, input[1][1])
if results then
local positions = {}
for i, result in ipairs(results) do
@@ -35,7 +35,7 @@ function TEST(script)
else
assert(#expect == 0)
end
- files.remove('')
+ files.remove(TESTURI)
end
require 'references.common'
diff --git a/test/rename/init.lua b/test/rename/init.lua
index 64e3916a..d4252d1e 100644
--- a/test/rename/init.lua
+++ b/test/rename/init.lua
@@ -6,7 +6,7 @@ local guide = require 'parser.guide'
local config = require 'config'
local function replace(text, positions)
- local state = files.getState('')
+ local state = files.getState(TESTURI)
local buf = {}
table.sort(positions, function (a, b)
return a.start < b.start
@@ -26,19 +26,19 @@ end
function TEST(oldName, newName)
return function (oldScript)
return function (expectScript)
- files.setText('', oldScript)
- local state = files.getState('')
+ files.setText(TESTURI, oldScript)
+ local state = files.getState(TESTURI)
local offset = oldScript:find('[^%w_]'..oldName..'[^%w_]')
assert(offset)
local position = guide.offsetToPosition(state, offset)
- local positions = core.rename('', position, newName)
+ local positions = core.rename(TESTURI, position, newName)
local script = oldScript
if positions then
script = replace(script, positions)
end
assert(script == expectScript)
- files.remove('')
+ files.remove(TESTURI)
end
end
end
diff --git a/test/signature/init.lua b/test/signature/init.lua
index 18a0fc30..b78fdaa5 100644
--- a/test/signature/init.lua
+++ b/test/signature/init.lua
@@ -8,8 +8,8 @@ rawset(_G, 'TEST', true)
function TEST(script)
return function (expect)
local newScript, catched1 = catch(script, '?')
- files.setText('', newScript)
- local hovers = core('', catched1['?'][1][1])
+ files.setText(TESTURI, newScript)
+ local hovers = core(TESTURI, catched1['?'][1][1])
if hovers then
assert(#hovers == #expect)
for i, hover in ipairs(hovers) do
@@ -28,7 +28,7 @@ function TEST(script)
else
assert(expect == nil)
end
- files.remove('')
+ files.remove(TESTURI)
end
end
diff --git a/test/type_formatting/init.lua b/test/type_formatting/init.lua
index 08c978b7..4e9ce556 100644
--- a/test/type_formatting/init.lua
+++ b/test/type_formatting/init.lua
@@ -8,15 +8,15 @@ rawset(_G, 'TEST', true)
function TEST(script)
return function(expect)
local newScript, catched = catch(script, '?')
- files.setText('', newScript)
- local edits = core('', catched['?'][1][1], expect.ch)
+ files.setText(TESTURI, newScript)
+ local edits = core(TESTURI, catched['?'][1][1], expect.ch)
if edits then
assert(expect.edits)
assert(util.equal(edits, expect.edits))
else
assert(expect.edits == nil)
end
- files.remove('')
+ files.remove(TESTURI)
end
end
diff --git a/test/type_inference/init.lua b/test/type_inference/init.lua
index f0948b49..43177dc7 100644
--- a/test/type_inference/init.lua
+++ b/test/type_inference/init.lua
@@ -7,7 +7,7 @@ local vm = require 'vm'
rawset(_G, 'TEST', true)
local function getSource(pos)
- local state = files.getState('')
+ local state = files.getState(TESTURI)
if not state then
return
end
@@ -31,15 +31,15 @@ end
function TEST(wanted)
return function (script)
local newScript, catched = catch(script, '?')
- files.setText('', newScript)
+ files.setText(TESTURI, newScript)
local source = getSource(catched['?'][1][1])
assert(source)
- local result = vm.getInfer(source):view('')
+ local result = vm.getInfer(source):view(TESTURI)
if wanted ~= result then
- vm.getInfer(source):view('')
+ vm.getInfer(source):view(TESTURI)
end
assert(wanted == result)
- files.remove('')
+ files.remove(TESTURI)
end
end