summaryrefslogtreecommitdiff
path: root/script
diff options
context:
space:
mode:
authorjefersonf <jeferson.silva>2021-10-30 13:19:12 -0300
committerjefersonf <jeferson.silva>2021-10-30 13:19:12 -0300
commitf0c5bbeb62794116b6517be51efa6054254076eb (patch)
treefee585182a7ec10e987e758a53edcbd7db9dca9b /script
parentf41a33de696dc5ff802d2f5e540da1c87861dac9 (diff)
parent107b57cc7728824a0e9515727f9a6123c5f7c902 (diff)
downloadlua-language-server-f0c5bbeb62794116b6517be51efa6054254076eb.zip
Merge branch 'master' of https://github.com/sumneko/lua-language-server into pt-br-locale-support
Diffstat (limited to 'script')
-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/core/diagnostics/redundant-return.lua27
-rw-r--r--script/core/hover/return.lua7
-rw-r--r--script/core/infer.lua1
-rw-r--r--script/core/searcher.lua1
-rw-r--r--script/encoder/utf16be.lua10
-rw-r--r--script/encoder/utf16le.lua10
-rw-r--r--script/files.lua7
-rw-r--r--script/parser/newparser.lua48
-rw-r--r--script/plugin.lua2
-rw-r--r--script/proto/define.lua2
-rw-r--r--script/workspace/require-path.lua8
-rw-r--r--script/workspace/workspace.lua9
15 files changed, 98 insertions, 39 deletions
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/core/diagnostics/redundant-return.lua b/script/core/diagnostics/redundant-return.lua
new file mode 100644
index 00000000..486db6cd
--- /dev/null
+++ b/script/core/diagnostics/redundant-return.lua
@@ -0,0 +1,27 @@
+local files = require 'files'
+local guide = require 'parser.guide'
+local lang = require 'language'
+local define = require 'proto.define'
+
+-- reports 'return' without any return values at the end of functions
+return function (uri, callback)
+ local ast = files.getState(uri)
+ if not ast then
+ return
+ end
+
+ guide.eachSourceType(ast.ast, 'return', function (source)
+ if not source.parent or source.parent.type ~= "function" then
+ return
+ end
+ if #source > 0 then
+ return
+ end
+ callback {
+ start = source.start,
+ finish = source.finish,
+ tags = { define.DiagnosticTag.Unnecessary },
+ message = lang.script.DIAG_REDUNDANT_RETURN,
+ }
+ end)
+end
diff --git a/script/core/hover/return.lua b/script/core/hover/return.lua
index 0f0d85e0..49f9536a 100644
--- a/script/core/hover/return.lua
+++ b/script/core/hover/return.lua
@@ -54,6 +54,13 @@ local function asFunction(source)
line[#line+1] = ('% 3d. '):format(i)
end
for n = 1, #rtn do
+ if rtn[n].type == 'doc.type' then
+ for _, typeUnit in ipairs(rtn[n].types) do
+ if typeUnit[1] == 'nil' then
+ infers['nil'] = true
+ end
+ end
+ end
local values = infer.searchInfers(rtn[n])
for tp in pairs(values) do
infers[tp] = true
diff --git a/script/core/infer.lua b/script/core/infer.lua
index ab297209..6e667e65 100644
--- a/script/core/infer.lua
+++ b/script/core/infer.lua
@@ -216,7 +216,6 @@ local function searchLiteralOfValue(value, literals, mark)
end
end
end
- return
end
local function bindClassOrType(source)
diff --git a/script/core/searcher.lua b/script/core/searcher.lua
index 4d72b038..c5180a54 100644
--- a/script/core/searcher.lua
+++ b/script/core/searcher.lua
@@ -960,6 +960,7 @@ function m.searchRefsByID(status, suri, expect, mode)
end
search(suri, expect, nil)
+ flushGeneric()
end
local function prepareSearch(source)
diff --git a/script/encoder/utf16be.lua b/script/encoder/utf16be.lua
index 179a676d..5fc19b2c 100644
--- a/script/encoder/utf16be.lua
+++ b/script/encoder/utf16be.lua
@@ -8,7 +8,7 @@ local function tobyte(s, i)
end
local function char(code)
- if code <= 0xffff then
+ if code <= 0xFFFF then
return tochar(code)
end
code = code - 0x10000
@@ -19,7 +19,7 @@ local m = {}
function m.encode(s)
local r = {}
- for _, c in utf8.codes(s) do
+ for _, c in utf8.codes(s, true) do
r[#r+1] = char(c)
end
return table.concat(r)
@@ -30,13 +30,13 @@ function m.decode(s)
local i = 1
while i < #s do
local code1 = tobyte(s, i)
- if code1 < 0xD800 then
- r[#r+1] = utf8.char(code1)
- else
+ if code1 >= 0xD800 and code1 < 0xE000 then
i = i + 2
local code2 = tobyte(s, i)
local code = 0x10000 + ((code1 - 0xD800) << 10) + ((code2 - 0xDC00) & 0x3FF)
r[#r+1] = utf8.char(code)
+ else
+ r[#r+1] = utf8.char(code1)
end
i = i + 2
end
diff --git a/script/encoder/utf16le.lua b/script/encoder/utf16le.lua
index cfbc33c2..d51b4cfb 100644
--- a/script/encoder/utf16le.lua
+++ b/script/encoder/utf16le.lua
@@ -8,7 +8,7 @@ local function tobyte(s, i)
end
local function char(code)
- if code <= 0xffff then
+ if code <= 0xFFFF then
return tochar(code)
end
code = code - 0x10000
@@ -19,7 +19,7 @@ local m = {}
function m.encode(s)
local r = {}
- for _, c in utf8.codes(s) do
+ for _, c in utf8.codes(s, true) do
r[#r+1] = char(c)
end
return table.concat(r)
@@ -30,13 +30,13 @@ function m.decode(s)
local i = 1
while i < #s do
local code1 = tobyte(s, i)
- if code1 < 0xD800 then
- r[#r+1] = utf8.char(code1)
- else
+ if code1 >= 0xD800 and code1 < 0xE000 then
i = i + 2
local code2 = tobyte(s, i)
local code = 0x10000 + ((code1 - 0xD800) << 10) + ((code2 - 0xDC00) & 0x3FF)
r[#r+1] = utf8.char(code)
+ else
+ r[#r+1] = utf8.char(code1)
end
i = i + 2
end
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/parser/newparser.lua b/script/parser/newparser.lua
index ca0bc66a..0b721a7a 100644
--- a/script/parser/newparser.lua
+++ b/script/parser/newparser.lua
@@ -1639,6 +1639,30 @@ local function parseTable()
return tbl
end
+local function addDummySelf(node, call)
+ if node.type ~= 'getmethod' then
+ return
+ end
+ -- dummy param `self`
+ if not call.args then
+ call.args = {
+ type = 'callargs',
+ start = call.start,
+ finish = call.finish,
+ parent = call,
+ }
+ end
+ local newNode = {}
+ for k, v in next, call.node.node do
+ newNode[k] = v
+ end
+ newNode.mirror = call.node.node
+ newNode.dummy = true
+ newNode.parent = call.args
+ call.node.node.mirror = newNode
+ tinsert(call.args, 1, newNode)
+end
+
local function parseSimple(node, funcName)
local lastMethod
while true do
@@ -1740,26 +1764,7 @@ local function parseSimple(node, funcName)
args.parent = call
call.args = args
end
- if node.type == 'getmethod' then
- -- dummy param `self`
- if not call.args then
- call.args = {
- type = 'callargs',
- start = call.start,
- finish = call.finish,
- parent = call,
- }
- end
- local newNode = {}
- for k, v in next, call.node.node do
- newNode[k] = v
- end
- newNode.mirror = call.node.node
- newNode.dummy = true
- newNode.parent = call.args
- call.node.node.mirror = newNode
- tinsert(call.args, 1, newNode)
- end
+ addDummySelf(node, call)
node.parent = call
node = call
elseif token == '{' then
@@ -1781,6 +1786,7 @@ local function parseSimple(node, funcName)
[1] = tbl,
}
call.args = args
+ addDummySelf(node, call)
tbl.parent = args
node.parent = call
node = call
@@ -1803,6 +1809,7 @@ local function parseSimple(node, funcName)
[1] = str,
}
call.args = args
+ addDummySelf(node, call)
str.parent = args
node.parent = call
node = call
@@ -1826,6 +1833,7 @@ local function parseSimple(node, funcName)
[1] = str,
}
call.args = args
+ addDummySelf(node, call)
str.parent = args
node.parent = call
node = call
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/proto/define.lua b/script/proto/define.lua
index 63153423..713857af 100644
--- a/script/proto/define.lua
+++ b/script/proto/define.lua
@@ -29,6 +29,7 @@ m.DiagnosticDefaultSeverity = {
['newline-call'] = 'Information',
['newfield-call'] = 'Warning',
['redundant-parameter'] = 'Warning',
+ ['redundant-return'] = 'Warning',
['ambiguity-1'] = 'Warning',
['lowercase-global'] = 'Information',
['undefined-env-child'] = 'Information',
@@ -82,6 +83,7 @@ m.DiagnosticDefaultNeededFileStatus = {
['newline-call'] = 'Any',
['newfield-call'] = 'Any',
['redundant-parameter'] = 'Opened',
+ ['redundant-return'] = 'Opened',
['ambiguity-1'] = 'Any',
['lowercase-global'] = 'Any',
['undefined-env-child'] = 'Any',
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