Skip to content

Commit c7b0301

Browse files
authored
Merge pull request #539 from xuhuanzy/update
update
2 parents c10aa11 + 4b39f83 commit c7b0301

File tree

120 files changed

+5017
-1214
lines changed

Some content is hidden

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

120 files changed

+5017
-1214
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
/target
22
.idea
3-
dhat-heap.json
3+
.cursor
4+
dhat-heap.json

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
local a = {}
1818
```
1919

20+
### 🔧 Changed
21+
- **Class Method Completion**: When a function call jumps, if there are multiple declarations, It will then attempt to return the most matching definition along with all actual code declarations, rather than returning all definitions.
2022

2123
### 🐛 Fixed
2224
- **Enum Variable Parameter Issue**: Fixed a crash issue when checking enum variable as parameter

crates/emmylua_code_analysis/locales/lint.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,4 +252,12 @@ Cannot use `...` outside a vararg function.:
252252
"the string template type must be a string constant":
253253
en: "the string template type must be a string constant"
254254
zh_CN: "字符串模板类型必须是字符串常量"
255-
zh_HK: "字串模板類型必須是字串常量"
255+
zh_HK: "字串模板類型必須是字串常量"
256+
"Cannot cast `%{original}` to `%{target}`. %{reason}":
257+
en: "Cannot cast `%{original}` to `%{target}`. %{reason}"
258+
zh_CN: "不能将 `%{original}` 转换为 `%{target}`。%{reason}"
259+
zh_HK: "不能將 `%{original}` 轉換為 `%{target}`。%{reason}"
260+
"type recursion":
261+
en: "type recursion"
262+
zh_CN: "类型递归"
263+
zh_HK: "類型遞歸"

crates/emmylua_code_analysis/resources/schema.json

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
"autoRequireFunction": "require",
3636
"autoRequireNamingConvention": "keep",
3737
"autoRequireSeparator": ".",
38+
"baseFunctionIncludesName": true,
3839
"callSnippet": false,
3940
"enable": true,
4041
"postfix": "@"
@@ -76,6 +77,7 @@
7677
"enable": true,
7778
"indexHint": true,
7879
"localHint": true,
80+
"metaCallHint": true,
7981
"overrideHint": true,
8082
"paramHint": true
8183
},
@@ -95,6 +97,16 @@
9597
}
9698
]
9799
},
100+
"inlineValues": {
101+
"default": {
102+
"enable": true
103+
},
104+
"allOf": [
105+
{
106+
"$ref": "#/definitions/EmmyrcInlineValues"
107+
}
108+
]
109+
},
98110
"references": {
99111
"default": {
100112
"enable": true,
@@ -511,6 +523,13 @@
511523
"enum": [
512524
"generic-constraint-mismatch"
513525
]
526+
},
527+
{
528+
"description": "cast-type-mismatch",
529+
"type": "string",
530+
"enum": [
531+
"cast-type-mismatch"
532+
]
514533
}
515534
]
516535
},
@@ -594,6 +613,11 @@
594613
"default": ".",
595614
"type": "string"
596615
},
616+
"baseFunctionIncludesName": {
617+
"description": "Whether to include the name in the base function completion. effect: `function () end` -> `function name() end`.",
618+
"default": true,
619+
"type": "boolean"
620+
},
597621
"callSnippet": {
598622
"description": "Whether to use call snippets in completions.",
599623
"default": false,
@@ -710,6 +734,13 @@
710734
"enum": [
711735
"camel-case"
712736
]
737+
},
738+
{
739+
"description": "When returning class definition, use class name, otherwise keep original name.",
740+
"type": "string",
741+
"enum": [
742+
"keep-class"
743+
]
713744
}
714745
]
715746
},
@@ -741,6 +772,11 @@
741772
"default": true,
742773
"type": "boolean"
743774
},
775+
"metaCallHint": {
776+
"description": "Whether to enable meta __call operator hints.",
777+
"default": true,
778+
"type": "boolean"
779+
},
744780
"overrideHint": {
745781
"description": "Whether to enable override hints.",
746782
"default": true,
@@ -753,6 +789,16 @@
753789
}
754790
}
755791
},
792+
"EmmyrcInlineValues": {
793+
"type": "object",
794+
"properties": {
795+
"enable": {
796+
"description": "Whether to enable inline values.",
797+
"default": true,
798+
"type": "boolean"
799+
}
800+
}
801+
},
756802
"EmmyrcLuaVersion": {
757803
"oneOf": [
758804
{

crates/emmylua_code_analysis/src/compilation/analyzer/decl/exprs.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use emmylua_parser::{
2-
LuaAst, LuaAstNode, LuaAstToken, LuaCallExpr, LuaClosureExpr, LuaExpr, LuaIndexExpr,
3-
LuaIndexKey, LuaLiteralExpr, LuaLiteralToken, LuaNameExpr, LuaTableExpr, LuaVarExpr,
2+
LuaAst, LuaAstNode, LuaAstToken, LuaCallExpr, LuaClosureExpr, LuaDocTagCast, LuaExpr,
3+
LuaIndexExpr, LuaIndexKey, LuaLiteralExpr, LuaLiteralToken, LuaNameExpr, LuaTableExpr,
4+
LuaVarExpr,
45
};
56

67
use crate::{
@@ -50,6 +51,9 @@ pub fn analyze_name_expr(analyzer: &mut DeclAnalyzer, expr: LuaNameExpr) -> Opti
5051
}
5152

5253
pub fn analyze_index_expr(analyzer: &mut DeclAnalyzer, index_expr: LuaIndexExpr) -> Option<()> {
54+
if index_expr.ancestors::<LuaDocTagCast>().next().is_some() {
55+
return Some(());
56+
}
5357
let index_key = index_expr.get_index_key()?;
5458
let key = match index_key {
5559
LuaIndexKey::Name(name) => LuaMemberKey::Name(name.get_name_text().to_string().into()),

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ pub fn analyze_field(analyzer: &mut DocAnalyzer, tag: LuaDocTagField) -> Option<
6666
for desc in tag.get_descriptions() {
6767
let mut desc_text = desc.get_description_text().to_string();
6868
if !desc_text.is_empty() {
69-
let text = preprocess_description(&mut desc_text);
69+
let text = preprocess_description(&mut desc_text, Some(&property_owner));
7070
if !description.is_empty() {
7171
description.push_str("\n\n");
7272
}

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
use std::sync::Arc;
22

33
use emmylua_parser::{
4-
LuaAst, LuaAstNode, LuaDocBinaryType, LuaDocFuncType, LuaDocGenericType,
5-
LuaDocMultiLineUnionType, LuaDocObjectFieldKey, LuaDocObjectType, LuaDocStrTplType, LuaDocType,
6-
LuaDocUnaryType, LuaDocVariadicType, LuaLiteralToken, LuaSyntaxKind, LuaTypeBinaryOperator,
7-
LuaTypeUnaryOperator, LuaVarExpr,
4+
LuaAst, LuaAstNode, LuaDocBinaryType, LuaDocDescriptionOwner, LuaDocFuncType,
5+
LuaDocGenericType, LuaDocMultiLineUnionType, LuaDocObjectFieldKey, LuaDocObjectType,
6+
LuaDocStrTplType, LuaDocType, LuaDocUnaryType, LuaDocVariadicType, LuaLiteralToken,
7+
LuaSyntaxKind, LuaTypeBinaryOperator, LuaTypeUnaryOperator, LuaVarExpr,
88
};
99
use rowan::TextRange;
1010
use smol_str::SmolStr;
@@ -588,7 +588,8 @@ fn infer_multi_line_union_type(
588588
};
589589

590590
let description = if let Some(description) = field.get_description() {
591-
let description_text = preprocess_description(&description.get_description_text());
591+
let description_text =
592+
preprocess_description(&description.get_description_text(), None);
592593
if !description_text.is_empty() {
593594
Some(description_text)
594595
} else {

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

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use super::AnalyzeContext;
1111
use crate::{
1212
db_index::{DbIndex, LuaTypeDeclId},
1313
profile::Profile,
14-
FileId,
14+
FileId, LuaSemanticDeclId,
1515
};
1616
use emmylua_parser::{LuaAstNode, LuaComment, LuaSyntaxNode};
1717
use file_generic_index::FileGenericIndex;
@@ -44,8 +44,10 @@ fn analyze_comment(analyzer: &mut DocAnalyzer) -> Option<()> {
4444
}
4545

4646
let owenr = get_owner_id(analyzer)?;
47-
let comment_description =
48-
preprocess_description(&comment.get_description()?.get_description_text());
47+
let comment_description = preprocess_description(
48+
&comment.get_description()?.get_description_text(),
49+
Some(&owenr),
50+
);
4951
analyzer.db.get_property_index_mut().add_description(
5052
analyzer.file_id,
5153
owenr,
@@ -90,9 +92,16 @@ impl<'a> DocAnalyzer<'a> {
9092
}
9193
}
9294

93-
pub fn preprocess_description(mut description: &str) -> String {
94-
if description.starts_with(['#', '@']) {
95-
description = description.trim_start_matches(|c| c == '#' || c == '@');
95+
pub fn preprocess_description(mut description: &str, owner: Option<&LuaSemanticDeclId>) -> String {
96+
let has_remove_start_char = if let Some(owner) = owner {
97+
!matches!(owner, LuaSemanticDeclId::Signature(_))
98+
} else {
99+
true
100+
};
101+
if has_remove_start_char {
102+
if description.starts_with(['#', '@']) {
103+
description = description.trim_start_matches(|c| c == '#' || c == '@');
104+
}
96105
}
97106

98107
let mut result = String::new();

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,16 @@ fn add_description_for_type_decl(
7474
) {
7575
let mut description_text = String::new();
7676

77+
// let comment = analyzer.comment.clone();
78+
// if let Some(description) = comment.get_description() {
79+
// let description = preprocess_description(&description.get_description_text(), None);
80+
// if !description.is_empty() {
81+
// description_text.push_str(&description);
82+
// }
83+
// }
84+
7785
for description in descriptions {
78-
let description = preprocess_description(&description.get_description_text());
86+
let description = preprocess_description(&description.get_description_text(), None);
7987
if !description.is_empty() {
8088
if !description_text.is_empty() {
8189
description_text.push_str("\n\n");

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ pub fn analyze_param(analyzer: &mut DocAnalyzer, tag: LuaDocTagParam) -> Option<
116116
}
117117

118118
let description = if let Some(des) = tag.get_description() {
119-
Some(preprocess_description(&des.get_description_text()))
119+
Some(preprocess_description(&des.get_description_text(), None))
120120
} else {
121121
None
122122
};
@@ -155,7 +155,7 @@ pub fn analyze_param(analyzer: &mut DocAnalyzer, tag: LuaDocTagParam) -> Option<
155155

156156
pub fn analyze_return(analyzer: &mut DocAnalyzer, tag: LuaDocTagReturn) -> Option<()> {
157157
let description = if let Some(des) = tag.get_description() {
158-
Some(preprocess_description(&des.get_description_text()))
158+
Some(preprocess_description(&des.get_description_text(), None))
159159
} else {
160160
None
161161
};
@@ -383,7 +383,7 @@ pub fn analyze_other(analyzer: &mut DocAnalyzer, other: LuaDocTagOther) -> Optio
383383
let owner = get_owner_id(analyzer)?;
384384
let tag_name = other.get_tag_name()?;
385385
let description = if let Some(des) = other.get_description() {
386-
let description = preprocess_description(&des.get_description_text());
386+
let description = preprocess_description(&des.get_description_text(), None);
387387
format!("@*{}* {}", tag_name, description)
388388
} else {
389389
format!("@*{}*", tag_name)

0 commit comments

Comments
 (0)