summaryrefslogtreecommitdiff
path: root/server-beta
diff options
context:
space:
mode:
Diffstat (limited to 'server-beta')
-rw-r--r--server-beta/src/core/diagnostics/lowercase-global.lua13
-rw-r--r--server-beta/src/parser/guide.lua27
-rw-r--r--server-beta/src/searcher/eachRef.lua6
-rw-r--r--server-beta/src/searcher/getLibrary.lua35
-rw-r--r--server-beta/test/diagnostics/init.lua4
5 files changed, 70 insertions, 15 deletions
diff --git a/server-beta/src/core/diagnostics/lowercase-global.lua b/server-beta/src/core/diagnostics/lowercase-global.lua
index 87a12190..f1ebdce5 100644
--- a/server-beta/src/core/diagnostics/lowercase-global.lua
+++ b/server-beta/src/core/diagnostics/lowercase-global.lua
@@ -20,18 +20,11 @@ return function (uri, callback)
end
guide.eachSourceType(ast.ast, 'setglobal', function (source)
- local name = guide.getKeyName(source)
- if not name then
+ local name = guide.getKeyString(source)
+ if definedGlobal[name] then
return
end
- local sname = name:match '^s|(.+)$'
- if not sname then
- return
- end
- if definedGlobal[sname] then
- return
- end
- local first = sname:match '%w'
+ local first = name:match '%w'
if not first then
return
end
diff --git a/server-beta/src/parser/guide.lua b/server-beta/src/parser/guide.lua
index f1fedbd9..a5b8202e 100644
--- a/server-beta/src/parser/guide.lua
+++ b/server-beta/src/parser/guide.lua
@@ -442,6 +442,33 @@ function m.lineRange(lines, row)
return line.start, line.finish
end
+function m.getKeyString(obj)
+ local tp = obj.type
+ if tp == 'getglobal'
+ or tp == 'setglobal' then
+ return obj[1]
+ elseif tp == 'getfield'
+ or tp == 'setfield'
+ or tp == 'tablefield' then
+ return obj.field[1]
+ elseif tp == 'getmethod'
+ or tp == 'setmethod' then
+ return obj.method[1]
+ elseif tp == 'getindex'
+ or tp == 'setindex'
+ or tp == 'tableindex' then
+ return m.getKeyString(obj.index)
+ elseif tp == 'field'
+ or tp == 'method' then
+ return obj[1]
+ elseif tp == 'index' then
+ return m.getKeyString(obj.index)
+ elseif tp == 'string' then
+ return obj[1]
+ end
+ return nil
+end
+
function m.getKeyName(obj)
local tp = obj.type
if tp == 'getglobal'
diff --git a/server-beta/src/searcher/eachRef.lua b/server-beta/src/searcher/eachRef.lua
index 743b693e..eb6fc992 100644
--- a/server-beta/src/searcher/eachRef.lua
+++ b/server-beta/src/searcher/eachRef.lua
@@ -164,7 +164,7 @@ end
local function asValue(source, callback)
local parent = source.parent
if parent and parent.value == source then
- if guide.getKeyName(parent) == 's|__index' then
+ if guide.getKeyString(parent) == '__index' then
if parent.type == 'tablefield'
or parent.type == 'tableindex' then
local t = parent.parent
@@ -267,7 +267,7 @@ local function ofLocal(loc, callback)
local parent = ref.parent
if parent.type == 'getfield'
or parent.type == 'getindex' then
- if guide.getKeyName(parent) == 's|_G' then
+ if guide.getKeyName(parent) == '_G' then
callback {
source = parent,
mode = 'get',
@@ -275,7 +275,7 @@ local function ofLocal(loc, callback)
end
end
elseif ref.type == 'getglobal' then
- if guide.getKeyName(ref) == 's|_G' then
+ if guide.getKeyString(ref) == '_G' then
callback {
source = ref,
mode = 'get',
diff --git a/server-beta/src/searcher/getLibrary.lua b/server-beta/src/searcher/getLibrary.lua
index b920387d..a2620295 100644
--- a/server-beta/src/searcher/getLibrary.lua
+++ b/server-beta/src/searcher/getLibrary.lua
@@ -1,7 +1,8 @@
local searcher = require 'searcher.searcher'
local library = require 'library'
+local guide = require 'parser.guide'
-local function getLibrary(source)
+local function checkStdLibrary(source)
local globalName = searcher.getGlobal(source)
if not globalName then
return nil
@@ -10,7 +11,37 @@ local function getLibrary(source)
if library.global[name] then
return library.global[name]
end
- return nil
+end
+
+local function getLibrary(source)
+ local lib = checkStdLibrary(source)
+ if lib then
+ return lib
+ end
+ return searcher.eachRef(source, function (info)
+ local src = info.source
+ if src.type ~= 'getfield'
+ and src.type ~= 'getmethod'
+ and src.type ~= 'getindex' then
+ return
+ end
+ local node = src.node
+ local nodeGlobalName = searcher.getGlobal(node)
+ if not nodeGlobalName then
+ return
+ end
+ local nodeName = nodeGlobalName:match '^s|(.+)$'
+ local nodeLib = library.global[nodeName]
+ if not nodeLib then
+ return
+ end
+ if not nodeLib.child then
+ return
+ end
+ local key = guide.getKeyString(src)
+ local defLib = nodeLib.child[key]
+ return defLib
+ end)
end
function searcher.getLibrary(source)
diff --git a/server-beta/test/diagnostics/init.lua b/server-beta/test/diagnostics/init.lua
index 40f605e6..35b46c77 100644
--- a/server-beta/test/diagnostics/init.lua
+++ b/server-beta/test/diagnostics/init.lua
@@ -683,3 +683,7 @@ t.a = 1
t.a = 2
return t
]]
+
+TEST [[
+table.insert({}, 1, 2, <!3!>)
+]]