-
-
Notifications
You must be signed in to change notification settings - Fork 423
Expand file tree
/
Copy pathmissing-doc-helper.lua
More file actions
117 lines (102 loc) · 3.59 KB
/
missing-doc-helper.lua
File metadata and controls
117 lines (102 loc) · 3.59 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
local lang = require 'language'
local m = {}
local function findParam(docs, param)
if not docs then
return false
end
for _, doc in ipairs(docs) do
if doc.type == 'doc.param' then
if doc.param[1] == param then
return true
end
end
end
return false
end
local function findReturn(docs, index)
if not docs then
return false
end
for _, doc in ipairs(docs) do
if doc.type == 'doc.return' then
for _, ret in ipairs(doc.returns) do
if ret.returnIndex == index then
return true
end
end
end
end
return false
end
---@param functionName string
---@param source parser.object
---@param diagnosticRangeSource? parser.object sometimes the object with the data isn't the one that needs the diagnostics
---@param bindDocsSource? parser.object sometimes the object with the bind docs isn't the value (`a.b = c` syntax)
---@param callback fun(result: any)
---@param commentId string
---@param paramId string
---@param returnId string
local function checkFunctionNamed(functionName, source, diagnosticRangeSource, bindDocsSource, callback, commentId,
paramId, returnId)
diagnosticRangeSource = diagnosticRangeSource or source
bindDocsSource = bindDocsSource or source
local argCount = source.args and #source.args or 0
local noRealArgs = argCount == 0 or (argCount == 1 and source.args[1][1] == 'self')
if noRealArgs and not source.returns and not bindDocsSource.bindDocs then
callback {
start = diagnosticRangeSource.start,
finish = diagnosticRangeSource.finish,
message = lang.script(commentId, functionName),
}
end
if argCount > 0 then
for _, arg in ipairs(source.args) do
local argName = arg[1]
if argName ~= 'self'
and argName ~= '_' then
if not findParam(bindDocsSource.bindDocs, argName) then
callback {
start = arg.start,
finish = arg.finish,
message = lang.script(paramId, argName, functionName),
}
end
end
end
end
if source.returns then
for _, ret in ipairs(source.returns) do
for index, expr in ipairs(ret) do
if not findReturn(bindDocsSource.bindDocs, index) then
callback {
start = expr.start,
finish = expr.finish,
message = lang.script(returnId, index, functionName),
}
end
end
end
end
end
---@param source parser.object
---@param callback fun(result: any)
---@param commentId string
---@param paramId string
---@param returnId string
local function checkFunction(source, callback, commentId, paramId, returnId)
local functionName = source.parent[1]
checkFunctionNamed(functionName, source, nil, nil, callback, commentId, paramId, returnId)
end
---@param source parser.object
---@param callback fun(result: any)
---@param commentId string
---@param paramId string
---@param returnId string
local function checkMethod(source, callback, commentId, paramId, returnId)
local functionName = source.method[1]
checkFunctionNamed(functionName, source.value, source, nil, callback, commentId, paramId, returnId)
end
m.CheckFunction = checkFunction
m.CheckFunctionNamed = checkFunctionNamed
m.CheckMethod = checkMethod
return m