-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(service): report top-level error tokens
- Loading branch information
Showing
6 changed files
with
76 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
use crate::{files::FilesCtx, helpers, InternUri, LanguageService}; | ||
use line_index::LineIndex; | ||
use lsp_types::{Diagnostic, DiagnosticSeverity, NumberOrString}; | ||
use std::rc::Rc; | ||
use wat_syntax::{SyntaxElement, SyntaxKind, SyntaxNode}; | ||
|
||
const DIAGNOSTIC_CODE: &str = "syntax"; | ||
|
||
pub fn check( | ||
service: &LanguageService, | ||
diags: &mut Vec<Diagnostic>, | ||
uri: InternUri, | ||
line_index: &LineIndex, | ||
root: &SyntaxNode, | ||
) { | ||
let mut errors = Rc::unwrap_or_clone(service.parser_result(uri).1); | ||
diags.append(&mut errors); | ||
diags.extend( | ||
root.children_with_tokens() | ||
.filter_map(|element| match element { | ||
SyntaxElement::Token(token) if token.kind() == SyntaxKind::ERROR => Some(token), | ||
_ => None, | ||
}) | ||
.map(|token| Diagnostic { | ||
range: helpers::rowan_range_to_lsp_range(line_index, token.text_range()), | ||
severity: Some(DiagnosticSeverity::ERROR), | ||
source: Some("wat".into()), | ||
code: Some(NumberOrString::String(DIAGNOSTIC_CODE.into())), | ||
message: "syntax error: unexpected token".into(), | ||
..Default::default() | ||
}), | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
...ice/tests/diagnostics/snapshots/features__diagnostics__syntax__top_level_error_token.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
--- | ||
source: crates/service/tests/diagnostics/syntax.rs | ||
expression: response | ||
--- | ||
{ | ||
"kind": "full", | ||
"items": [ | ||
{ | ||
"range": { | ||
"start": { | ||
"line": 0, | ||
"character": 8 | ||
}, | ||
"end": { | ||
"line": 0, | ||
"character": 9 | ||
} | ||
}, | ||
"severity": 1, | ||
"code": "syntax", | ||
"source": "wat", | ||
"message": "syntax error: unexpected token" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters