diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2019-03-04 13:45:30 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2019-03-04 13:45:30 +0800 |
commit | bcec4c1f25f0cac07a56e4fcfe98fe1477d97f29 (patch) | |
tree | 419a720e94bbd9b1dcb7a864c799241b5cd4a433 /server/src | |
parent | 93d6d913857c29caadcc6292c0befdfb278a63b7 (diff) | |
download | lua-language-server-bcec4c1f25f0cac07a56e4fcfe98fe1477d97f29.zip |
shadow
Diffstat (limited to 'server/src')
-rw-r--r-- | server/src/core/diagnostics.lua | 38 | ||||
-rw-r--r-- | server/src/vm/function.lua | 4 | ||||
-rw-r--r-- | server/src/vm/local.lua | 13 |
3 files changed, 34 insertions, 21 deletions
diff --git a/server/src/core/diagnostics.lua b/server/src/core/diagnostics.lua index 5f2e03e1..47542fa5 100644 --- a/server/src/core/diagnostics.lua +++ b/server/src/core/diagnostics.lua @@ -141,30 +141,27 @@ function mt:searchSpaces(callback) end function mt:searchRedefinition(callback) - local results = self.results - local uri = self.uri local used = {} - for _, var in ipairs(results.locals) do - if var.key == '_' - or var.key == '_ENV' - or var.key == '' - then - goto NEXT_VAR - end - if var.hide then - goto NEXT_VAR + local uri = self.uri + self.vm:eachSource(function (source) + local loc = source:bindLocal() + if not loc then + return end - local shadow = var.shadow + local shadow = loc:shadow() if not shadow then - goto NEXT_VAR + return end if used[shadow] then - goto NEXT_VAR + return end used[shadow] = true - -- 如果多次重定义,则不再警告 - if #shadow >= 4 then - goto NEXT_VAR + if loc:getFlag 'hide' then + return + end + local name = loc:getName() + if name == '_' or name == '_ENV' or name == '' then + return end local related = {} for i = 1, #shadow do @@ -175,10 +172,9 @@ function mt:searchRedefinition(callback) } end for i = 2, #shadow do - callback(shadow[i].source.start, shadow[i].source.finish, shadow[i].key, related) + callback(shadow[i].source.start, shadow[i].source.finish, name, related) end - ::NEXT_VAR:: - end + end) end function mt:searchNewLineCall(callback) @@ -278,7 +274,7 @@ return function (vm, lines, uri) -- 重定义局部变量 session:doDiagnostics(session.searchRedefinition, 'redefined-local', function (key, related) return { - level = DiagnosticSeverity.Information, + level = DiagnosticSeverity.Hint, message = lang.script('DIAG_REDEFINED_LOCAL', key), related = related, } diff --git a/server/src/vm/function.lua b/server/src/vm/function.lua index 2d9e570d..a6835f5b 100644 --- a/server/src/vm/function.lua +++ b/server/src/vm/function.lua @@ -26,6 +26,10 @@ function mt:saveLocal(name, loc) if loc.type ~= 'local' then error('saveLocal必须是local') end + local old = self:loadLocal(name) + if old then + loc:shadow(old) + end self.locals[self._top][name] = loc end diff --git a/server/src/vm/local.lua b/server/src/vm/local.lua index 75f41db2..6062d28e 100644 --- a/server/src/vm/local.lua +++ b/server/src/vm/local.lua @@ -56,6 +56,19 @@ function mt:getName() return self.name end +function mt:shadow(old) + if not old then + return self._shadow + end + local group = old._shadow + if not group then + group = {} + group[#group+1] = old + end + group[#group+1] = self + self._shadow = group +end + return function (name, source, value) if not value then error('Local must has a value') |