Assert tree-sitter validity in each AST test
This commit is contained in:
@@ -321,3 +321,19 @@ pub fn ast_syntax_errors(db: &dyn Database, ast: AstNode) {
|
|||||||
.for_each(|child| ast_syntax_errors(db, *child));
|
.for_each(|child| ast_syntax_errors(db, *child));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[salsa::tracked]
|
||||||
|
pub fn file_has_syntax_error(db: &dyn Database, file: File) -> bool {
|
||||||
|
ast_has_syntax_error(db, file.ast(db))
|
||||||
|
}
|
||||||
|
|
||||||
|
#[salsa::tracked]
|
||||||
|
pub fn ast_has_syntax_error(db: &dyn Database, ast: AstNode) -> bool {
|
||||||
|
if ast.symbol(db) == "ERROR" {
|
||||||
|
true
|
||||||
|
} else {
|
||||||
|
ast.children(db)
|
||||||
|
.iter()
|
||||||
|
.any(|ast| ast_has_syntax_error(db, *ast))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -38,6 +38,12 @@ fn test_ast(path: &Path) -> datatest_stable::Result<()> {
|
|||||||
let uri = lsp_types::Url::from_file_path(&path).unwrap();
|
let uri = lsp_types::Url::from_file_path(&path).unwrap();
|
||||||
let ed = Editor::new(&mut db, workspace, uri, &src);
|
let ed = Editor::new(&mut db, workspace, uri, &src);
|
||||||
|
|
||||||
|
// ensure tree-sitter has fully parsed
|
||||||
|
assert!(
|
||||||
|
!workspace::file_has_syntax_error(&db, ed.get_file()),
|
||||||
|
"test has syntax error"
|
||||||
|
);
|
||||||
|
|
||||||
// list and parse top-level items
|
// list and parse top-level items
|
||||||
ast::items(&db, ed.get_file()).into_iter().for_each(|meta| {
|
ast::items(&db, ed.get_file()).into_iter().for_each(|meta| {
|
||||||
ast::item(&db, meta);
|
ast::item(&db, meta);
|
||||||
|
|||||||
Reference in New Issue
Block a user