summaryrefslogtreecommitdiff
path: root/script
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2022-02-15 20:10:00 +0800
committer最萌小汐 <sumneko@hotmail.com>2022-02-15 20:10:00 +0800
commit12d6a9eb75f31b64cbc89eb3265805bc8dad01f0 (patch)
tree031a449c1222ef1705d34fbb22c11ef1ea388ee5 /script
parentbf8b18fe8d2f3cc470021e32b9d5f11ec765a643 (diff)
downloadlua-language-server-12d6a9eb75f31b64cbc89eb3265805bc8dad01f0.zip
cleanup
Diffstat (limited to 'script')
-rw-r--r--script/client.lua2
-rw-r--r--script/config/config.lua8
-rw-r--r--script/config/loader.lua2
-rw-r--r--script/core/code-action.lua55
-rw-r--r--script/core/completion/completion.lua111
-rw-r--r--script/core/completion/postfix.lua17
-rw-r--r--script/core/definition.lua14
-rw-r--r--script/core/diagnostics/count-down-loop.lua14
-rw-r--r--script/core/diagnostics/deprecated.lua6
-rw-r--r--script/core/diagnostics/duplicate-doc-field.lua6
-rw-r--r--script/core/diagnostics/init.lua1
-rw-r--r--script/core/diagnostics/newline-call.lua5
-rw-r--r--script/core/diagnostics/type-check.lua56
-rw-r--r--script/core/diagnostics/undefined-doc-class.lua2
-rw-r--r--script/core/diagnostics/undefined-doc-param.lua3
-rw-r--r--script/core/diagnostics/undefined-env-child.lua9
-rw-r--r--script/core/diagnostics/undefined-field.lua6
-rw-r--r--script/core/document-symbol.lua12
-rw-r--r--script/core/folding.lua14
-rw-r--r--script/core/generic.lua7
-rw-r--r--script/core/highlight.lua42
-rw-r--r--script/core/hover/description.lua4
-rw-r--r--script/core/hover/label.lua14
-rw-r--r--script/core/hover/table.lua7
-rw-r--r--script/core/infer.lua18
-rw-r--r--script/core/keyword.lua224
-rw-r--r--script/core/look-backward.lua2
-rw-r--r--script/library.lua2
-rw-r--r--script/parser/compile.lua24
-rw-r--r--script/parser/grammar.lua23
30 files changed, 364 insertions, 346 deletions
diff --git a/script/client.lua b/script/client.lua
index ef390b9e..0388ff39 100644
--- a/script/client.lua
+++ b/script/client.lua
@@ -315,7 +315,7 @@ end
function m.setConfig(changes, onlyMemory)
local finalChanges = {}
for _, change in ipairs(changes) do
- if change.action == 'add' then
+ if change.action == 'add' then
local suc = config.add(change.uri, change.key, change.value)
if suc then
finalChanges[#finalChanges+1] = change
diff --git a/script/config/config.lua b/script/config/config.lua
index 06309d72..a53b77b5 100644
--- a/script/config/config.lua
+++ b/script/config/config.lua
@@ -47,7 +47,7 @@ end)
register('Integer', 0, function (self, v)
return type(v) == 'number'
-end,function (self, v)
+end, function (self, v)
return math.floor(v)
end)
@@ -118,7 +118,7 @@ end, function (self, value)
end
if type(value) == 'string' then
local t = {}
- for s in value:gmatch('[^'..self.sep..']+') do
+ for s in value:gmatch('[^' .. self.sep .. ']+') do
t[s] = true
end
return t
@@ -143,7 +143,7 @@ end, function (self, value)
end
end
end, function (self, ...)
- self.subs = {...}
+ self.subs = { ... }
end)
local Template = {
@@ -412,7 +412,7 @@ function m.update(scp, ...)
if m.nullSymbols[value] then
value = m.NULL
end
- if Template[fullKey] then
+ if Template[fullKey] then
m.setByScope(scp, fullKey, value)
elseif Template['Lua.' .. fullKey] then
m.setByScope(scp, 'Lua.' .. fullKey, value)
diff --git a/script/config/loader.lua b/script/config/loader.lua
index 1b520c15..c0bd66d7 100644
--- a/script/config/loader.lua
+++ b/script/config/loader.lua
@@ -45,7 +45,7 @@ function m.loadLocalConfig(uri, filename)
scp:set('lastLocalType', nil)
return nil
end
- local buf = util.loadFile(path)
+ local buf = util.loadFile(path)
if not buf then
errorMessage(lang.script('CONFIG_LOAD_FAILED', path))
scp:set('lastLocalConfig', nil)
diff --git a/script/core/code-action.lua b/script/core/code-action.lua
index f96e341a..4b1ebd57 100644
--- a/script/core/code-action.lua
+++ b/script/core/code-action.lua
@@ -12,24 +12,29 @@ local function checkDisableByLuaDocExits(uri, row, mode, code)
local state = files.getState(uri)
local lines = state.lines
if state.ast.docs and lines then
- return guide.eachSourceBetween(state.ast.docs, guide.positionOf(row, 0), guide.positionOf(row + 1, 0), function (doc)
- if doc.type == 'doc.diagnostic'
- and doc.mode == mode then
- if doc.names then
- return {
- start = doc.finish,
- finish = doc.finish,
- newText = ', ' .. code,
- }
- else
- return {
- start = doc.finish,
- finish = doc.finish,
- newText = ': ' .. code,
- }
+ return guide.eachSourceBetween(
+ state.ast.docs,
+ guide.positionOf(row, 0),
+ guide.positionOf(row + 1, 0),
+ function (doc)
+ if doc.type == 'doc.diagnostic'
+ and doc.mode == mode then
+ if doc.names then
+ return {
+ start = doc.finish,
+ finish = doc.finish,
+ newText = ', ' .. code,
+ }
+ else
+ return {
+ start = doc.finish,
+ finish = doc.finish,
+ newText = ': ' .. code,
+ }
+ end
end
end
- end)
+ )
end
return nil
end
@@ -86,7 +91,7 @@ local function markGlobal(uri, name, results)
kind = 'quickfix',
command = {
title = lang.script.COMMAND_MARK_GLOBAL,
- command = 'lua.setConfig',
+ command = 'lua.setConfig',
arguments = {
{
key = 'Lua.diagnostics.globals',
@@ -208,7 +213,7 @@ local function solveSyntaxByFix(uri, err, results)
results[#results+1] = {
title = lang.script('ACTION_' .. err.fix.title, err.fix),
kind = 'quickfix',
- edit = {
+ edit = {
changes = {
[uri] = changes,
}
@@ -263,8 +268,8 @@ local function solveNewlineCall(uri, diag, results)
changes = {
[uri] = {
{
- start = start,
- finish = start,
+ start = start,
+ finish = start,
newText = ';',
}
}
@@ -335,8 +340,8 @@ local function solveAwaitInSync(uri, diag, results)
changes = {
[uri] = {
{
- start = pos,
- finish = pos,
+ start = pos,
+ finish = pos,
newText = '---@async\n',
}
}
@@ -541,11 +546,11 @@ end
--end
local function checkJsonToLua(results, uri, start, finish)
- local text = files.getText(uri)
- local state = files.getState(uri)
+ local text = files.getText(uri)
+ local state = files.getState(uri)
local startOffset = guide.positionToOffset(state, start)
local finishOffset = guide.positionToOffset(state, finish)
- local jsonStart = text:match ('()[%{%[]', startOffset + 1)
+ local jsonStart = text:match('()[%{%[]', startOffset + 1)
if not jsonStart then
return
end
diff --git a/script/core/completion/completion.lua b/script/core/completion/completion.lua
index a8000c91..2c3a354d 100644
--- a/script/core/completion/completion.lua
+++ b/script/core/completion/completion.lua
@@ -23,7 +23,7 @@ local noder = require 'core.noder'
local await = require 'await'
local postfix = require 'core.completion.postfix'
-local DiagnosticModes = {
+local diagnosticModes = {
'disable-next-line',
'disable-line',
'disable',
@@ -101,9 +101,9 @@ local function findParent(state, position)
goto CONTINUE
end
local oop
- if char == '.' then
+ if char == '.' then
-- `..` 的情况
- if text:sub(i-1, i-1) == '.' then
+ if text:sub(i - 1, i - 1) == '.' then
return nil, nil
end
oop = false
@@ -112,7 +112,7 @@ local function findParent(state, position)
else
return nil, nil
end
- local anyOffset = lookBackward.findAnyOffset(text, i-1)
+ local anyOffset = lookBackward.findAnyOffset(text, i - 1)
if not anyOffset then
return nil, nil
end
@@ -198,10 +198,10 @@ local function getSnip(source)
if vm.isMetaFile(uri) then
goto CONTINUE
end
- local firstRow = guide.rowColOf(def.start)
- local lastRow = firstRow + context
+ local firstRow = guide.rowColOf(def.start)
+ local lastRow = firstRow + context
local lastOffset = lines[lastRow] and (lines[lastRow] - 1) or #text
- local snip = text:sub(lines[firstRow], lastOffset)
+ local snip = text:sub(lines[firstRow], lastOffset)
return snip
end
::CONTINUE::
@@ -228,19 +228,21 @@ local function buildFunction(results, source, value, oop, data)
end
if snipType == 'Both' or snipType == 'Replace' then
local snipData = util.deepCopy(data)
- snipData.kind = define.CompletionItemKind.Snippet
- snipData.insertText = buildFunctionSnip(source, value, oop)
+
+ snipData.kind = define.CompletionItemKind.Snippet
+ snipData.insertText = buildFunctionSnip(source, value, oop)
snipData.insertTextFormat = 2
- snipData.command = {
+ snipData.command = {
title = 'trigger signature',
command = 'editor.action.triggerParameterHints',
}
- snipData.id = stack(function () ---@async
+ snipData.id = stack(function () ---@async
return {
detail = buildDetail(source),
description = buildDesc(source),
}
end)
+
results[#results+1] = snipData
end
end
@@ -262,7 +264,7 @@ local function getParams(func, oop)
end
local args = {}
for _, arg in ipairs(func.args) do
- if arg.type == '...' then
+ if arg.type == '...' then
args[#args+1] = '...'
elseif arg.type == 'doc.type.arg' then
args[#args+1] = arg.name[1]
@@ -294,11 +296,11 @@ local function checkLocal(state, word, position, results)
or def.type == 'doc.type.function' then
local funcLabel = name .. getParams(def, false)
buildFunction(results, source, def, false, {
- label = funcLabel,
- match = name,
+ label = funcLabel,
+ match = name,
insertText = name,
- kind = define.CompletionItemKind.Function,
- id = stack(function () ---@async
+ kind = define.CompletionItemKind.Function,
+ id = stack(function () ---@async
return {
detail = buildDetail(source),
description = buildDesc(source),
@@ -327,7 +329,7 @@ local function checkModule(state, word, position, results)
if not config.get(state.uri, 'Lua.completion.autoRequire') then
return
end
- local locals = guide.getVisibleLocals(state.ast, position)
+ local locals = guide.getVisibleLocals(state.ast, position)
for uri in files.eachFile(state.uri) do
if uri == guide.getUri(state.ast) then
goto CONTINUE
@@ -362,10 +364,10 @@ local function checkModule(state, word, position, results)
goto CONTINUE
end
results[#results+1] = {
- label = stemName,
- kind = define.CompletionItemKind.Variable,
- commitCharacters = {'.'},
- command = {
+ label = stemName,
+ kind = define.CompletionItemKind.Variable,
+ commitCharacters = { '.' },
+ command = {
title = 'autoRequire',
command = 'lua.autoRequire',
arguments = {
@@ -376,7 +378,7 @@ local function checkModule(state, word, position, results)
},
},
},
- id = stack(function () ---@async
+ id = stack(function () ---@async
local md = markdown()
md:add('md', lang.script('COMPLETION_IMPORT_FROM', ('[%s](%s)'):format(
workspace.getRelativePath(uri),
@@ -428,9 +430,9 @@ local function checkFieldFromFieldToIndex(state, name, src, parent, word, startP
local nxt = parent.next
if nxt then
local dotStart, dotFinish
- if nxt.type == 'setfield'
- or nxt.type == 'getfield'
- or nxt.type == 'tablefield' then
+ if nxt.type == 'setfield'
+ or nxt.type == 'getfield'
+ or nxt.type == 'tablefield' then
dotStart = nxt.dot.start
dotFinish = nxt.dot.finish
elseif nxt.type == 'setmethod'
@@ -506,13 +508,14 @@ local function checkFieldThen(state, name, src, word, startPos, position, parent
kind = kind,
deprecated = vm.isDeprecated(src) or nil,
textEdit = textEdit,
- additionalTextEdits = additionalTextEdits,
id = stack(function () ---@async
return {
detail = buildDetail(src),
description = buildDesc(src),
}
- end)
+ end),
+
+ additionalTextEdits = additionalTextEdits,
}
end
@@ -520,7 +523,7 @@ end
local function checkFieldOfRefs(refs, state, word, startPos, position, parent, oop, results, locals, isGlobal)
local fields = {}
local funcs = {}
- local count = 0
+ local count = 0
for _, src in ipairs(refs) do
local name = vm.getKeyName(src)
if not name then
@@ -727,7 +730,7 @@ local function checkKeyWord(state, start, position, word, hasSpace, afterLocal,
text = text,
start = start,
uri = guide.getUri(state.ast),
- position = position,
+ position = position,
state = state,
}
for _, data in ipairs(keyWordMap) do
@@ -870,7 +873,7 @@ local function checkFunctionArgByDocParam(state, word, startPos, results)
end
local function isAfterLocal(state, startPos)
- local text = state.lua
+ local text = state.lua
local offset = guide.positionToOffset(state, startPos)
local pos = lookBackward.skipSpace(text, offset)
local word = lookBackward.findWord(text, pos)
@@ -972,11 +975,11 @@ local function collectRequireNames(mode, myUri, literal, source, smark, position
end
end
results[#results+1] = {
- label = label,
- detail = infos.path,
- kind = define.CompletionItemKind.File,
+ label = label,
+ detail = infos.path,
+ kind = define.CompletionItemKind.File,
description = table.concat(des, '\n'),
- textEdit = infos.textEdit,
+ textEdit = infos.textEdit,
}
end
end
@@ -1138,8 +1141,8 @@ local function checkEqualEnumLeft(state, position, source, results)
end
local function checkEqualEnum(state, position, results)
- local text = state.lua
- local start = lookBackward.findTargetSymbol(text, guide.positionToOffset(state, position), '=')
+ local text = state.lua
+ local start = lookBackward.findTargetSymbol(text, guide.positionToOffset(state, position), '=')
if not start then
return
end
@@ -1247,7 +1250,7 @@ local function tryWord(state, position, triggerCharacter, results)
end
else
local parent, oop = findParent(state, startPos)
- if parent then
+ if parent then
checkField(state, word, startPos, position, parent, oop, results)
elseif isFuncArg(state, position) then
checkProvideLocal(state, word, startPos, results)
@@ -1352,8 +1355,8 @@ local function getCallEnumsAndFuncs(source, index, oop, call)
end
end
for _, doc in ipairs(source.bindDocs) do
- if doc.type == 'doc.param'
- and doc.param[1] == arg[1] then
+ if doc.type == 'doc.param'
+ and doc.param[1] == arg[1] then
return pushCallEnumsAndFuncs(vm.getDefs(doc.extends))
elseif doc.type == 'doc.vararg'
and arg.type == '...' then
@@ -1377,7 +1380,7 @@ local function getCallEnumsAndFuncs(source, index, oop, call)
return
end
local results = {}
- if currentIndex == 1 then
+ if currentIndex == 1 then
for _, doc in ipairs(class.fields) do
if doc.field ~= source
and doc.field[1] == source[1] then
@@ -1468,10 +1471,10 @@ local function checkTableLiteralField(state, position, tbl, fields, results)
local name = guide.getKeyName(field)
if not mark[name] and matchKey(left, guide.getKeyName(field)) then
results[#results+1] = {
- label = guide.getKeyName(field),
- kind = define.CompletionItemKind.Property,
+ label = guide.getKeyName(field),
+ kind = define.CompletionItemKind.Property,
insertText = ('%s = $0'):format(guide.getKeyName(field)),
- id = stack(function () ---@async
+ id = stack(function () ---@async
return {
detail = buildDetail(field),
description = buildDesc(field),
@@ -1598,7 +1601,7 @@ local function getluaDocByContain(state, position)
if not src.start then
return
end
- if range >= position - src.start
+ if range >= position - src.start
and position <= src.finish then
range = position - src.start
result = src
@@ -1633,7 +1636,7 @@ local function getluaDocByErr(state, start, position)
end
local function tryluaDocBySource(state, position, source, results)
- if source.type == 'doc.extends.name' then
+ if source.type == 'doc.extends.name' then
if source.parent.type == 'doc.class' then
local used = {}
for _, doc in ipairs(vm.getDocDefines(state.uri, '*')) do
@@ -1699,7 +1702,7 @@ local function tryluaDocBySource(state, position, source, results)
end
return true
elseif source.type == 'doc.diagnostic' then
- for _, mode in ipairs(DiagnosticModes) do
+ for _, mode in ipairs(diagnosticModes) do
if matchKey(source.mode, mode) then
results[#results+1] = {
label = mode,
@@ -1717,8 +1720,8 @@ local function tryluaDocBySource(state, position, source, results)
for name in util.sortPairs(define.DiagnosticDefaultSeverity) do
if matchKey(source[1], name) then
results[#results+1] = {
- label = name,
- kind = define.CompletionItemKind.Value,
+ label = name,
+ kind = define.CompletionItemKind.Value,
textEdit = {
start = source.start,
finish = source.start + #source[1] - 1,
@@ -1734,7 +1737,7 @@ local function tryluaDocBySource(state, position, source, results)
end
local function tryluaDocByErr(state, position, err, docState, results)
- if err.type == 'LUADOC_MISS_CLASS_EXTENDS_NAME' then
+ if err.type == 'LUADOC_MISS_CLASS_EXTENDS_NAME' then
for _, doc in ipairs(vm.getDocDefines(state.uri, '*')) do
if doc.type == 'doc.class.name'
and doc.parent ~= docState then
@@ -1794,7 +1797,7 @@ local function tryluaDocByErr(state, position, err, docState, results)
end
end
elseif err.type == 'LUADOC_MISS_DIAG_MODE' then
- for _, mode in ipairs(DiagnosticModes) do
+ for _, mode in ipairs(diagnosticModes) do
results[#results+1] = {
label = mode,
kind = define.CompletionItemKind.Enum,
@@ -1876,11 +1879,11 @@ local function tryluaDocOfFunction(doc, results)
end
local insertText = buildluaDocOfFunction(func)
results[#results+1] = {
- label = '@param;@return',
- kind = define.CompletionItemKind.Snippet,
+ label = '@param;@return',
+ kind = define.CompletionItemKind.Snippet,
insertTextFormat = 2,
- filterText = '---',
- insertText = insertText
+ filterText = '---',
+ insertText = insertText
}
end
diff --git a/script/core/completion/postfix.lua b/script/core/completion/postfix.lua
index 3b58d0b2..98bd0639 100644
--- a/script/core/completion/postfix.lua
+++ b/script/core/completion/postfix.lua
@@ -50,17 +50,17 @@ register 'function' {
register 'method' {
function (state, source, callback)
- if source.type == 'getfield' then
+ if source.type == 'getfield' then
if hasNonFieldInNode(source) then
return
end
local subber = subString(state)
callback(string.format('function %s:%s($1)\n\t$0\nend'
, subber(source.start + 1, source.dot.start)
- , subber(source.dot .finish + 1, source.finish)
+ , subber(source.dot.finish + 1, source.finish)
))
end
- if source.type == 'getmethod' then
+ if source.type == 'getmethod' then
if hasNonFieldInNode(source.parent) then
return
end
@@ -298,16 +298,18 @@ local function checkPostFix(state, word, wordPosition, position, symbol, results
if matchKey(word, action.key) then
action.data[1](state, source, function (newText)
results[#results+1] = {
- label = action.key,
- kind = define.CompletionItemKind.Event,
- description= markdown()
+ label = action.key,
+ kind = define.CompletionItemKind.Event,
+ description = markdown()
: add('lua', newText)
: string(),
- textEdit = {
+ textEdit = {
start = wordPosition + #symbol,
finish = position,
newText = newText,
},
+ sortText = ('postfix-%04d'):format(i),
+
additionalTextEdits = {
{
start = source.start,
@@ -315,7 +317,6 @@ local function checkPostFix(state, word, wordPosition, position, symbol, results
newText = '',
},
},
- sortText = ('postfix-%04d'):format(i),
}
end)
end
diff --git a/script/core/definition.lua b/script/core/definition.lua
index 6c6b3df3..b08b7706 100644
--- a/script/core/definition.lua
+++ b/script/core/definition.lua
@@ -20,8 +20,8 @@ local function sortResults(results)
-- 如果2个结果处于嵌套状态,则取范围小的那个
local lf, lu
for i = #results, 1, -1 do
- local res = results[i].target
- local f = res.finish
+ local res = results[i].target
+ local f = res.finish
local uri = guide.getUri(res)
if lf and f > lf and uri == lu then
table.remove(results, i)
@@ -152,9 +152,9 @@ return function (uri, offset)
goto CONTINUE
end
src = src.field or src.method or src
- if src.type == 'getindex'
- or src.type == 'setindex'
- or src.type == 'tableindex' then
+ if src.type == 'getindex'
+ or src.type == 'setindex'
+ or src.type == 'tableindex' then
src = src.index
if not src then
goto CONTINUE
@@ -163,8 +163,8 @@ return function (uri, offset)
goto CONTINUE
end
end
- if src.type == 'doc.class.name'
- or src.type == 'doc.alias.name' then
+ if src.type == 'doc.class.name'
+ or src.type == 'doc.alias.name' then
if source.type ~= 'doc.type.name'
and source.type ~= 'doc.extends.name'
and source.type ~= 'doc.see.name' then
diff --git a/script/core/diagnostics/count-down-loop.lua b/script/core/diagnostics/count-down-loop.lua
index 49c48880..9bc4b273 100644
--- a/script/core/diagnostics/count-down-loop.lua
+++ b/script/core/diagnostics/count-down-loop.lua
@@ -20,28 +20,26 @@ return function (uri, callback)
end
if not source.step then
callback {
- start = source.init.start,
- finish = source.max.finish,
+ start = source.init.start,
+ finish = source.max.finish,
message = lang.script('DIAG_COUNT_DOWN_LOOP'
, ('%s, %s'):format(text:sub(
guide.positionToOffset(state, source.init.start),
guide.positionToOffset(state, source.max.finish)
- )
- , '-1')
+ ), '-1')
)
}
else
local stepNumber = tonumber(source.step[1])
if stepNumber and stepNumber > 0 then
callback {
- start = source.init.start,
- finish = source.step.finish,
+ start = source.init.start,
+ finish = source.step.finish,
message = lang.script('DIAG_COUNT_DOWN_LOOP'
, ('%s, -%s'):format(text:sub(
guide.positionToOffset(state, source.init.start),
guide.positionToOffset(state, source.max.finish)
- )
- , source.step[1])
+ ), source.step[1])
)
}
end
diff --git a/script/core/diagnostics/deprecated.lua b/script/core/diagnostics/deprecated.lua
index 1c248646..649f4dab 100644
--- a/script/core/diagnostics/deprecated.lua
+++ b/script/core/diagnostics/deprecated.lua
@@ -83,7 +83,11 @@ return function (uri, callback)
end
table.sort(versions)
if #versions > 0 then
- message = ('%s(%s)'):format(message, lang.script('DIAG_DEFINED_VERSION', table.concat(versions, '/'), config.get(uri, 'Lua.runtime.version')))
+ message = ('%s(%s)'):format(message
+ , lang.script('DIAG_DEFINED_VERSION'
+ , table.concat(versions, '/')
+ , config.get(uri, 'Lua.runtime.version'))
+ )
end
end
cache[id] = {
diff --git a/script/core/diagnostics/duplicate-doc-field.lua b/script/core/diagnostics/duplicate-doc-field.lua
index ab3084c9..71610ef5 100644
--- a/script/core/diagnostics/duplicate-doc-field.lua
+++ b/script/core/diagnostics/duplicate-doc-field.lua
@@ -15,7 +15,7 @@ return function (uri, callback)
local mark
for _, group in ipairs(state.ast.docs.groups) do
for _, doc in ipairs(group) do
- if doc.type == 'doc.class' then
+ if doc.type == 'doc.class' then
mark = {}
elseif doc.type == 'doc.field' then
if mark then
@@ -26,8 +26,8 @@ return function (uri, callback)
end
if mark[name] then
callback {
- start = doc.field.start,
- finish = doc.field.finish,
+ start = doc.field.start,
+ finish = doc.field.finish,
message = lang.script('DIAG_DUPLICATE_DOC_FIELD', name),
}
end
diff --git a/script/core/diagnostics/init.lua b/script/core/diagnostics/init.lua
index 562b526d..4368f51a 100644
--- a/script/core/diagnostics/init.lua
+++ b/script/core/diagnostics/init.lua
@@ -82,6 +82,7 @@ local function check(uri, name, isScopeDiag, response)
return
end
mark[result.start] = true
+
result.level = severity or result.level
result.code = name
response(result)
diff --git a/script/core/diagnostics/newline-call.lua b/script/core/diagnostics/newline-call.lua
index dbb8c690..3f2d5ca5 100644
--- a/script/core/diagnostics/newline-call.lua
+++ b/script/core/diagnostics/newline-call.lua
@@ -37,7 +37,10 @@ return function (uri, callback)
callback {
start = node.start,
finish = args.finish,
- message = lang.script('DIAG_PREVIOUS_CALL', text:sub(node.start, node.finish), text:sub(args.start, args.finish)),
+ message = lang.script('DIAG_PREVIOUS_CALL'
+ , text:sub(node.start, node.finish)
+ , text:sub(args.start, args.finish)
+ ),
}
end
end)
diff --git a/script/core/diagnostics/type-check.lua b/script/core/diagnostics/type-check.lua
index 5f37312e..58574bfa 100644
--- a/script/core/diagnostics/type-check.lua
+++ b/script/core/diagnostics/type-check.lua
@@ -51,10 +51,10 @@ local function isUserDefineClass(uri, name)
end
local function isClassOralias(typeName)
- if not typeName then
+ if not typeName then
return false
elseif typeNameMap[typeName]
- or vm.isBuiltinType(typeName) then
+ or vm.isBuiltinType(typeName) then
return true
else
return false
@@ -74,21 +74,21 @@ local function compatibleType(param, args)
param[1] = string.sub(param.type, 10)
end
for _, v in ipairs(args) do
- if v[1] == 'any' then
+ if v[1] == 'any' then
return true
elseif param[1] == v[1] then
return true
elseif (param[1] == 'number' or param[1] == 'integer')
- and (v[1] == 'integer' or v[1] == 'number') then
+ and (v[1] == 'integer' or v[1] == 'number') then
return true
elseif v[1] == 'string' then
---处理alias
--@alias searchmode '"ref"'|'"def"'
- if param[1] and param[1]:sub(1,1) == '"' then
+ if param[1] and param[1]:sub(1, 1) == '"' then
return true
end
elseif (isTable(v.type) or isTable(v[1]))
- and (isTable(param[1]) or isTable(param.type)) then
+ and (isTable(param[1]) or isTable(param.type)) then
return true
end
end
@@ -140,8 +140,8 @@ local function getParamTypes(arg)
return false
end
local types
- ---处理doc.type.function
- if arg.type == 'doc.type.arg' then
+ if arg.type == 'doc.type.arg' then
+ ---处理doc.type.function
if arg.name and arg.name[1] == '...' then
types = {
[1] = {
@@ -153,15 +153,15 @@ local function getParamTypes(arg)
end
types = arg.extends.types
return true, types
- ---处理function
elseif arg.type == 'local' then
+ ---处理function
local argDefs = vm.getDefs(arg)
if #argDefs == 0 then
return false
end
types = {}
- ---method, 如果self没有定义为一个class或者type,则认为它为any
if arg.tag == 'self' then
+ ---method, 如果self没有定义为一个class或者type,则认为它为any
for _, argDef in ipairs(argDefs) do
if argDef.type == 'doc.class.name'
or argDef.type == 'doc.type.name'
@@ -176,7 +176,7 @@ local function getParamTypes(arg)
return true, types
else
for _, argDef in ipairs(argDefs) do
- if argDef.type == 'doc.param' and argDef.extends then
+ if argDef.type == 'doc.param' and argDef.extends then
types = argDef.extends.types
if argDef.optional then
types[#types+1] = {
@@ -185,9 +185,9 @@ local function getParamTypes(arg)
}
end
elseif argDef.type == 'doc.type.enum'
- or argDef.type == 'doc.type.ltable' then
+ or argDef.type == 'doc.type.ltable' then
types[#types+1] = argDef
- ---变长参数
+ ---变长参数
elseif argDef.name and argDef.name[1] == '...' then
types = {
[1] = {
@@ -204,8 +204,8 @@ local function getParamTypes(arg)
return true, types
end
end
- ---处理只有一个可变参数
elseif arg.type == '...' then
+ ---处理只有一个可变参数
types = {
[1] = {
[1] = '...',
@@ -235,7 +235,7 @@ local function getInfoFromDefs(defs)
if suc then
local plusAlias = {}
for i, tp in ipairs(types) do
- local aliasDefs = vm.getDefs(tp)
+ local aliasDefs = vm.getDefs(tp)
for _, v in ipairs(aliasDefs) do
---TODO(arthur)
-- if not v.type then
@@ -376,32 +376,36 @@ local function matchParams(paramsTypes, i, arg)
end
flag = ''
for _, param in ipairs(paramTypes[i]) do
- if param[1] == '...' then
+ if param[1] == '...' then
hasVarargs = true
return true
- ---如果形参的类型在实参里面
elseif compatibleType(param, arg)
- or param[1] == 'any' then
+ or param[1] == 'any' then
+ ---如果形参的类型在实参里面
flag = ''
return true
- ---如果是泛型,不检查
elseif isGeneric(param) then
+ ---如果是泛型,不检查
return true
else
- ---TODO(arthur) 什么时候param[1]是nil?
if param[1] and not errType[param[1]] then
+ ---TODO(arthur) 什么时候param[1]是nil?
errType[param[1]] = true
- flag = flag ..' ' .. (param[1] or '')
+ flag = flag .. ' ' .. (param[1] or '')
end
end
end
if flag ~= '' then
local argm = '[ '
for _, v in ipairs(arg) do
- argm = argm .. v[1]..' '
+ argm = argm .. v[1] .. ' '
end
argm = argm .. ']'
- local message = 'Argument of type in '..argm..' is not assignable to parameter of type in ['..flag..' ]'
+ local message = 'Argument of type in '
+ .. argm
+ .. ' is not assignable to parameter of type in ['
+ .. flag
+ .. ' ]'
if not messages[message] then
messages[message] = true
messages[#messages+1] = message
@@ -413,12 +417,12 @@ local function matchParams(paramsTypes, i, arg)
end
---@async
-return function (uri, callback)
+return function(uri, callback)
local ast = files.getState(uri)
if not ast then
return
end
- guide.eachSourceType(ast.ast, 'call', function (source) ---@async
+ guide.eachSourceType(ast.ast, 'call', function(source) ---@async
if not source.args then
return
end
@@ -444,7 +448,7 @@ return function (uri, callback)
---都不匹配
if not match then
if #messages > 0 then
- callback{
+ callback {
start = arg.start,
finish = arg.finish,
message = table.concat(messages, '\n')
diff --git a/script/core/diagnostics/undefined-doc-class.lua b/script/core/diagnostics/undefined-doc-class.lua
index 5f3902a2..715583e7 100644
--- a/script/core/diagnostics/undefined-doc-class.lua
+++ b/script/core/diagnostics/undefined-doc-class.lua
@@ -1,7 +1,5 @@
local files = require 'files'
-local searcher = require 'core.searcher'
local lang = require 'language'
-local define = require 'proto.define'
local vm = require 'vm'
return function (uri, callback)
diff --git a/script/core/diagnostics/undefined-doc-param.lua b/script/core/diagnostics/undefined-doc-param.lua
index 86bf3871..98919284 100644
--- a/script/core/diagnostics/undefined-doc-param.lua
+++ b/script/core/diagnostics/undefined-doc-param.lua
@@ -1,8 +1,5 @@
local files = require 'files'
-local searcher = require 'core.searcher'
local lang = require 'language'
-local define = require 'proto.define'
-local vm = require 'vm'
local function hasParamName(func, name)
if not func.args then
diff --git a/script/core/diagnostics/undefined-env-child.lua b/script/core/diagnostics/undefined-env-child.lua
index 39c8de27..2f559697 100644
--- a/script/core/diagnostics/undefined-env-child.lua
+++ b/script/core/diagnostics/undefined-env-child.lua
@@ -1,8 +1,7 @@
-local files = require 'files'
-local searcher = require 'core.searcher'
-local guide = require 'parser.guide'
-local lang = require 'language'
-local vm = require "vm.vm"
+local files = require 'files'
+local guide = require 'parser.guide'
+local lang = require 'language'
+local vm = require "vm.vm"
return function (uri, callback)
local ast = files.getState(uri)
diff --git a/script/core/diagnostics/undefined-field.lua b/script/core/diagnostics/undefined-field.lua
index 2e64f0cc..7d309096 100644
--- a/script/core/diagnostics/undefined-field.lua
+++ b/script/core/diagnostics/undefined-field.lua
@@ -5,7 +5,7 @@ local guide = require 'parser.guide'
local noder = require 'core.noder'
local await = require 'await'
-local SkipCheckClass = {
+local skipCheckClass = {
['unknown'] = true,
['any'] = true,
['table'] = true,
@@ -49,7 +49,7 @@ return function (uri, callback)
local ok
for _, def in ipairs(defs) do
if def.type == 'doc.class.name'
- and not SkipCheckClass[def[1]] then
+ and not skipCheckClass[def[1]] then
ok = true
break
end
@@ -60,7 +60,7 @@ return function (uri, callback)
end
end
local message = lang.script('DIAG_UNDEF_FIELD', guide.getKeyName(src))
- if src.type == 'getfield' and src.field then
+ if src.type == 'getfield' and src.field then
callback {
start = src.field.start,
finish = src.field.finish,
diff --git a/script/core/document-symbol.lua b/script/core/document-symbol.lua
index 07794e60..33970042 100644
--- a/script/core/document-symbol.lua
+++ b/script/core/document-symbol.lua
@@ -5,8 +5,8 @@ local define = require 'proto.define'
local util = require 'utility'
local function buildName(source, text)
- local uri = guide.getUri(source)
- local state = files.getState(uri)
+ local uri = guide.getUri(source)
+ local state = files.getState(uri)
local startOffset = guide.positionToOffset(state, source.start)
if source.type == 'setmethod'
or source.type == 'getmethod' then
@@ -95,10 +95,10 @@ local function buildTable(tbl)
end
local function buildValue(source, text, symbols)
- local name = buildName(source, text)
+ local name = buildName(source, text)
local range, sRange, valueRange, kind
local details = {}
- if source.type == 'local' then
+ if source.type == 'local' then
if source.parent.type == 'funcargs' then
details[1] = 'param'
range = { source.start, source.finish }
@@ -141,7 +141,7 @@ local function buildValue(source, text, symbols)
end
if source.value then
local literal = source.value[1]
- if source.value.type == 'boolean' then
+ if source.value.type == 'boolean' then
details[2] = ' boolean'
if literal ~= nil then
details[3] = ' = '
@@ -202,7 +202,7 @@ local function buildAnonymousFunction(source, text, used, symbols)
used[source] = true
local head = ''
local parent = source.parent
- if parent.type == 'return' then
+ if parent.type == 'return' then
head = 'return '
elseif parent.type == 'callargs' then
local call = parent.parent
diff --git a/script/core/folding.lua b/script/core/folding.lua
index 2cf06d46..4f93aed9 100644
--- a/script/core/folding.lua
+++ b/script/core/folding.lua
@@ -3,7 +3,7 @@ local guide = require "parser.guide"
local util = require 'utility'
local await = require 'await'
-local Care = {
+local care = {
['function'] = function (source, text, results)
local folding = {
start = source.start,
@@ -95,8 +95,8 @@ local Care = {
['comment.short'] = function (source, text, results, status)
local ltext = source.text:lower()
ltext = util.trim(ltext, 'left')
- if ltext:sub(1, #'region') == 'region'
- or ltext:sub(1, #'#region') == '#region' then
+ if ltext:sub(1, #'region') == 'region'
+ or ltext:sub(1, #'#region') == '#region' then
if not status.regions then
status.regions = {}
end
@@ -157,16 +157,16 @@ return function (uri)
guide.eachSource(state.ast, function (source) ---@async
local tp = source.type
- if Care[tp] then
+ if care[tp] then
await.delay()
- Care[tp](source, text, regions)
+ care[tp](source, text, regions)
end
end)
for _, source in ipairs(state.comms) do
local tp = source.type
- if Care[tp] then
+ if care[tp] then
await.delay()
- Care[tp](source, text, regions, status)
+ care[tp](source, text, regions, status)
end
end
diff --git a/script/core/generic.lua b/script/core/generic.lua
index 2eb454ff..f260dc0b 100644
--- a/script/core/generic.lua
+++ b/script/core/generic.lua
@@ -119,7 +119,7 @@ local function createValue(closure, proto, callback, road)
if not tkey and not tvalue then
return nil
end
- local value = instantValue(closure, proto)
+ local value = instantValue(closure, proto)
value.tkey = tkey or proto.tkey
value.tvalue = tvalue or proto.tvalue
noder.compileNode(noder.getNoders(proto), value)
@@ -199,7 +199,7 @@ local function buildValues(closure)
for i, param in ipairs(params) do
local arg = args and args[i]
if arg then
- if arg.type == 'local' then
+ if arg.type == 'local' then
paramMap[arg[1]] = param
elseif arg.type == 'doc.type.arg' then
paramMap[arg.name[1]] = param
@@ -234,6 +234,7 @@ local function buildValues(closure)
local name = arg.name[1]
local extends = arg.extends
local param = paramMap[name]
+
closure.params[name] = param and createValue(closure, extends, function (road, key, proto)
buildValue(road, key, proto, param, upvalues)
end) or extends
@@ -249,7 +250,7 @@ end
---@return generic.closure
function m.createClosure(proto, call)
local protoFunction, parentClosure
- if proto.type == 'function' then
+ if proto.type == 'function' then
protoFunction = proto
elseif proto.type == 'doc.type.function' then
protoFunction = proto
diff --git a/script/core/highlight.lua b/script/core/highlight.lua
index bbfd1504..9db4b508 100644
--- a/script/core/highlight.lua
+++ b/script/core/highlight.lua
@@ -96,12 +96,12 @@ end
local function findKeyWord(state, text, position, callback)
guide.eachSourceContain(state.ast, position, function (source)
- if source.type == 'do'
- or source.type == 'function'
- or source.type == 'loop'
- or source.type == 'in'
- or source.type == 'while'
- or source.type == 'repeat' then
+ if source.type == 'do'
+ or source.type == 'function'
+ or source.type == 'loop'
+ or source.type == 'in'
+ or source.type == 'while'
+ or source.type == 'repeat' then
local ok
for i = 1, #source.keyword, 2 do
local start = source.keyword[i]
@@ -153,7 +153,7 @@ local function checkRegion(ast, text, offset, callback)
and comment.finish >= offset then
local ltext = comment.text:lower()
ltext = util.trim(ltext, 'left')
- if isRegion(ltext) then
+ if isRegion(ltext) then
start = comment.start - 2
count = 1
selected = i
@@ -177,7 +177,7 @@ local function checkRegion(ast, text, offset, callback)
if comment.type == 'comment.short' then
local ltext = comment.text:lower()
ltext = util.trim(ltext, 'left')
- if isRegion(ltext) then
+ if isRegion(ltext) then
count = count + 1
elseif isEndRegion(ltext) then
count = count - 1
@@ -195,7 +195,7 @@ local function checkRegion(ast, text, offset, callback)
if comment.type == 'comment.short' then
local ltext = comment.text:lower()
ltext = util.trim(ltext, 'left')
- if isEndRegion(ltext) then
+ if isEndRegion(ltext) then
count = count + 1
elseif isRegion(ltext) then
count = count - 1
@@ -223,7 +223,7 @@ local accept = {
['string'] = true,
['boolean'] = true,
['number'] = true,
- ['integer'] = true,
+ ['integer'] = true,
['nil'] = true,
}
@@ -289,27 +289,27 @@ return function (uri, offset)
kind = define.DocumentHighlightKind.Read
elseif target.type == 'field' then
if target.parent.type == 'getfield' then
- kind = define.DocumentHighlightKind.Read
+ kind = define.DocumentHighlightKind.Read
else
- kind = define.DocumentHighlightKind.Write
+ kind = define.DocumentHighlightKind.Write
end
elseif target.type == 'method' then
if target.parent.type == 'getmethod' then
- kind = define.DocumentHighlightKind.Read
+ kind = define.DocumentHighlightKind.Read
else
- kind = define.DocumentHighlightKind.Write
+ kind = define.DocumentHighlightKind.Write
end
elseif target.type == 'index' then
if target.parent.type == 'getindex' then
- kind = define.DocumentHighlightKind.Read
+ kind = define.DocumentHighlightKind.Read
else
- kind = define.DocumentHighlightKind.Write
+ kind = define.DocumentHighlightKind.Write
end
elseif target.type == 'index' then
if target.parent.type == 'getindex' then
- kind = define.DocumentHighlightKind.Read
+ kind = define.DocumentHighlightKind.Read
else
- kind = define.DocumentHighlightKind.Write
+ kind = define.DocumentHighlightKind.Write
end
elseif target.type == 'setindex'
or target.type == 'tableindex' then
@@ -318,18 +318,18 @@ return function (uri, offset)
elseif target.type == 'getlocal'
or target.type == 'getglobal'
or target.type == 'goto' then
- kind = define.DocumentHighlightKind.Read
+ kind = define.DocumentHighlightKind.Read
elseif target.type == 'setlocal'
or target.type == 'local'
or target.type == 'setglobal'
or target.type == 'label' then
- kind = define.DocumentHighlightKind.Write
+ kind = define.DocumentHighlightKind.Write
elseif target.type == 'string'
or target.type == 'boolean'
or target.type == 'number'
or target.type == 'integer'
or target.type == 'nil' then
- kind = define.DocumentHighlightKind.Text
+ kind = define.DocumentHighlightKind.Text
else
return
end
diff --git a/script/core/hover/description.lua b/script/core/hover/description.lua
index 43d15c39..d694660b 100644
--- a/script/core/hover/description.lua
+++ b/script/core/hover/description.lua
@@ -219,7 +219,7 @@ local function getBindEnums(source, docGroup)
local chunks = {}
local returnIndex = 0
for _, doc in ipairs(docGroup) do
- if doc.type == 'doc.param' then
+ if doc.type == 'doc.param' then
local name = doc.param[1]
if mark[name] then
goto CONTINUE
@@ -270,7 +270,7 @@ local function getFunctionComment(source)
local md = markdown()
for _, doc in ipairs(docGroup) do
- if doc.type == 'doc.comment' then
+ if doc.type == 'doc.comment' then
if doc.comment.text:sub(1, 1) == '-' then
md:add('md', doc.comment.text:sub(2))
else
diff --git a/script/core/hover/label.lua b/script/core/hover/label.lua
index a39f0eac..d07212f8 100644
--- a/script/core/hover/label.lua
+++ b/script/core/hover/label.lua
@@ -15,6 +15,7 @@ local function asFunction(source, oop)
local arg = buildArg(source, oop)
local rtn = buildReturn(source)
local lines = {}
+
lines[1] = string.format('%s%s %s(%s)'
, vm.isAsync(source) and 'async ' or ''
, oop and 'method' or 'function'
@@ -22,6 +23,7 @@ local function asFunction(source, oop)
, arg
)
lines[2] = rtn
+
return table.concat(lines, '\n')
end
@@ -89,10 +91,10 @@ local function isGlobalField(source)
or source.type == 'method' then
source = source.parent
end
- if source.type == 'setfield'
- or source.type == 'getfield'
- or source.type == 'setmethod'
- or source.type == 'getmethod' then
+ if source.type == 'setfield'
+ or source.type == 'getfield'
+ or source.type == 'setmethod'
+ or source.type == 'getmethod' then
local node = source.node
if node.type == 'setglobal'
or node.type == 'getglobal' then
@@ -178,8 +180,8 @@ end
---@async
return function (source, oop)
- if source.type == 'function'
- or source.type == 'doc.type.function' then
+ if source.type == 'function'
+ or source.type == 'doc.type.function' then
return asFunction(source, oop)
elseif source.type == 'local'
or source.type == 'getlocal'
diff --git a/script/core/hover/table.lua b/script/core/hover/table.lua
index 1310005f..374f756d 100644
--- a/script/core/hover/table.lua
+++ b/script/core/hover/table.lua
@@ -86,7 +86,7 @@ local function getKeyMap(fields)
for _, field in ipairs(fields) do
local key = vm.getKeyName(field)
local tp = vm.getKeyType(field)
- if tp == 'number' or tp == 'integer' then
+ if tp == 'number' or tp == 'integer' then
key = tonumber(key)
elseif tp == 'boolean' then
key = key == 'true'
@@ -123,7 +123,7 @@ local function getOptionalMap(fields)
if field.parent.optional then
local key = vm.getKeyName(field)
local tp = vm.getKeyType(field)
- if tp == 'number' or tp == 'integer' then
+ if tp == 'number' or tp == 'integer' then
key = tonumber(key)
elseif tp == 'boolean' then
key = key == 'true'
@@ -135,7 +135,7 @@ local function getOptionalMap(fields)
if field.optional then
local key = vm.getKeyName(field)
local tp = vm.getKeyType(field)
- if tp == 'number' or tp == 'integer' then
+ if tp == 'number' or tp == 'integer' then
key = tonumber(key)
elseif tp == 'boolean' then
key = key == 'true'
@@ -176,6 +176,7 @@ return function (source)
for i = 1, #keys do
await.delay()
local key = keys[i]
+
inferMap[key] = infer.searchAndViewInfers(source, key)
literalMap[key] = infer.searchAndViewLiterals(source, key)
if not tonumber(literalMap[key]) then
diff --git a/script/core/infer.lua b/script/core/infer.lua
index 3c62712e..88028a6c 100644
--- a/script/core/infer.lua
+++ b/script/core/infer.lua
@@ -5,11 +5,11 @@ local util = require 'utility'
local vm = require "vm.vm"
local guide = require "parser.guide"
-local CLASS = {'CLASS'}
-local TABLE = {'TABLE'}
-local CACHE = {'CACHE'}
+local CLASS = { 'CLASS' }
+local TABLE = { 'TABLE' }
+local CACHE = { 'CACHE' }
-local TypeSort = {
+local typeSort = {
['boolean'] = 1,
['string'] = 2,
['integer'] = 3,
@@ -52,7 +52,7 @@ local function searchInferOfUnary(value, infers, mark)
return
end
if op == '-' then
- if m.hasType(value[1], 'integer', mark) then
+ if m.hasType(value[1], 'integer', mark) then
infers['integer'] = true
elseif isBaseType(value[1], mark) then
infers['number'] = true
@@ -127,8 +127,8 @@ local function searchInferOfBinary(value, infers, mark)
or op == '*'
or op == '%'
or op == '//' then
- if m.hasType(value[1], 'integer', mark)
- and m.hasType(value[2], 'integer', mark) then
+ if m.hasType(value[1], 'integer', mark)
+ and m.hasType(value[2], 'integer', mark) then
infers['integer'] = true
elseif isBaseType(value[1], mark)
and isBaseType(value[2], mark) then
@@ -291,8 +291,8 @@ function m.viewInfers(uri, infers)
return 'any'
end
table.sort(result, function (a, b)
- local sa = TypeSort[a] or 100
- local sb = TypeSort[b] or 100
+ local sa = typeSort[a] or 100
+ local sb = typeSort[b] or 100
if sa == sb then
return a < b
else
diff --git a/script/core/keyword.lua b/script/core/keyword.lua
index 295026d7..5558106a 100644
--- a/script/core/keyword.lua
+++ b/script/core/keyword.lua
@@ -3,28 +3,28 @@ local files = require 'files'
local guide = require 'parser.guide'
local keyWordMap = {
- {'do', function (info, results)
+ { 'do', function(info, results)
if info.hasSpace then
results[#results+1] = {
- label = 'do .. end',
- kind = define.CompletionItemKind.Snippet,
+ label = 'do .. end',
+ kind = define.CompletionItemKind.Snippet,
insertTextFormat = 2,
- insertText = [[$0 end]],
+ insertText = [[$0 end]],
}
else
results[#results+1] = {
- label = 'do .. end',
- kind = define.CompletionItemKind.Snippet,
+ label = 'do .. end',
+ kind = define.CompletionItemKind.Snippet,
insertTextFormat = 2,
- insertText = "\z
+ insertText = "\z
do\
\t$0\
end",
}
end
return true
- end, function (info)
- return guide.eachSourceContain(info.state.ast, info.start, function (source)
+ end, function(info)
+ return guide.eachSourceContain(info.state.ast, info.start, function(source)
if source.type == 'while'
or source.type == 'in'
or source.type == 'loop' then
@@ -33,102 +33,102 @@ end",
end
end
end)
- end},
- {'and'},
- {'break'},
- {'else'},
- {'elseif', function (info, results)
+ end },
+ { 'and' },
+ { 'break' },
+ { 'else' },
+ { 'elseif', function(info, results)
local offset = guide.positionToOffset(info.state, info.position)
if info.text:find('^%s*then', offset + 1)
- or info.text:find('^%s*do', offset + 1) then
+ or info.text:find('^%s*do', offset + 1) then
return false
end
if info.hasSpace then
results[#results+1] = {
- label = 'elseif .. then',
- kind = define.CompletionItemKind.Snippet,
+ label = 'elseif .. then',
+ kind = define.CompletionItemKind.Snippet,
insertTextFormat = 2,
- insertText = [[$1 then]],
+ insertText = [[$1 then]],
}
else
results[#results+1] = {
- label = 'elseif .. then',
- kind = define.CompletionItemKind.Snippet,
+ label = 'elseif .. then',
+ kind = define.CompletionItemKind.Snippet,
insertTextFormat = 2,
- insertText = [[elseif $1 then]],
+ insertText = [[elseif $1 then]],
}
end
return true
- end},
- {'end'},
- {'false'},
- {'for', function (info, results)
+ end },
+ { 'end' },
+ { 'false' },
+ { 'for', function(info, results)
if info.hasSpace then
results[#results+1] = {
- label = 'for .. ipairs',
- kind = define.CompletionItemKind.Snippet,
+ label = 'for .. ipairs',
+ kind = define.CompletionItemKind.Snippet,
insertTextFormat = 2,
- insertText = "\z
+ insertText = "\z
${1:index}, ${2:value} in ipairs(${3:t}) do\
\t$0\
end"
}
results[#results+1] = {
- label = 'for .. pairs',
- kind = define.CompletionItemKind.Snippet,
+ label = 'for .. pairs',
+ kind = define.CompletionItemKind.Snippet,
insertTextFormat = 2,
- insertText = "\z
+ insertText = "\z
${1:key}, ${2:value} in pairs(${3:t}) do\
\t$0\
end"
}
results[#results+1] = {
- label = 'for i = ..',
- kind = define.CompletionItemKind.Snippet,
+ label = 'for i = ..',
+ kind = define.CompletionItemKind.Snippet,
insertTextFormat = 2,
- insertText = "\z
+ insertText = "\z
${1:i} = ${2:1}, ${3:10, 1} do\
\t$0\
end"
}
else
results[#results+1] = {
- label = 'for .. ipairs',
- kind = define.CompletionItemKind.Snippet,
+ label = 'for .. ipairs',
+ kind = define.CompletionItemKind.Snippet,
insertTextFormat = 2,
- insertText = "\z
+ insertText = "\z
for ${1:index}, ${2:value} in ipairs(${3:t}) do\
\t$0\
end"
}
results[#results+1] = {
- label = 'for .. pairs',
- kind = define.CompletionItemKind.Snippet,
+ label = 'for .. pairs',
+ kind = define.CompletionItemKind.Snippet,
insertTextFormat = 2,
- insertText = "\z
+ insertText = "\z
for ${1:key}, ${2:value} in pairs(${3:t}) do\
\t$0\
end"
}
results[#results+1] = {
- label = 'for i = ..',
- kind = define.CompletionItemKind.Snippet,
+ label = 'for i = ..',
+ kind = define.CompletionItemKind.Snippet,
insertTextFormat = 2,
- insertText = "\z
+ insertText = "\z
for ${1:i} = ${2:1}, ${3:10, 1} do\
\t$0\
end"
}
end
return true
- end},
- {'function', function (info, results)
+ end },
+ { 'function', function(info, results)
if info.hasSpace then
results[#results+1] = {
- label = 'function ()',
- kind = define.CompletionItemKind.Snippet,
+ label = 'function ()',
+ kind = define.CompletionItemKind.Snippet,
insertTextFormat = 2,
- insertText = info.isExp and "\z
+ insertText = info.isExp and "\z
($1)\
\t$0\
end" or "\z
@@ -138,10 +138,10 @@ end"
}
else
results[#results+1] = {
- label = 'function ()',
- kind = define.CompletionItemKind.Snippet,
+ label = 'function ()',
+ kind = define.CompletionItemKind.Snippet,
insertTextFormat = 2,
- insertText = info.isExp and "\z
+ insertText = info.isExp and "\z
function ($1)\
\t$0\
end" or "\z
@@ -151,126 +151,126 @@ end"
}
end
return true
- end},
- {'goto'},
- {'if', function (info, results)
+ end },
+ { 'goto' },
+ { 'if', function(info, results)
local offset = guide.positionToOffset(info.state, info.position)
if info.text:find('^%s*then', offset + 1)
- or info.text:find('^%s*do', offset + 1) then
+ or info.text:find('^%s*do', offset + 1) then
return false
end
if info.hasSpace then
results[#results+1] = {
- label = 'if .. then',
- kind = define.CompletionItemKind.Snippet,
+ label = 'if .. then',
+ kind = define.CompletionItemKind.Snippet,
insertTextFormat = 2,
- insertText = "\z
+ insertText = "\z
$1 then\
\t$0\
end"
}
else
results[#results+1] = {
- label = 'if .. then',
- kind = define.CompletionItemKind.Snippet,
+ label = 'if .. then',
+ kind = define.CompletionItemKind.Snippet,
insertTextFormat = 2,
- insertText = "\z
+ insertText = "\z
if $1 then\
\t$0\
end"
}
end
return true
- end},
- {'in', function (info, results)
+ end },
+ { 'in', function(info, results)
local offset = guide.positionToOffset(info.state, info.position)
if info.text:find('^%s*then', offset + 1)
- or info.text:find('^%s*do', offset + 1) then
+ or info.text:find('^%s*do', offset + 1) then
return false
end
if info.hasSpace then
results[#results+1] = {
- label = 'in ..',
- kind = define.CompletionItemKind.Snippet,
+ label = 'in ..',
+ kind = define.CompletionItemKind.Snippet,
insertTextFormat = 2,
- insertText = "\z
+ insertText = "\z
${1:pairs(${2:t})} do\
\t$0\
end"
}
else
results[#results+1] = {
- label = 'in ..',
- kind = define.CompletionItemKind.Snippet,
+ label = 'in ..',
+ kind = define.CompletionItemKind.Snippet,
insertTextFormat = 2,
- insertText = "\z
+ insertText = "\z
in ${1:pairs(${2:t})} do\
\t$0\
end"
}
end
return true
- end},
- {'local', function (info, results)
+ end },
+ { 'local', function(info, results)
if info.hasSpace then
results[#results+1] = {
- label = 'local function',
- kind = define.CompletionItemKind.Snippet,
+ label = 'local function',
+ kind = define.CompletionItemKind.Snippet,
insertTextFormat = 2,
- insertText = "\z
+ insertText = "\z
function $1($2)\
\t$0\
end"
}
else
results[#results+1] = {
- label = 'local function',
- kind = define.CompletionItemKind.Snippet,
+ label = 'local function',
+ kind = define.CompletionItemKind.Snippet,
insertTextFormat = 2,
- insertText = "\z
+ insertText = "\z
local function $1($2)\
\t$0\
end"
}
end
return false
- end},
- {'nil'},
- {'not'},
- {'or'},
- {'repeat', function (info, results)
+ end },
+ { 'nil' },
+ { 'not' },
+ { 'or' },
+ { 'repeat', function(info, results)
if info.hasSpace then
results[#results+1] = {
- label = 'repeat .. until',
- kind = define.CompletionItemKind.Snippet,
+ label = 'repeat .. until',
+ kind = define.CompletionItemKind.Snippet,
insertTextFormat = 2,
- insertText = [[$0 until $1]]
+ insertText = [[$0 until $1]]
}
else
results[#results+1] = {
- label = 'repeat .. until',
- kind = define.CompletionItemKind.Snippet,
+ label = 'repeat .. until',
+ kind = define.CompletionItemKind.Snippet,
insertTextFormat = 2,
- insertText = "\z
+ insertText = "\z
repeat\
\t$0\
until $1"
}
end
return true
- end},
- {'return', function (info, results)
+ end },
+ { 'return', function(info, results)
if not info.hasSpace then
results[#results+1] = {
- label = 'do return end',
- kind = define.CompletionItemKind.Snippet,
+ label = 'do return end',
+ kind = define.CompletionItemKind.Snippet,
insertTextFormat = 2,
- insertText = [[do return $1end]]
+ insertText = [[do return $1end]]
}
end
return false
- end},
- {'then', function (info, results)
+ end },
+ { 'then', function(info, results)
local startOffset = guide.positionToOffset(info.state, info.start)
local pos, first = info.text:match('%S+%s+()(%S+)', startOffset + 1)
if first == 'end'
@@ -279,51 +279,51 @@ until $1"
local startRow = guide.rowColOf(info.start)
local finishPosition = guide.offsetToPosition(info.state, pos)
local finishRow = guide.rowColOf(finishPosition)
- local startSp = info.text:match('^%s*', info.state.lines[startRow])
- local finishSp = info.text:match('^%s*', info.state.lines[finishRow])
+ local startSp = info.text:match('^%s*', info.state.lines[startRow])
+ local finishSp = info.text:match('^%s*', info.state.lines[finishRow])
if startSp == finishSp then
return false
end
end
if not info.hasSpace then
results[#results+1] = {
- label = 'then .. end',
- kind = define.CompletionItemKind.Snippet,
+ label = 'then .. end',
+ kind = define.CompletionItemKind.Snippet,
insertTextFormat = 2,
- insertText = '\z
+ insertText = '\z
then\
\t$0\
end'
}
end
return true
- end},
- {'true'},
- {'until'},
- {'while', function (info, results)
+ end },
+ { 'true' },
+ { 'until' },
+ { 'while', function(info, results)
if info.hasSpace then
results[#results+1] = {
- label = 'while .. do',
- kind = define.CompletionItemKind.Snippet,
+ label = 'while .. do',
+ kind = define.CompletionItemKind.Snippet,
insertTextFormat = 2,
- insertText = "\z
+ insertText = "\z
${1:true} do\
\t$0\
end"
}
else
results[#results+1] = {
- label = 'while .. do',
- kind = define.CompletionItemKind.Snippet,
+ label = 'while .. do',
+ kind = define.CompletionItemKind.Snippet,
insertTextFormat = 2,
- insertText = "\z
+ insertText = "\z
while ${1:true} do\
\t$0\
end"
}
end
return true
- end},
+ end },
}
return keyWordMap
diff --git a/script/core/look-backward.lua b/script/core/look-backward.lua
index 2f90b768..82f2ea1f 100644
--- a/script/core/look-backward.lua
+++ b/script/core/look-backward.lua
@@ -38,7 +38,7 @@ function m.findWord(text, offset)
if i == offset then
return nil
end
- return text:sub(i+1, offset), i+1
+ return text:sub(i + 1, offset), i + 1
end
end
return text:sub(1, offset), 1
diff --git a/script/library.lua b/script/library.lua
index dc06f978..501f70d4 100644
--- a/script/library.lua
+++ b/script/library.lua
@@ -410,7 +410,7 @@ local function wholeMatch(a, b)
if not pos1 then
return false
end
- local left = a:sub(pos1 - 1, pos1-1)
+ local left = a:sub(pos1 - 1, pos1 - 1)
local right = a:sub(pos2, pos2)
if left:match '[%w_]'
or right:match '[%w_]' then
diff --git a/script/parser/compile.lua b/script/parser/compile.lua
index d6c6a526..752728d1 100644
--- a/script/parser/compile.lua
+++ b/script/parser/compile.lua
@@ -61,7 +61,7 @@ local vmMap = {
addRef(node, obj)
end
local name = obj[1]
- if specials[name] then
+ if specials[name] then
addSpecial(name, obj)
elseif Options and Options.special then
local asName = Options.special[name]
@@ -90,9 +90,9 @@ local vmMap = {
for k, v in pairs(obj.node.node) do
newNode[k] = v
end
- newNode.mirror = obj.node.node
- newNode.dummy = true
- newNode.parent = obj.args
+ newNode.mirror = obj.node.node
+ newNode.dummy = true
+ newNode.parent = obj.args
obj.node.node.mirror = newNode
tableInsert(obj.args, 1, newNode)
Compiled[newNode] = true
@@ -249,7 +249,7 @@ local vmMap = {
addRef(node, obj)
end
local name = obj[1]
- if specials[name] then
+ if specials[name] then
addSpecial(name, obj)
elseif Options and Options.special then
local asName = Options.special[name]
@@ -332,9 +332,9 @@ local vmMap = {
if Version == 'Lua 5.4'
or block == guide.getBlock(label) then
pushError {
- type = 'REDEFINED_LABEL',
- start = obj.start,
- finish = obj.finish,
+ type = 'REDEFINED_LABEL',
+ start = obj.start,
+ finish = obj.finish,
relative = {
{
label.start,
@@ -538,10 +538,10 @@ local function compileGoTo(obj)
local ref = refs[j]
if ref.finish > label.finish then
pushError {
- type = 'JUMP_LOCAL_SCOPE',
- start = obj.start,
- finish = obj.finish,
- info = {
+ type = 'JUMP_LOCAL_SCOPE',
+ start = obj.start,
+ finish = obj.finish,
+ info = {
loc = loc[1],
},
relative = {
diff --git a/script/parser/grammar.lua b/script/parser/grammar.lua
index 154bd7ba..a28b7950 100644
--- a/script/parser/grammar.lua
+++ b/script/parser/grammar.lua
@@ -31,18 +31,19 @@ local RESERVED = {
['while'] = true,
}
-defs.nl = (m.P'\r\n' + m.S'\r\n')
-defs.s = m.S' \t'
-defs.S = - defs.s
-defs.ea = '\a'
-defs.eb = '\b'
-defs.ef = '\f'
-defs.en = '\n'
-defs.er = '\r'
-defs.et = '\t'
-defs.ev = '\v'
-defs['nil'] = m.Cp() / function () return nil end
+defs.nl = (m.P'\r\n' + m.S'\r\n')
+defs.s = m.S' \t'
+defs.S = - defs.s
+defs.ea = '\a'
+defs.eb = '\b'
+defs.ef = '\f'
+defs.en = '\n'
+defs.er = '\r'
+defs.et = '\t'
+defs.ev = '\v'
+defs['nil'] = m.Cp() / function () return nil end
defs['false'] = m.Cp() / function () return false end
+
defs.NotReserved = function (_, _, str)
if RESERVED[str] then
return false