Skip to content

Commit 0c19747

Browse files
committed
feat(ls): validate the rule name validation regex and show an error message if incorrect.
1 parent 77ba14b commit 0c19747

File tree

4 files changed

+20
-5
lines changed

4 files changed

+20
-5
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ls/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ default = ["full-compiler"]
3737
bitflags = { workspace = true }
3838
dashmap = { version = "6.1.0" }
3939
futures = "0.3.31"
40+
regex = { workspace = true }
4041
tracing = { version = "0.1.44", optional = true }
4142
tracing-subscriber = { version = "0.3.22", optional = true }
4243
itertools = { workspace = true}

ls/editors/code/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@
103103
"YARA.ruleNameValidation": {
104104
"type": "string",
105105
"default": "",
106-
"description": "A regular expression that all rule names must match."
106+
"description": "A regular expression that all rule names must match (example: APT_.*)."
107107
}
108108
}
109109
},

ls/src/server.rs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ use async_lsp::lsp_types::{
2424
DocumentSymbolResponse, FullDocumentDiagnosticReport,
2525
GotoDefinitionParams, GotoDefinitionResponse, Hover, HoverParams,
2626
HoverProviderCapability, InitializeParams, InitializeResult, Location,
27-
OneOf, PublishDiagnosticsParams, ReferenceParams,
27+
MessageType, OneOf, PublishDiagnosticsParams, ReferenceParams,
2828
RelatedFullDocumentDiagnosticReport, RenameParams, SaveOptions,
2929
SelectionRange, SelectionRangeParams, SelectionRangeProviderCapability,
3030
SemanticTokensFullOptions, SemanticTokensLegend, SemanticTokensOptions,
3131
SemanticTokensRangeResult, SemanticTokensResult,
32-
SemanticTokensServerCapabilities, ServerCapabilities,
32+
SemanticTokensServerCapabilities, ServerCapabilities, ShowMessageParams,
3333
TextDocumentSyncCapability, TextDocumentSyncKind, TextDocumentSyncOptions,
3434
TextDocumentSyncSaveOptions, TextEdit, Url, WorkspaceEdit,
3535
};
@@ -553,7 +553,7 @@ impl YARALanguageServer {
553553
mut client: ClientSocket,
554554
scope_uri: Url,
555555
) -> Settings {
556-
client
556+
let settings = client
557557
.configuration(ConfigurationParams {
558558
items: vec![
559559
ConfigurationItem {
@@ -583,7 +583,20 @@ impl YARALanguageServer {
583583

584584
Settings { metadata_validation, rule_name_validation }
585585
})
586-
.unwrap_or_default()
586+
.unwrap_or_default();
587+
588+
if let Some(re) = &settings.rule_name_validation {
589+
if regex::Regex::new(re).is_err() {
590+
let _ = client.show_message(ShowMessageParams {
591+
typ: MessageType::ERROR,
592+
message: format!(
593+
"YARA: wrong rule name validation regex: {re}"
594+
),
595+
});
596+
}
597+
}
598+
599+
settings
587600
}
588601

589602
/// Sends diagnostics for specific document if publish model is used.

0 commit comments

Comments
 (0)