@@ -7,7 +7,7 @@ use petgraph::stable_graph::NodeIndex;
77use serde:: Deserialize ;
88use serde_json:: { from_value, Value } ;
99
10- use tree_sitter:: Parser ;
10+ use tree_sitter:: { Parser , Point } ;
1111use url_norm:: FromUrl ;
1212
1313use walkdir:: WalkDir ;
@@ -39,10 +39,10 @@ use regex::Regex;
3939use lazy_static:: lazy_static;
4040
4141mod commands;
42- mod diagnostics_parser;
4342mod configuration;
4443mod consts;
4544mod dfs;
45+ mod diagnostics_parser;
4646mod graph;
4747mod logging;
4848mod lsp_ext;
@@ -352,7 +352,11 @@ impl MinecraftShaderLanguageServer {
352352 return Ok ( diagnostics) ;
353353 }
354354 } ;
355- diagnostics. extend ( diagnostics_parser:: parse_diagnostics_output ( stdout, uri, self . opengl_context . as_ref ( ) ) ) ;
355+ diagnostics. extend ( diagnostics_parser:: parse_diagnostics_output (
356+ stdout,
357+ uri,
358+ self . opengl_context . as_ref ( ) ,
359+ ) ) ;
356360 } else {
357361 let mut all_trees: Vec < ( TreeType , Vec < ( NodeIndex , Option < _ > ) > ) > = Vec :: new ( ) ;
358362
@@ -402,7 +406,11 @@ impl MinecraftShaderLanguageServer {
402406 Some ( s) => s,
403407 None => continue ,
404408 } ;
405- diagnostics. extend ( diagnostics_parser:: parse_diagnostics_output ( stdout, uri, self . opengl_context . as_ref ( ) ) ) ;
409+ diagnostics. extend ( diagnostics_parser:: parse_diagnostics_output (
410+ stdout,
411+ uri,
412+ self . opengl_context . as_ref ( ) ,
413+ ) ) ;
406414 }
407415 } ;
408416
@@ -488,6 +496,7 @@ impl LanguageServerHandling for MinecraftShaderLanguageServer {
488496 info ! ( "starting server..." ) ;
489497
490498 let capabilities = ServerCapabilities {
499+ definition_provider : Some ( OneOf :: Left ( true ) ) ,
491500 document_link_provider : Some ( DocumentLinkOptions {
492501 resolve_provider : None ,
493502 work_done_progress_options : WorkDoneProgressOptions { work_done_progress : None } ,
@@ -660,7 +669,23 @@ impl LanguageServerHandling for MinecraftShaderLanguageServer {
660669 completable. complete ( Err ( Self :: error_not_available ( ( ) ) ) ) ;
661670 }
662671
663- fn goto_definition ( & mut self , _: TextDocumentPositionParams , completable : LSCompletable < Vec < Location > > ) {
672+ fn goto_definition ( & mut self , params : TextDocumentPositionParams , completable : LSCompletable < Vec < Location > > ) {
673+ let source = fs:: read_to_string ( params. text_document . uri . path ( ) ) . unwrap ( ) ;
674+ let tree = self . tree_sitter . borrow_mut ( ) . parse ( source, None ) . unwrap ( ) ;
675+
676+ let node_at_pos = tree. root_node ( ) . named_descendant_for_point_range (
677+ Point {
678+ row : params. position . line as usize ,
679+ column : params. position . character as usize ,
680+ } ,
681+ Point {
682+ row : params. position . line as usize ,
683+ column : ( params. position . character + 1 ) as usize ,
684+ } ,
685+ ) ;
686+
687+ info ! ( "found a node" ; "node" => format!( "{:?}" , node_at_pos) ) ;
688+
664689 completable. complete ( Err ( Self :: error_not_available ( ( ) ) ) ) ;
665690 }
666691
0 commit comments