@@ -47,11 +47,13 @@ use biome_js_formatter::format_node;
47
47
use biome_js_parser:: JsParserOptions ;
48
48
use biome_js_semantic:: { SemanticModelOptions , semantic_model} ;
49
49
use biome_js_syntax:: {
50
- AnyJsRoot , JsFileSource , JsLanguage , JsSyntaxNode , LanguageVariant , TextRange , TextSize ,
50
+ AnyJsRoot , JsClassDeclaration , JsClassExpression , JsFileSource , JsFunctionDeclaration ,
51
+ JsLanguage , JsSyntaxNode , JsVariableDeclarator , LanguageVariant , TextRange , TextSize ,
51
52
TokenAtOffset ,
52
53
} ;
54
+ use biome_js_type_info:: Type ;
53
55
use biome_parser:: AnyParse ;
54
- use biome_rowan:: { AstNode , BatchMutationExt , Direction , NodeCache } ;
56
+ use biome_rowan:: { AstNode , BatchMutationExt , Direction , NodeCache , WalkEvent } ;
55
57
use camino:: Utf8Path ;
56
58
use serde:: { Deserialize , Serialize } ;
57
59
use std:: borrow:: Cow ;
@@ -481,6 +483,7 @@ impl ExtensionHandler for JsFileHandler {
481
483
debug_syntax_tree : Some ( debug_syntax_tree) ,
482
484
debug_control_flow : Some ( debug_control_flow) ,
483
485
debug_formatter_ir : Some ( debug_formatter_ir) ,
486
+ debug_type_info : Some ( debug_type_info) ,
484
487
} ,
485
488
analyzer : AnalyzerCapabilities {
486
489
lint : Some ( lint) ,
@@ -630,6 +633,37 @@ fn debug_formatter_ir(
630
633
Ok ( root_element. to_string ( ) )
631
634
}
632
635
636
+ fn debug_type_info ( _path : & BiomePath , parse : AnyParse ) -> Result < String , WorkspaceError > {
637
+ let tree: AnyJsRoot = parse. tree ( ) ;
638
+ let mut result = String :: new ( ) ;
639
+ let preorder = tree. syntax ( ) . preorder ( ) ;
640
+
641
+ for event in preorder {
642
+ match event {
643
+ WalkEvent :: Enter ( node) => {
644
+ if let Some ( node) = JsVariableDeclarator :: cast_ref ( & node) {
645
+ if let Some ( ty) = Type :: from_js_variable_declarator ( & node) {
646
+ result. push_str ( & ty. to_string ( ) ) ;
647
+ result. push ( '\n' ) ;
648
+ }
649
+ } else if let Some ( function) = JsFunctionDeclaration :: cast_ref ( & node) {
650
+ result. push_str ( & Type :: from_js_function_declaration ( & function) . to_string ( ) ) ;
651
+ result. push ( '\n' ) ;
652
+ } else if let Some ( class) = JsClassDeclaration :: cast_ref ( & node) {
653
+ result. push_str ( & Type :: from_js_class_declaration ( & class) . to_string ( ) ) ;
654
+ result. push ( '\n' ) ;
655
+ } else if let Some ( expression) = JsClassExpression :: cast_ref ( & node) {
656
+ result. push_str ( & Type :: from_js_class_expression ( & expression) . to_string ( ) ) ;
657
+ result. push ( '\n' ) ;
658
+ }
659
+ }
660
+ WalkEvent :: Leave ( _) => { }
661
+ }
662
+ }
663
+
664
+ Ok ( result)
665
+ }
666
+
633
667
pub ( crate ) fn lint ( params : LintParams ) -> LintResults {
634
668
let _ =
635
669
debug_span ! ( "Linting JavaScript file" , path =? params. path, language =? params. language)
0 commit comments