Skip to content

Commit 6752e17

Browse files
authored
Merge pull request #1113 from xuhuanzy/update
update
2 parents a608be6 + 291c98f commit 6752e17

209 files changed

Lines changed: 11026 additions & 5282 deletions

File tree

Some content is hidden

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

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ jobs:
5858
- name: Install Rust toolchain
5959
uses: dtolnay/rust-toolchain@stable
6060
- name: Run Tests
61-
run: cargo test --workspace --features emmylua_ls/full-test
61+
run: cargo test --workspace --all-features
6262

6363
check-schema:
6464
name: Check schema generation

CHANGELOG.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,34 @@
33
*All notable changes to the EmmyLua Analyzer Rust project will be documented in this file.*
44

55
## [0.24.0] - Unreleased
6+
7+
### ✨ Added
8+
69
- **Support LuaJIT-Ext**: Added support for LuaJIT‑Ext syntax, including compound assignment operators, null‑safe navigation, the null‑coalescing operator, constant variables, and the continue statement.
710

811
- **Support LuaJIT3**: Besides LuaJIT‑Ext syntax, named variadic arguments and integer division are also supported.
912

13+
- **Support const generic parameters**: Added the `const T` syntax for generics, for example `---@generic const T`.
14+
15+
- **emmylua_check severity filter**: Added the `--severity` option to filter diagnostic output by minimum severity.
16+
17+
### ⚠️ Deprecated
18+
19+
- **std.ConstTpl**: Marked `std.ConstTpl` as deprecated. Use the new `const T` generic syntax instead.
20+
21+
### 🔧 Changed
22+
23+
- **Rename table field optimization**: `lsp_optimization("skip_table_fields_check")` is now the documented name for skipping table field diagnostics. The old `check_table_field` name remains supported as a compatibility alias.
24+
- **Refactor hover signature**: Refactored signature rendering in hover.
25+
26+
### 🗑️ Removed
27+
28+
- **`---@attribute` tag**: Removed the `---@attribute` tag. Attribute definitions now use C#-like class definitions:
29+
```lua
30+
---@class NewAttribute: Attribute
31+
---@overload fun(args)
32+
```
33+
1034
## [0.23.2] - 2026-6-3
1135

1236
- **Fix some stuck loading issue**: Fixed some issue that cause the language server stuck at loading workspace, and improve the loading performance of large workspace

crates/emmylua_check/README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,13 @@ Output diagnostics in JSON format to a file for further processing:
7373
emmylua_check . -f json --output ./diag.json
7474
```
7575

76+
#### Filter by Severity
77+
78+
Only output warnings and errors:
79+
```shell
80+
emmylua_check . --severity warn
81+
```
82+
7683
---
7784

7885
## ⚙️ Configuration
@@ -130,9 +137,10 @@ Arguments:
130137
Options:
131138
-c, --config <CONFIG> Path to configuration file. If not provided, ".emmyrc.json" and ".luarc.json" will be searched in the workspace directory
132139
-i, --ignore <IGNORE> Comma-separated list of ignore patterns. Patterns must follow glob syntax
133-
-f, --output-format <OUTPUT_FORMAT> Specify output format [default: text] [possible values: json, text]
140+
-f, --output-format <OUTPUT_FORMAT> Specify output format [default: text] [possible values: json, text, sarif]
134141
--output <OUTPUT> Specify output target (stdout or file path, only used when output_format is json) [default: stdout]
135142
--warnings-as-errors Treat warnings as errors
143+
--severity <SEVERITY> Only output diagnostics at this severity or above [possible values: error, warn, info, hint]
136144
--verbose Verbose output
137145
-h, --help Print help information
138146
-V, --version Print version information

crates/emmylua_check/src/cmd_args.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#[cfg(feature = "cli")]
22
use clap::{Parser, ValueEnum};
33

4+
use lsp_types::DiagnosticSeverity;
45
use std::path::PathBuf;
56

67
#[allow(unused)]
@@ -44,6 +45,10 @@ pub struct CmdArgs {
4445
#[cfg_attr(feature = "cli", arg(long))]
4546
pub warnings_as_errors: bool,
4647

48+
/// Only output diagnostics at this severity or above
49+
#[cfg_attr(feature = "cli", arg(long, value_enum, ignore_case = true))]
50+
pub severity: Option<DiagnosticSeverityFilter>,
51+
4752
/// Verbose output
4853
#[cfg_attr(feature = "cli", arg(long))]
4954
pub verbose: bool,
@@ -57,6 +62,35 @@ pub enum OutputFormat {
5762
Sarif,
5863
}
5964

65+
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
66+
#[cfg_attr(feature = "cli", derive(ValueEnum))]
67+
pub enum DiagnosticSeverityFilter {
68+
Error,
69+
Warn,
70+
Info,
71+
Hint,
72+
}
73+
74+
impl DiagnosticSeverityFilter {
75+
pub fn allows(self, severity: Option<DiagnosticSeverity>) -> bool {
76+
match severity {
77+
Some(severity) => severity <= self.into(),
78+
None => false,
79+
}
80+
}
81+
}
82+
83+
impl From<DiagnosticSeverityFilter> for DiagnosticSeverity {
84+
fn from(value: DiagnosticSeverityFilter) -> Self {
85+
match value {
86+
DiagnosticSeverityFilter::Error => DiagnosticSeverity::ERROR,
87+
DiagnosticSeverityFilter::Warn => DiagnosticSeverity::WARNING,
88+
DiagnosticSeverityFilter::Info => DiagnosticSeverity::INFORMATION,
89+
DiagnosticSeverityFilter::Hint => DiagnosticSeverity::HINT,
90+
}
91+
}
92+
}
93+
6094
#[allow(unused)]
6195
#[derive(Debug, Clone)]
6296
pub enum OutputDestination {

crates/emmylua_check/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ pub async fn run_check(cmd_args: CmdArgs) -> Result<(), Box<dyn Error + Sync + S
7474
cmd_args.output_format,
7575
cmd_args.output,
7676
cmd_args.warnings_as_errors,
77+
cmd_args.severity,
7778
)
7879
.await;
7980

crates/emmylua_check/src/output/mod.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use emmylua_code_analysis::{DbIndex, FileId};
88
use lsp_types::Diagnostic;
99
use tokio::sync::mpsc::Receiver;
1010

11-
use crate::cmd_args::{OutputDestination, OutputFormat};
11+
use crate::cmd_args::{DiagnosticSeverityFilter, OutputDestination, OutputFormat};
1212

1313
use crate::terminal_display::TerminalDisplay;
1414

@@ -23,6 +23,7 @@ pub async fn output_result(
2323
output_format: OutputFormat,
2424
output: OutputDestination,
2525
warnings_as_errors: bool,
26+
severity_filter: Option<DiagnosticSeverityFilter>,
2627
) -> i32 {
2728
let mut writer: Box<dyn OutputWriter> = match output_format {
2829
OutputFormat::Json => Box::new(json_output_writer::JsonOutputWriter::new(output)),
@@ -42,7 +43,11 @@ pub async fn output_result(
4243

4344
while let Some((file_id, diagnostics)) = receiver.recv().await {
4445
count += 1;
45-
if let Some(diagnostics) = diagnostics {
46+
if let Some(mut diagnostics) = diagnostics {
47+
if let Some(severity_filter) = severity_filter {
48+
diagnostics.retain(|diagnostic| severity_filter.allows(diagnostic.severity));
49+
}
50+
4651
for diagnostic in &diagnostics {
4752
match diagnostic.severity {
4853
Some(lsp_types::DiagnosticSeverity::ERROR) => {

crates/emmylua_code_analysis/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ hashbrown.workspace = true
5757
[features]
5858
default = []
5959
reqwest = ["dep:reqwest"]
60+
slow-tests = []
6061

6162
[package.metadata.i18n]
6263
available-locales = ["en", "zh_CN", "zh_HK"]

crates/emmylua_code_analysis/resources/std/builtin.lua

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,8 @@
128128
--- built-in type for Rawget
129129
--- @alias std.RawGet<T, K> unknown
130130

131+
--- built-in type for generic template, for match integer const and `true`/`false`
131132
--- @deprecated use `const T` as a replacement, for example `---@generic const T`.
132-
---
133-
--- built-in type for generic template, for match integer const and true/false
134133
--- @alias std.ConstTpl<T> unknown
135134

136135
--- compact luals
@@ -171,24 +170,29 @@
171170

172171
--- attribute
173172

173+
--- @class Attribute
174+
174175
---
175176
--- Deprecated. Receives an optional message parameter.
176-
--- @attribute deprecated(message: string?)
177+
--- @class deprecated: Attribute
178+
--- @overload fun(message?: string)
177179

178180
---
179181
--- Language Server Optimization Items.
180182
---
181183
--- Parameters:
182-
--- - `check_table_field`: Skip the assign check for table fields. It is recommended to use this option for all large configuration tables.
184+
--- - `skip_table_fields_check`: Skip table field diagnostics. It is recommended to use this option for all large configuration tables.
183185
--- - `delayed_definition`: Indicates that the type of the variable is determined by the first assignment.
184186
--- Only valid for `local` declarations with no initial value.
185-
--- @attribute lsp_optimization(code: "check_table_field"|"delayed_definition")
187+
--- @class lsp_optimization: Attribute
188+
--- @overload fun(code: "skip_table_fields_check"|"delayed_definition")
186189

187190
---
188191
--- Index field alias, will be displayed in `hint` and `completion`.
189192
---
190193
--- Receives a string parameter for the alias name.
191-
--- @attribute index_alias(name: string)
194+
--- @class index_alias: Attribute
195+
--- @overload fun(name: string)
192196

193197
---
194198
--- This attribute must be applied to function parameters, and the function parameter's type must be a string template generic,
@@ -201,7 +205,8 @@
201205
--- - `return_mode`: Constructor return strategy. `"self"` forces `self`, `"doc"` uses the documented return type,
202206
--- and `"default"` prefers the documented return type and falls back to `self`.
203207
--- Defaults to `"default"`
204-
--- @attribute constructor(name: string, root_class: string?, strip_self: boolean?, return_mode: "self"|"doc"|"default"?)
208+
--- @class constructor: Attribute
209+
--- @overload fun(name: string, root_class?: string, strip_self?: boolean, return_mode?: "self"|"doc"|"default")
205210

206211
---
207212
--- Associates `getter` and `setter` methods with a field. Currently provides only definition navigation functionality,
@@ -211,4 +216,5 @@
211216
--- - `convention`: Naming convention, defaults to `camelCase`. Implicitly adds `get` and `set` prefixes. eg: `_age` -> `getAge`, `setAge`.
212217
--- - `getter`: Getter method name. Takes precedence over `convention`.
213218
--- - `setter`: Setter method name. Takes precedence over `convention`.
214-
--- @attribute field_accessor(convention: "camelCase"|"PascalCase"|"snake_case"|nil, getter: string?, setter: string?)
219+
--- @class field_accessor: Attribute
220+
--- @overload fun(convention?: "camelCase"|"PascalCase"|"snake_case", getter?: string, setter?: string)

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

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use emmylua_parser::{
2-
LuaAstNode, LuaAstToken, LuaComment, LuaDocTag, LuaDocTagAlias, LuaDocTagAttribute,
3-
LuaDocTagClass, LuaDocTagEnum, LuaDocTagMeta, LuaDocTagNamespace, LuaDocTagUsing,
4-
LuaDocTypeFlag,
2+
LuaAstNode, LuaAstToken, LuaComment, LuaDocTag, LuaDocTagAlias, LuaDocTagClass, LuaDocTagEnum,
3+
LuaDocTagMeta, LuaDocTagNamespace, LuaDocTagUsing, LuaDocTypeFlag,
54
};
65
use flagset::FlagSet;
76
use rowan::TextRange;
@@ -62,8 +61,8 @@ fn get_type_flag_value(
6261
"internal" => {
6362
attr |= LuaTypeFlag::Internal;
6463
}
65-
"private" => {
66-
attr |= LuaTypeFlag::Private;
64+
"private" | "file" => {
65+
attr |= LuaTypeFlag::File;
6766
}
6867
_ => {}
6968
}
@@ -100,24 +99,6 @@ pub fn analyze_doc_tag_alias(analyzer: &mut DeclAnalyzer, alias: LuaDocTagAlias)
10099
Some(())
101100
}
102101

103-
pub fn analyze_doc_tag_attribute(
104-
analyzer: &mut DeclAnalyzer,
105-
attribute: LuaDocTagAttribute,
106-
) -> Option<()> {
107-
let name_token = attribute.get_name_token()?;
108-
let name = name_token.get_name_text().to_string();
109-
let range = name_token.syntax().text_range();
110-
111-
add_type_decl(
112-
analyzer,
113-
&name,
114-
range,
115-
LuaDeclTypeKind::Attribute,
116-
FlagSet::default(),
117-
);
118-
Some(())
119-
}
120-
121102
pub fn analyze_doc_tag_namespace(
122103
analyzer: &mut DeclAnalyzer,
123104
namespace: LuaDocTagNamespace,
@@ -218,8 +199,8 @@ fn add_type_decl(
218199
let full_name = option_namespace
219200
.map(|ns| format!("{}.{}", ns, basic_name))
220201
.unwrap_or(basic_name.to_string());
221-
let id = if flag.contains(LuaTypeFlag::Private) {
222-
LuaTypeDeclId::local(file_id, &full_name)
202+
let id = if flag.contains(LuaTypeFlag::File) {
203+
LuaTypeDeclId::file(file_id, &full_name)
223204
} else if flag.contains(LuaTypeFlag::Internal) {
224205
LuaTypeDeclId::internal(workspace_id, &full_name)
225206
} else {

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,6 @@ fn walk_node_enter(analyzer: &mut DeclAnalyzer, node: LuaAst) {
107107
LuaAst::LuaDocTagAlias(doc_tag) => {
108108
docs::analyze_doc_tag_alias(analyzer, doc_tag);
109109
}
110-
LuaAst::LuaDocTagAttribute(doc_tag) => {
111-
docs::analyze_doc_tag_attribute(analyzer, doc_tag);
112-
}
113110
LuaAst::LuaDocTagNamespace(doc_tag) => {
114111
docs::analyze_doc_tag_namespace(analyzer, doc_tag);
115112
}

0 commit comments

Comments
 (0)