summaryrefslogtreecommitdiff
path: root/script-beta/core
diff options
context:
space:
mode:
Diffstat (limited to 'script-beta/core')
-rw-r--r--script-beta/core/completion.lua26
-rw-r--r--script-beta/core/diagnostics/unused-local.lua65
2 files changed, 62 insertions, 29 deletions
diff --git a/script-beta/core/completion.lua b/script-beta/core/completion.lua
index a19edb5e..b0f15f74 100644
--- a/script-beta/core/completion.lua
+++ b/script-beta/core/completion.lua
@@ -360,29 +360,15 @@ end]]
end},
{'function', function (ast, text, start, results)
if config.config.completion.keywordSnippet then
- local spStart = skipSpace(text, start - 1)
- local before = findWord(text, spStart)
- if before == 'local' then
- results[#results+1] = {
- label = 'function ()',
- kind = ckind.Snippet,
- insertTextFormat = 2,
- insertText = [[
-function ($1)
- $0
-end]]
- }
- else
- results[#results+1] = {
- label = 'function ()',
- kind = ckind.Snippet,
- insertTextFormat = 2,
- insertText = [[
+ results[#results+1] = {
+ label = 'function ()',
+ kind = ckind.Snippet,
+ insertTextFormat = 2,
+ insertText = [[
function $1($2)
$0
end]]
- }
- end
+ }
end
end},
{'goto'},
diff --git a/script-beta/core/diagnostics/unused-local.lua b/script-beta/core/diagnostics/unused-local.lua
index 22b2e16b..294a86e5 100644
--- a/script-beta/core/diagnostics/unused-local.lua
+++ b/script-beta/core/diagnostics/unused-local.lua
@@ -7,19 +7,46 @@ local function hasGet(loc)
if not loc.ref then
return false
end
+ local weak
for _, ref in ipairs(loc.ref) do
if ref.type == 'getlocal' then
if not ref.next then
- return true
+ return 'strong'
end
local nextType = ref.next.type
if nextType ~= 'setmethod'
and nextType ~= 'setfield'
and nextType ~= 'setindex' then
- return true
+ return 'strong'
+ else
+ weak = true
end
end
end
+ if weak then
+ return 'weak'
+ else
+ return nil
+ end
+end
+
+local function isMyTable(loc)
+ local value = loc.value
+ if value and value.type == 'table' then
+ return true
+ end
+ return false
+end
+
+local function isClose(source)
+ if not source.attrs then
+ return false
+ end
+ for _, attr in ipairs(source.attrs) do
+ if attr[1] == 'close' then
+ return true
+ end
+ end
return false
end
@@ -34,13 +61,33 @@ return function (uri, callback)
or name == '_ENV' then
return
end
- if not hasGet(source) then
- callback {
- start = source.start,
- finish = source.finish,
- tags = { define.DiagnosticTag.Unnecessary },
- message = lang.script('DIAG_UNUSED_LOCAL', name),
- }
+ if isClose(source) then
+ return
+ end
+ local data = hasGet(source)
+ if data == 'strong' then
+ return
+ end
+ if data == 'weak' then
+ if not isMyTable(source) then
+ return
+ end
+ end
+ callback {
+ start = source.start,
+ finish = source.finish,
+ tags = { define.DiagnosticTag.Unnecessary },
+ message = lang.script('DIAG_UNUSED_LOCAL', name),
+ }
+ if source.ref then
+ for _, ref in ipairs(source.ref) do
+ callback {
+ start = ref.start,
+ finish = ref.finish,
+ tags = { define.DiagnosticTag.Unnecessary },
+ message = lang.script('DIAG_UNUSED_LOCAL', name),
+ }
+ end
end
end)
end