Skip to content

Commit 885833e

Browse files
authored
Merge pull request #381 from xuhuanzy/completion
update
2 parents c52277f + aaa86db commit 885833e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+1586
-198
lines changed

crates/emmylua_code_analysis/resources/schema.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@
143143
"strict": {
144144
"default": {
145145
"arrayIndex": true,
146+
"metaOverrideFileDefine": true,
146147
"requirePath": false,
147148
"typeCall": false
148149
},
@@ -852,6 +853,11 @@
852853
"default": true,
853854
"type": "boolean"
854855
},
856+
"metaOverrideFileDefine": {
857+
"description": "meta define overrides file define",
858+
"default": true,
859+
"type": "boolean"
860+
},
855861
"requirePath": {
856862
"description": "Whether to enable strict mode require path.",
857863
"default": false,

crates/emmylua_code_analysis/resources/std/builtin.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@
5555
--- integrity of data owned by the host program.
5656
---@class userdata
5757

58+
---@class lightuserdata
59+
5860
---
5961
--- The type *thread* represents independent threads of execution and it is
6062
--- used to implement coroutines. Lua threads are not related to

crates/emmylua_code_analysis/resources/std/debug.lua

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,17 @@ function debug.gethook(thread) end
6363
---@field ntransfer integer
6464
---@field activelines table
6565

66+
---@alias debuglib.InfoWhat
67+
---|+"n" # `name` 和 `namewhat`
68+
---|+"S" # `source`,`short_src`,`linedefined`,`lalinedefined`,和 `what`
69+
---|+"l" # `currentline`
70+
---|+"t" # `istailcall`
71+
---|+"u" # `nups`、`nparams` 和 `isvararg`
72+
---|+"f" # `func`
73+
---|+"r" # `ftransfer` 和 `ntransfer`
74+
---|+"L" # `activelines`
75+
---| string
76+
6677
---
6778
--- Returns a table with information about a function. You can give the
6879
--- function directly, or you can give a number as the value of `f`,
@@ -83,10 +94,10 @@ function debug.gethook(thread) end
8394
--- with a name for the current function, if a reasonable name can be found,
8495
--- and the expression `debug.getinfo(print)` returns a table with all available
8596
--- information about the `print` function.
86-
---@overload fun(f: int|function, what?: string):debuglib.DebugInfo
97+
---@overload fun(f: int|function, what?: debuglib.InfoWhat):debuglib.DebugInfo
8798
---@param thread thread
88-
---@param f function
89-
---@param what? string
99+
---@param f integer|function
100+
---@param what? debuglib.InfoWhat
90101
---@return debuglib.DebugInfo
91102
---@nodiscard
92103
function debug.getinfo(thread, f, what) end
@@ -146,10 +157,10 @@ function debug.getlocal(thread, lvl, index) end
146157
---
147158
--- Returns the metatable of the given `value` or **nil** if it does not have
148159
--- a metatable.
149-
---@param value table
160+
---@param object any
150161
---@return table?
151162
---@nodiscard
152-
function debug.getmetatable(value) end
163+
function debug.getmetatable(object) end
153164

154165
---
155166
--- Returns the registry table.
@@ -164,7 +175,7 @@ function debug.getregistry() end
164175
---
165176
--- Variable names starting with '(' (open parenthesis) represent variables with
166177
--- no known names (variables from chunks saved without debug information).
167-
---@param f async fun(...):any...
178+
---@param f function
168179
---@param up integer
169180
---@return string name
170181
---@return any value
@@ -176,6 +187,7 @@ function debug.getupvalue(f, up) end
176187
--- **false** if the userdata does not have that value.
177188
---@param u userdata
178189
---@param n integer
190+
---@return any
179191
---@return boolean
180192
function debug.getuservalue(u, n) end
181193

@@ -304,9 +316,10 @@ function debug.traceback(thread, message, level) end
304316
--- access a same external local variable) will return identical ids for those
305317
--- upvalue indices.
306318
---@version >5.2, JIT
307-
---@param f fun():integer
319+
---@param f function
308320
---@param n integer
309-
---@return integer
321+
---@return lightuserdata id
322+
---@nodiscard
310323
function debug.upvalueid(f, n) end
311324

312325

crates/emmylua_code_analysis/resources/std/global.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,11 @@ function ipairs(t) end
150150
---
151151
--- Lua does not check the consistency of binary chunks. Maliciously crafted
152152
--- binary chunks can crash the interpreter.
153-
---@param chunk (fun():string) | string
153+
---@param chunk (fun(...:any):string) | string
154154
---@param chunkname? string
155155
---@param mode? std.loadmode
156156
---@param env? table
157-
---@return fun():any
157+
---@return fun(...:any):any
158158
---@return string? error_message
159159
---@nodiscard
160160
function load(chunk, chunkname, mode, env) end

crates/emmylua_code_analysis/resources/std/io.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ function io.input(file) end
5555
---@return fun():any
5656
function io.lines(filename, ...) end
5757

58-
---@alias iolib.OpenMode "r" | "w" | "a" | "r+" | "w+" | "a+" | "rb" | "wb" | "ab" | "rb+" | "wb+" | "ab+"
58+
---@alias iolib.OpenMode "r" | "w" | "a" | "r+" | "w+" | "a+" | "rb" | "wb" | "ab" | "rb+" | "wb+" | "ab+" | "r+b" | "w+b" | "a+b"
5959
---
6060
--- This function opens a file, in the mode specified in the string `mode`. In
6161
--- case of success, it returns a new file handle. The `mode` string can be

crates/emmylua_code_analysis/resources/std/math.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,8 @@ function math.tointeger(x) end
194194
---
195195
--- Returns "`integer`" if `x` is an integer, "`float`" if it is a float, or
196196
--- **nil** if `x` is not a number.
197-
---@param x number
198-
---@return 'integer'|'float'|nil
197+
---@param x any
198+
---@return 'integer'|'float'|'nil'
199199
function math.type(x) end
200200

201201
---@version >5.3

crates/emmylua_code_analysis/resources/std/string.lua

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -190,11 +190,12 @@ function string.gmatch(s, pattern) end
190190
--- `local t = {name="lua", version="5.3"}`
191191
--- `x = string.gsub("$name-$version.tar.gz", "%$(%w+)", t)`
192192
--- > x="lua-5.3.tar.gz"
193-
---@param s string
194-
---@param pattern string
195-
---@param repl string|fun(param:string)
193+
---@param s string|number
194+
---@param pattern string|number
195+
---@param repl string|number|table|fun(param:string)
196196
---@param n? integer
197-
---@return string, integer
197+
---@return string
198+
---@return integer count
198199
function string.gsub(s, pattern, repl, n) end
199200

200201
---
@@ -289,7 +290,8 @@ function string.sub(s, i, j) end
289290
---@param fmt string
290291
---@param s string
291292
---@param pos? integer
292-
---@return string
293+
---@return any ...
294+
---@return integer offset
293295
function string.unpack(fmt, s, pos) end
294296

295297
---

crates/emmylua_code_analysis/resources/std/table.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ function table.sort(list, comp) end
107107
--- return `list[i]`, `list[i+1]`, `···`, `list[j]`
108108
--- By default, i is 1 and j is #list.
109109
---@generic T
110-
---@param list [T...] | table<any, T>
110+
---@param list [T...] | T[] | table<any, T>
111111
---@param i? integer
112112
---@param j? integer
113113
---@return T...

crates/emmylua_code_analysis/src/compilation/analyzer/flow/mod.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ fn analyze_flow(
5959
}
6060
}
6161
}
62-
62+
let last_flow_id = var_trace.get_current_flow_id();
6363
let mut guard_count = 0;
6464
while var_trace.has_unresolve_traces() {
6565
resolve_flow_analyze(db, &mut var_trace);
@@ -68,6 +68,9 @@ fn analyze_flow(
6868
break;
6969
}
7070
}
71+
if let Some(last_flow_id) = last_flow_id {
72+
var_trace.set_current_flow_id(last_flow_id);
73+
}
7174
}
7275

7376
for (_, var_trace) in var_trace_map {
@@ -79,11 +82,12 @@ fn analyze_flow(
7982
fn resolve_flow_analyze(db: &mut DbIndex, var_trace: &mut VarTrace) -> Option<()> {
8083
let all_trace = var_trace.pop_all_unresolve_traces();
8184
for (trace_id, uresolve_trace_info) in all_trace {
85+
var_trace.set_current_flow_id(uresolve_trace_info.0);
8286
match trace_id {
8387
UnResolveTraceId::Expr(expr) => {
8488
let binary_expr = expr.get_parent::<LuaBinaryExpr>()?;
8589
let op = binary_expr.get_op_token()?.get_op();
86-
let trace_info = uresolve_trace_info.get_trace_info()?;
90+
let trace_info = uresolve_trace_info.1.get_trace_info()?;
8791
if op == BinaryOperator::OpAnd || op == BinaryOperator::OpOr {
8892
broadcast_up(
8993
db,
@@ -99,6 +103,7 @@ fn resolve_flow_analyze(db: &mut DbIndex, var_trace: &mut VarTrace) -> Option<()
99103
}
100104
UnResolveTraceId::If(if_stat) => {
101105
let asserts = uresolve_trace_info
106+
.1
102107
.get_trace_infos()?
103108
.into_iter()
104109
.map(|trace_info| trace_info.type_assertion.clone())

crates/emmylua_code_analysis/src/compilation/analyzer/flow/var_analyze/broadcast_up.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ pub fn broadcast_up_and(
210210
} else {
211211
let left_id = UnResolveTraceId::Expr(left);
212212
if let Some(left_unresolve_trace_info) = var_trace.pop_unresolve_trace(&left_id) {
213-
let left_trace_info = left_unresolve_trace_info.get_trace_info()?;
213+
let left_trace_info = left_unresolve_trace_info.1.get_trace_info()?;
214214
let new_assert = left_trace_info
215215
.type_assertion
216216
.and_assert(trace_info.type_assertion.clone());
@@ -260,7 +260,7 @@ pub fn broadcast_up_or(
260260
} else {
261261
let left_id = UnResolveTraceId::Expr(left);
262262
if let Some(left_unresolve_trace_info) = var_trace.pop_unresolve_trace(&left_id) {
263-
let left_trace_info = left_unresolve_trace_info.get_trace_info()?;
263+
let left_trace_info = left_unresolve_trace_info.1.get_trace_info()?;
264264
let new_assert = left_trace_info
265265
.type_assertion
266266
.or_assert(trace_info.type_assertion.clone());

0 commit comments

Comments
 (0)