on master help sign in
feat(lsp): configurable diagnostic severity (#1325)
0e7d757Matouš Dzivjak
book/src/guides/adding_languages.md+13−12
@@ -27,18 +27,19 @@ directory](../configuration.md).
27
27
28These are the available keys and descriptions for the file.
28These are the available keys and descriptions for the file.
29
29
30−| Key | Description |
30+| Key | Description |
31−| ---- | ----------- |
31+| ---- | ----------- |
32−| name | The name of the language |
32+| name | The name of the language |
33−| scope | A string like `source.js` that identifies the language. Currently, we strive to match the scope names used by popular TextMate grammars and by the Linguist library. Usually `source.<name>` or `text.<name>` in case of markup languages |
33+| scope | A string like `source.js` that identifies the language. Currently, we strive to match the scope names used by popular TextMate grammars and by the Linguist library. Usually `source.<name>` or `text.<name>` in case of markup languages |
34−| injection-regex | regex pattern that will be tested against a language name in order to determine whether this language should be used for a potential [language injection][treesitter-language-injection] site. |
34+| injection-regex | regex pattern that will be tested against a language name in order to determine whether this language should be used for a potential [language injection][treesitter-language-injection] site. |
35−| file-types | The filetypes of the language, for example `["yml", "yaml"]` |
35+| file-types | The filetypes of the language, for example `["yml", "yaml"]` |
36−| shebangs | The interpreters from the shebang line, for example `["sh", "bash"]` |
36+| shebangs | The interpreters from the shebang line, for example `["sh", "bash"]` |
37−| roots | A set of marker files to look for when trying to find the workspace root. For example `Cargo.lock`, `yarn.lock` |
37+| roots | A set of marker files to look for when trying to find the workspace root. For example `Cargo.lock`, `yarn.lock` |
38−| auto-format | Whether to autoformat this language when saving |
38+| auto-format | Whether to autoformat this language when saving |
39+| diagnostic-severity | Minimal severity of diagnostic for it to be displayed. (Allowed values: `Error`, `Warning`, `Info`, `Hint`) |
39−| comment-token | The token to use as a comment-token |
40+| comment-token | The token to use as a comment-token |
40−| indent | The indent to use. Has sub keys `tab-width` and `unit` |
41+| indent | The indent to use. Has sub keys `tab-width` and `unit` |
41−| config | Language server configuration |
42+| config | Language server configuration |
42
43
43## Queries
44## Queries
44
45
book/src/languages.md−1
@@ -11,4 +11,3 @@ Changes made to the `languages.toml` file in a user's [configuration directory](
11name = "rust"
11name = "rust"
12auto-format = false
12auto-format = false
13```
13```
14−
helix-core/src/diagnostic.rs+11−4
@@ -1,12 +1,19 @@
1//! LSP diagnostic utility types.
1//! LSP diagnostic utility types.
2+use serde::{Deserialize, Serialize};
2
3
3/// Describes the severity level of a [`Diagnostic`].
4/// Describes the severity level of a [`Diagnostic`].
4−#[derive(Debug, Clone, Copy, Eq, PartialEq)]
5+#[derive(Debug, Clone, Copy, Eq, PartialEq, PartialOrd, Ord, Deserialize, Serialize)]
5pub enum Severity {
6pub enum Severity {
6− Error,
7− Warning,
8− Info,
9 Hint,
7 Hint,
8+ Info,
9+ Warning,
10+ Error,
11+}
12+
13+impl Default for Severity {
14+ fn default() -> Self {
15+ Self::Hint
16+ }
10}
17}
11
18
12/// A range of `char`s within the text.
19/// A range of `char`s within the text.
helix-core/src/indent.rs+2
@@ -442,6 +442,7 @@ where
442 );
442 );
443
443
444 let doc = Rope::from(doc);
444 let doc = Rope::from(doc);
445+ use crate::diagnostic::Severity;
445 use crate::syntax::{
446 use crate::syntax::{
446 Configuration, IndentationConfiguration, LanguageConfiguration, Loader,
447 Configuration, IndentationConfiguration, LanguageConfiguration, Loader,
447 };
448 };
@@ -459,6 +460,7 @@ where
459 roots: vec![],
460 roots: vec![],
460 comment_token: None,
461 comment_token: None,
461 auto_format: false,
462 auto_format: false,
463+ diagnostic_severity: Severity::Warning,
462 language_server: None,
464 language_server: None,
463 indent: Some(IndentationConfiguration {
465 indent: Some(IndentationConfiguration {
464 tab_width: 4,
466 tab_width: 4,
helix-core/src/syntax.rs+3
@@ -1,5 +1,6 @@
1use crate::{
1use crate::{
2 chars::char_is_line_ending,
2 chars::char_is_line_ending,
3+ diagnostic::Severity,
3 regex::Regex,
4 regex::Regex,
4 transaction::{ChangeSet, Operation},
5 transaction::{ChangeSet, Operation},
5 Rope, RopeSlice, Tendril,
6 Rope, RopeSlice, Tendril,
@@ -63,6 +64,8 @@ pub struct LanguageConfiguration {
63
64
64 #[serde(default)]
65 #[serde(default)]
65 pub auto_format: bool,
66 pub auto_format: bool,
67+ #[serde(default)]
68+ pub diagnostic_severity: Severity,
66
69
67 // content_regex
70 // content_regex
68 #[serde(default, skip_serializing, deserialize_with = "deserialize_regex")]
71 #[serde(default, skip_serializing, deserialize_with = "deserialize_regex")]
helix-term/src/application.rs+22−9
@@ -378,6 +378,7 @@ impl Application {
378 let doc = self.editor.document_by_path_mut(&path);
378 let doc = self.editor.document_by_path_mut(&path);
379
379
380 if let Some(doc) = doc {
380 if let Some(doc) = doc {
381+ let lang_conf = doc.language_config();
381 let text = doc.text();
382 let text = doc.text();
382
383
383 let diagnostics = params
384 let diagnostics = params
@@ -415,19 +416,31 @@ impl Application {
415 return None;
416 return None;
416 };
417 };
417
418
419+ let severity =
420+ diagnostic.severity.map(|severity| match severity {
421+ DiagnosticSeverity::ERROR => Error,
422+ DiagnosticSeverity::WARNING => Warning,
423+ DiagnosticSeverity::INFORMATION => Info,
424+ DiagnosticSeverity::HINT => Hint,
425+ severity => unreachable!(
426+ "unrecognized diagnostic severity: {:?}",
427+ severity
428+ ),
429+ });
430+
431+ if let Some(lang_conf) = lang_conf {
432+ if let Some(severity) = severity {
433+ if severity < lang_conf.diagnostic_severity {
434+ return None;
435+ }
436+ }
437+ };
438+
418 Some(Diagnostic {
439 Some(Diagnostic {
419 range: Range { start, end },
440 range: Range { start, end },
420 line: diagnostic.range.start.line as usize,
441 line: diagnostic.range.start.line as usize,
421 message: diagnostic.message,
442 message: diagnostic.message,
422− severity: diagnostic.severity.map(
443+ severity,
423− |severity| match severity {
424− DiagnosticSeverity::ERROR => Error,
425− DiagnosticSeverity::WARNING => Warning,
426− DiagnosticSeverity::INFORMATION => Info,
427− DiagnosticSeverity::HINT => Hint,
428− severity => unimplemented!("{:?}", severity),
429− },
430− ),
431 // code
444 // code
432 // source
445 // source
433 })
446 })