summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.github/workflows/checkPR.yml16
-rw-r--r--changelog.md5
-rw-r--r--locale/en-us/script.lua1
-rw-r--r--locale/zh-cn/script.lua1
-rw-r--r--script/config/config.lua1
-rw-r--r--script/core/command/autoRequire.lua2
-rw-r--r--script/core/completion.lua2
-rw-r--r--script/files.lua7
-rw-r--r--script/plugin.lua2
-rw-r--r--script/workspace/require-path.lua8
-rw-r--r--script/workspace/workspace.lua9
-rw-r--r--test/crossfile/completion.lua108
-rw-r--r--test/crossfile/definition.lua25
13 files changed, 178 insertions, 9 deletions
diff --git a/.github/workflows/checkPR.yml b/.github/workflows/checkPR.yml
new file mode 100644
index 00000000..c83bf3ab
--- /dev/null
+++ b/.github/workflows/checkPR.yml
@@ -0,0 +1,16 @@
+name: checkPR
+on: pull_request
+jobs:
+ compile:
+ runs-on: ${{ matrix.os }}
+ strategy:
+ fail-fast: false
+ matrix:
+ os: [windows-latest, ubuntu-18.04, macos-latest]
+ steps:
+ - uses: actions/checkout@v1
+ with:
+ ref: ${{ github.event.pull_request.head.sha }}
+ submodules : recursive
+ - uses: actboy168/setup-luamake@master
+ - run: luamake
diff --git a/changelog.md b/changelog.md
index 19520163..6ee49a79 100644
--- a/changelog.md
+++ b/changelog.md
@@ -1,5 +1,10 @@
# changelog
+## 2.5.0
+* `NEW` setting `Lua.runtime.pathStrict`
+* `NEW` skip huge files (>= 100 MB)
+* `CHG` no longer asks to trust plugin in VSCode, because VSCode already provides the workspace trust feature
+
## 2.4.7
`2021-10-27`
* `FIX` [#762](https://github.com/sumneko/lua-language-server/issues/762)
diff --git a/locale/en-us/script.lua b/locale/en-us/script.lua
index c5e683b0..fde50ae9 100644
--- a/locale/en-us/script.lua
+++ b/locale/en-us/script.lua
@@ -66,6 +66,7 @@ MWS_WCONFIG_UPDATED = 'Workspace setting updated.'
WORKSPACE_SKIP_LARGE_FILE = 'Too large file: {} skipped. The currently set size limit is: {} KB, and the file size is: {} KB.'
WORKSPACE_LOADING = 'Loading workspace'
WORKSPACE_DIAGNOSTIC = 'Diagnosing workspace'
+WORKSPACE_SKIP_HUGE_FILE = 'For performance reasons, the parsing of this file has been stopped: {}'
PARSER_CRASH = 'Parser crashed! Last words:{}'
PARSER_UNKNOWN = 'Unknown syntax error...'
diff --git a/locale/zh-cn/script.lua b/locale/zh-cn/script.lua
index de204e63..120ce765 100644
--- a/locale/zh-cn/script.lua
+++ b/locale/zh-cn/script.lua
@@ -66,6 +66,7 @@ MWS_WCONFIG_UPDATED = '工作区配置已更新。'
WORKSPACE_SKIP_LARGE_FILE = '已跳过过大的文件:{}。当前设置的大小限制为:{} KB,该文件大小为:{} KB'
WORKSPACE_LOADING = '正在加载工作目录'
WORKSPACE_DIAGNOSTIC = '正在对工作目录进行诊断'
+WORKSPACE_SKIP_HUGE_FILE = '出于性能考虑,已停止对此文件解析:{}'
PARSER_CRASH = '语法解析崩溃了!遗言:{}'
PARSER_UNKNOWN = '未知语法错误...'
diff --git a/script/config/config.lua b/script/config/config.lua
index 461ec260..8661e0d0 100644
--- a/script/config/config.lua
+++ b/script/config/config.lua
@@ -151,6 +151,7 @@ local Template = {
"?.lua",
"?/init.lua",
},
+ ['Lua.runtime.pathStrict'] = Type.Boolean >> false,
['Lua.runtime.special'] = Type.Hash(Type.String, Type.String),
['Lua.runtime.meta'] = Type.String >> '${version} ${language} ${encoding}',
['Lua.runtime.unicodeName'] = Type.Boolean,
diff --git a/script/core/command/autoRequire.lua b/script/core/command/autoRequire.lua
index aa641967..ca8826d7 100644
--- a/script/core/command/autoRequire.lua
+++ b/script/core/command/autoRequire.lua
@@ -135,7 +135,7 @@ return function (data)
end
local path = furi.decode(target)
- local visiblePaths = rpath.getVisiblePath(path, config.get 'Lua.runtime.path')
+ local visiblePaths = rpath.getVisiblePath(path)
if not visiblePaths or #visiblePaths == 0 then
return
end
diff --git a/script/core/completion.lua b/script/core/completion.lua
index 74017ec6..8b31614d 100644
--- a/script/core/completion.lua
+++ b/script/core/completion.lua
@@ -885,7 +885,7 @@ local function collectRequireNames(mode, myUri, literal, source, smark, position
goto CONTINUE
end
local path = workspace.getRelativePath(uri)
- local infos = rpath.getVisiblePath(path, config.get 'Lua.runtime.path')
+ local infos = rpath.getVisiblePath(path)
for _, info in ipairs(infos) do
if matchKey(literal, info.expect) then
if not collect[info.expect] then
diff --git a/script/files.lua b/script/files.lua
index 4d649b29..29a66d48 100644
--- a/script/files.lua
+++ b/script/files.lua
@@ -120,10 +120,15 @@ end
--- 设置文件文本
---@param uri uri
---@param text string
-function m.setText(uri, text, isTrust, instance)
+function m.setText(uri, text, isTrust)
if not text then
return
end
+ if #text > 1024 * 1024 * 100 then
+ local client = require 'client'
+ client.showMessage('Warning', lang.script('WORKSPACE_SKIP_HUGE_FILE', uri))
+ return
+ end
--log.debug('setText', uri)
local create
if not m.fileMap[uri] then
diff --git a/script/plugin.lua b/script/plugin.lua
index 26f39226..26e99d53 100644
--- a/script/plugin.lua
+++ b/script/plugin.lua
@@ -100,7 +100,7 @@ function m.init()
m.showError(err)
return
end
- if not checkTrustLoad() then
+ if not client.isVSCode() and not checkTrustLoad() then
return
end
local suc, err = xpcall(f, log.error, f)
diff --git a/script/workspace/require-path.lua b/script/workspace/require-path.lua
index 2ec2918c..e2149bac 100644
--- a/script/workspace/require-path.lua
+++ b/script/workspace/require-path.lua
@@ -27,7 +27,9 @@ local function getOnePath(path, searcher)
return nil
end
-function m.getVisiblePath(path, searchers, strict)
+function m.getVisiblePath(path)
+ local searchers = config.get 'Lua.runtime.path'
+ local strict = config.get 'Lua.runtime.pathStrict'
path = path:gsub('^[/\\]+', '')
local uri = furi.encode(path)
local libraryPath = files.getLibraryPath(uri)
@@ -91,7 +93,9 @@ files.watch(function (ev)
end)
config.watch(function (key, value, oldValue)
- if key == 'Lua.completion.requireSeparator' then
+ if key == 'Lua.completion.requireSeparator'
+ or key == 'Lua.runtime.path'
+ or key == 'Lua.runtime.pathStrict' then
m.flush()
end
end)
diff --git a/script/workspace/workspace.lua b/script/workspace/workspace.lua
index 5b87b2bb..726bec09 100644
--- a/script/workspace/workspace.lua
+++ b/script/workspace/workspace.lua
@@ -246,7 +246,7 @@ local function loadFileFactory(root, progressData, isLibrary)
log.info('++++As library of:', root)
files.setLibraryPath(uri, root)
end
- files.setText(uri, text, false, true)
+ files.setText(uri, text, false)
else
files.remove(uri)
end
@@ -391,17 +391,22 @@ function m.findUrisByFilePath(path)
return resultCache[path].results, resultCache[path].posts
end
tracy.ZoneBeginN('findUrisByFilePath #1')
+ local strict = config.get 'Lua.runtime.pathStrict'
local results = {}
local posts = {}
for uri in files.eachFile() do
if not uri:find(lpath, 1, true) then
goto CONTINUE
end
+ local relat = m.getRelativePath(uri)
local pathLen = #path
- local curPath = furi.decode(uri)
+ local curPath = relat
local curLen = #curPath
local seg = curPath:sub(curLen - pathLen, curLen - pathLen)
if seg == '/' or seg == '\\' or seg == '' then
+ if strict and seg ~= '' then
+ goto CONTINUE
+ end
local see = curPath:sub(curLen - pathLen + 1, curLen)
if see == path then
results[#results+1] = uri
diff --git a/test/crossfile/completion.lua b/test/crossfile/completion.lua
index 172f9d6f..27acb15d 100644
--- a/test/crossfile/completion.lua
+++ b/test/crossfile/completion.lua
@@ -87,7 +87,7 @@ function TEST(data)
local pos
for _, info in ipairs(data) do
local uri = furi.encode(info.path)
- local script = info.content
+ local script = info.content or ''
if info.main then
local newScript, catched = catch(script, '?')
pos = catched['?'][1][1]
@@ -565,9 +565,115 @@ TEST {
]],
main = true,
},
+ completion = nil,
}
TEST {
+ { path = 'f/a.lua' },
+ { path = 'f/b.lua' },
+ {
+ path = 'c.lua',
+ content = [[
+ require '<??>'
+ ]],
+ main = true,
+ },
+ completion = {
+ {
+ label = 'a',
+ kind = CompletionItemKind.Reference,
+ textEdit = EXISTS,
+ },
+ {
+ label = 'b',
+ kind = CompletionItemKind.Reference,
+ textEdit = EXISTS,
+ },
+ {
+ label = 'f.a',
+ kind = CompletionItemKind.Reference,
+ textEdit = EXISTS,
+ },
+ {
+ label = 'f.b',
+ kind = CompletionItemKind.Reference,
+ textEdit = EXISTS,
+ },
+ }
+}
+
+TEST {
+ { path = 'f/a.lua' },
+ { path = 'f/b.lua' },
+ {
+ path = 'c.lua',
+ content = [[
+ require 'a<??>'
+ ]],
+ main = true,
+ },
+ completion = {
+ {
+ label = 'a',
+ kind = CompletionItemKind.Reference,
+ textEdit = EXISTS,
+ },
+ {
+ label = 'f.a',
+ kind = CompletionItemKind.Reference,
+ textEdit = EXISTS,
+ },
+ }
+}
+
+config.set('Lua.runtime.pathStrict', true)
+
+TEST {
+ { path = 'f/a.lua' },
+ { path = 'f/b.lua' },
+ {
+ path = 'c.lua',
+ content = [[
+ require '<??>'
+ ]],
+ main = true,
+ },
+ completion = {
+ {
+ label = 'f.a',
+ kind = CompletionItemKind.Reference,
+ textEdit = EXISTS,
+ },
+ {
+ label = 'f.b',
+ kind = CompletionItemKind.Reference,
+ textEdit = EXISTS,
+ },
+ }
+}
+
+TEST {
+ { path = 'f/a.lua' },
+ { path = 'f/b.lua' },
+ {
+ path = 'c.lua',
+ content = [[
+ require 'a<??>'
+ ]],
+ main = true,
+ },
+ completion = {
+ {
+ label = 'f.a',
+ kind = CompletionItemKind.Reference,
+ textEdit = EXISTS,
+ },
+ }
+}
+
+config.set('Lua.runtime.pathStrict', false)
+
+TEST {
{
path = 'xxx.lua',
content = ''
diff --git a/test/crossfile/definition.lua b/test/crossfile/definition.lua
index 37c10db6..862d95e8 100644
--- a/test/crossfile/definition.lua
+++ b/test/crossfile/definition.lua
@@ -117,6 +117,31 @@ TEST {
},
}
+config.set('Lua.runtime.pathStrict', true)
+TEST {
+ {
+ path = 'aaa/bbb.lua',
+ content = '',
+ },
+ {
+ path = 'b.lua',
+ content = 'require "<?bbb?>"',
+ },
+}
+
+TEST {
+ {
+ path = 'aaa/bbb.lua',
+ content = '<!!>',
+ },
+ {
+ path = 'b.lua',
+ content = 'require "<?aaa.bbb?>"',
+ },
+}
+
+config.set('Lua.runtime.pathStrict', false)
+
TEST {
{
path = 'a.lua',