summaryrefslogtreecommitdiff
path: root/script/core
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2022-02-16 15:22:45 +0800
committer最萌小汐 <sumneko@hotmail.com>2022-02-16 15:22:45 +0800
commit30bc6d37b823cab58114ea09c3f6388c6ef30b02 (patch)
tree18fa3cf12eafe6b06bf2eb60b08302311a3b2698 /script/core
parent8f2c4227753f300e717fa218d915c281dbc3e175 (diff)
parent12d6a9eb75f31b64cbc89eb3265805bc8dad01f0 (diff)
downloadlua-language-server-30bc6d37b823cab58114ea09c3f6388c6ef30b02.zip
Merge commit '12d6a9eb75f31b64cbc89eb3265805bc8dad01f0' into 3.0
Diffstat (limited to 'script/core')
-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/codestyle-check.lua20
-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/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
24 files changed, 340 insertions, 322 deletions
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 4c78972f..569847a4 100644
--- a/script/core/completion/completion.lua
+++ b/script/core/completion/completion.lua
@@ -22,7 +22,7 @@ local infer = require 'core.infer'
local await = require 'await'
local postfix = require 'core.completion.postfix'
-local DiagnosticModes = {
+local diagnosticModes = {
'disable-next-line',
'disable-line',
'disable',
@@ -100,9 +100,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
@@ -111,7 +111,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
@@ -197,10 +197,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::
@@ -227,19 +227,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
@@ -261,7 +263,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]
@@ -293,11 +295,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),
@@ -326,7 +328,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
@@ -361,10 +363,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 = {
@@ -375,7 +377,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),
@@ -427,9 +429,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'
@@ -505,13 +507,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
@@ -519,7 +522,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
@@ -726,7 +729,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
@@ -869,7 +872,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)
@@ -971,11 +974,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
@@ -1137,8 +1140,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
@@ -1246,7 +1249,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)
@@ -1351,8 +1354,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
@@ -1376,7 +1379,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
@@ -1467,10 +1470,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),
@@ -1597,7 +1600,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
@@ -1632,7 +1635,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
@@ -1698,7 +1701,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,
@@ -1716,8 +1719,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,
@@ -1733,7 +1736,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
@@ -1793,7 +1796,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,
@@ -1875,11 +1878,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 11223187..9270367f 100644
--- a/script/core/definition.lua
+++ b/script/core/definition.lua
@@ -19,8 +19,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)
@@ -141,9 +141,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
@@ -152,8 +152,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/codestyle-check.lua b/script/core/diagnostics/codestyle-check.lua
index 16623eca..34d55ee2 100644
--- a/script/core/diagnostics/codestyle-check.lua
+++ b/script/core/diagnostics/codestyle-check.lua
@@ -1,8 +1,8 @@
-local files = require("files")
-local codeFormat = require "code_format"
-local converter = require("proto.converter")
-local log = require("log")
-local config = require("config")
+local files = require 'files'
+local codeFormat = require 'code_format'
+local converter = require 'proto.converter'
+local log = require 'log'
+local pformatting = require 'provider.formatting'
---@async
@@ -12,6 +12,8 @@ return function(uri, callback)
return
end
+ pformatting.updateConfig(uri)
+
local status, diagnosticInfos = codeFormat.diagnose_file(uri, text)
if not status then
@@ -21,12 +23,12 @@ return function(uri, callback)
return
end
-
+
if diagnosticInfos then
- for _, diagnosticInfo in pairs(diagnosticInfos) do
+ for _, diagnosticInfo in ipairs(diagnosticInfos) do
callback {
- start = converter.unpackPosition(uri, diagnosticInfo.range.start),
- finish = converter.unpackPosition(uri, diagnosticInfo.range["end"]),
+ start = converter.unpackPosition(uri, diagnosticInfo.range.start),
+ finish = converter.unpackPosition(uri, diagnosticInfo.range["end"]),
message = diagnosticInfo.message
}
end
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 28f67b15..bd2a95b0 100644
--- a/script/core/diagnostics/deprecated.lua
+++ b/script/core/diagnostics/deprecated.lua
@@ -82,7 +82,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 5394665c..0ad2045e 100644
--- a/script/core/diagnostics/duplicate-doc-field.lua
+++ b/script/core/diagnostics/duplicate-doc-field.lua
@@ -14,7 +14,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
@@ -25,8 +25,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 b456ef9a..ea15dcda 100644
--- a/script/core/diagnostics/undefined-field.lua
+++ b/script/core/diagnostics/undefined-field.lua
@@ -4,7 +4,7 @@ local lang = require 'language'
local guide = require 'parser.guide'
local await = require 'await'
-local SkipCheckClass = {
+local skipCheckClass = {
['unknown'] = true,
['any'] = true,
['table'] = true,
@@ -48,7 +48,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
@@ -59,7 +59,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/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 d57139b3..a5b30cf3 100644
--- a/script/core/hover/description.lua
+++ b/script/core/hover/description.lua
@@ -218,7 +218,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
@@ -269,7 +269,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 ab5e2180..d98449d1 100644
--- a/script/core/infer.lua
+++ b/script/core/infer.lua
@@ -3,11 +3,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,
@@ -50,7 +50,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
@@ -125,8 +125,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
@@ -289,8 +289,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