Skip to content

Commit 38f7ec6

Browse files
committed
compact luals config and overload syntax
1 parent 2cd898a commit 38f7ec6

File tree

4 files changed

+48
-21
lines changed

4 files changed

+48
-21
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ jobs:
6060
if: ${{ matrix.cross == 'general-macos-intel' }}
6161
run: |
6262
rustup target add ${{ matrix.target }}
63-
RUSTFLAGS="-C link-args=-mmacos-version-min=10.15" cargo build --release --target ${{ matrix.target }} -p emmylua_ls
63+
cargo build --release --target ${{ matrix.target }} -p emmylua_ls
6464
otool -l ./target/${{ matrix.target }}/release/emmylua_ls | grep -A4 "LC_BUILD_VERSION\|LC_VERSION_MIN_MACOSX"
6565
- name: copy-binary
6666
if: ${{ matrix.os != 'windows-latest' }}

crates/emmylua_code_analysis/src/compilation/analyzer/doc/infer_type.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,15 @@ fn infer_func_type(analyzer: &mut DocAnalyzer, func: LuaDocFuncType) -> LuaType
375375
}
376376
}
377377

378+
// compact luals
379+
if is_colon {
380+
if let Some(first_param) = params_result.first() {
381+
if first_param.0 == "self" {
382+
is_colon = false
383+
}
384+
}
385+
}
386+
378387
LuaType::DocFunction(
379388
LuaFunctionType::new(is_async, is_colon, params_result, return_types).into(),
380389
)

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

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,15 @@ pub(crate) fn analyze(db: &mut DbIndex, context: &mut AnalyzeContext) {
1313
let tree_list = context.tree_list.clone();
1414
// build decl and ref flow chain
1515
for in_filed_tree in &tree_list {
16-
let mut analyzer =
17-
FlowAnalyzer::new(db, in_filed_tree.file_id, in_filed_tree.value.clone());
18-
flow_analyze(&mut analyzer);
16+
flow_analyze(db, in_filed_tree.file_id, in_filed_tree.value.clone());
1917
}
2018
}
2119

22-
fn flow_analyze(analyzer: &mut FlowAnalyzer) -> Option<()> {
23-
let references_index = analyzer.db.get_reference_index();
24-
let refs_map = references_index
25-
.get_decl_references_map(&analyzer.file_id)?
26-
.clone();
27-
let root = analyzer.root.syntax();
28-
let file_id = analyzer.file_id;
20+
fn flow_analyze(db: &mut DbIndex, file_id: FileId, root: LuaChunk) -> Option<()> {
21+
let references_index = db.get_reference_index();
22+
let refs_map = references_index.get_decl_references_map(&file_id)?.clone();
2923

24+
let mut analyzer = FlowAnalyzer::new(db, file_id, root.clone());
3025
for (decl_id, decl_refs) in refs_map {
3126
let mut flow_chains = LuaFlowChain::new(decl_id);
3227

@@ -35,16 +30,18 @@ fn flow_analyze(analyzer: &mut FlowAnalyzer) -> Option<()> {
3530
if !decl_ref.is_write {
3631
let syntax_id =
3732
LuaSyntaxId::new(LuaSyntaxKind::NameExpr.into(), decl_ref.range.clone());
38-
if let Some(name_expr) = LuaNameExpr::cast(syntax_id.to_node_from_root(root)?) {
39-
infer_name_expr(analyzer, &mut flow_chains, name_expr);
33+
if let Some(name_expr) =
34+
LuaNameExpr::cast(syntax_id.to_node_from_root(root.syntax())?)
35+
{
36+
infer_name_expr(&mut analyzer, &mut flow_chains, name_expr);
4037
}
4138
} else {
4239
need_assign_infer = true;
4340
}
4441
}
4542

4643
if need_assign_infer {
47-
infer_from_assign_stats(analyzer, &mut flow_chains, decl_refs.iter().collect());
44+
infer_from_assign_stats(&mut analyzer, &mut flow_chains, decl_refs.iter().collect());
4845
}
4946

5047
analyzer

crates/emmylua_code_analysis/src/config/configs/runtime.rs

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,25 +34,25 @@ impl Default for EmmyrcRuntime {
3434
}
3535
}
3636

37-
#[derive(Serialize, Deserialize, Debug, JsonSchema, Clone, Copy)]
37+
#[derive(Serialize, Deserialize, Debug, JsonSchema, Clone, Copy, PartialEq, Eq)]
3838
pub enum EmmyrcLuaVersion {
3939
/// Lua 5.1
40-
#[serde(rename = "Lua5.1")]
40+
#[serde(rename = "Lua5.1", alias = "Lua 5.1")]
4141
Lua51,
4242
/// LuaJIT
4343
#[serde(rename = "LuaJIT")]
4444
LuaJIT,
4545
/// Lua 5.2
46-
#[serde(rename = "Lua5.2")]
46+
#[serde(rename = "Lua5.2", alias = "Lua 5.2")]
4747
Lua52,
4848
/// Lua 5.3
49-
#[serde(rename = "Lua5.3")]
49+
#[serde(rename = "Lua5.3", alias = "Lua 5.3")]
5050
Lua53,
5151
/// Lua 5.4
52-
#[serde(rename = "Lua5.4")]
52+
#[serde(rename = "Lua5.4", alias = "Lua 5.4")]
5353
Lua54,
54-
/// Lua 5.4
55-
#[serde(rename = "LuaLatest")]
54+
/// Lua Latest
55+
#[serde(rename = "LuaLatest", alias = "Lua Latest")]
5656
LuaLatest,
5757
}
5858

@@ -73,4 +73,25 @@ impl EmmyrcLuaVersion {
7373
EmmyrcLuaVersion::LuaLatest => LuaVersionNumber::new(5, 4, 0),
7474
}
7575
}
76+
}
77+
78+
#[cfg(test)]
79+
mod tests {
80+
use super::*;
81+
82+
#[test]
83+
fn test_emmyrc_runtime() {
84+
let json1 = r#"{
85+
"version": "Lua5.1"
86+
}"#;
87+
let runtime: EmmyrcRuntime = serde_json::from_str(json1).unwrap();
88+
assert_eq!(runtime.version, EmmyrcLuaVersion::Lua51);
89+
90+
let json2 = r#"{
91+
"version": "Lua 5.1"
92+
}"#;
93+
94+
let runtime: EmmyrcRuntime = serde_json::from_str(json2).unwrap();
95+
assert_eq!(runtime.version, EmmyrcLuaVersion::Lua51);
96+
}
7697
}

0 commit comments

Comments
 (0)