-
-
Notifications
You must be signed in to change notification settings - Fork 423
Expand file tree
/
Copy pathno-unknown.lua
More file actions
54 lines (51 loc) · 1.57 KB
/
no-unknown.lua
File metadata and controls
54 lines (51 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
local files = require 'files'
local guide = require 'parser.guide'
local lang = require 'language'
local vm = require 'vm'
local await = require 'await'
local types = {
'local',
'setlocal',
'setglobal',
'getglobal',
'setfield',
'setindex',
'tablefield',
'tableindex',
}
---@async
return function (uri, callback)
local ast = files.getState(uri)
if not ast then
return
end
---@async
guide.eachSourceTypes(ast.ast, types, function (source)
await.delay()
if vm.getInfer(source):view(uri) == 'unknown' then
-- When a node only contains a 'variable' object whose base
-- declaration has a known type, this is a false positive caused
-- by circular dependency during compilation, not a true unknown.
local dominated = false
local node = vm.getNode(source)
if node then
for n in node:eachObject() do
if n.type == 'variable' and n.base and n.base.value then
local baseView = vm.getInfer(n.base):view(uri)
if baseView ~= 'unknown' then
dominated = true
break
end
end
end
end
if not dominated then
callback {
start = source.start,
finish = source.finish,
message = lang.script('DIAG_UNKNOWN'),
}
end
end
end)
end