@@ -39,6 +39,7 @@ use regex::Regex;
3939use lazy_static:: lazy_static;
4040
4141mod commands;
42+ mod diagnostics_parser;
4243mod configuration;
4344mod consts;
4445mod dfs;
@@ -53,7 +54,6 @@ mod url_norm;
5354mod test;
5455
5556lazy_static ! {
56- static ref RE_DIAGNOSTIC : Regex = Regex :: new( r#"^(?P<filepath>[^?<>*|"]+)\((?P<linenum>\d+)\) : (?P<severity>error|warning) [A-C]\d+: (?P<output>.+)"# ) . unwrap( ) ;
5757 static ref RE_VERSION : Regex = Regex :: new( r#"#version [\d]{3}"# ) . unwrap( ) ;
5858 static ref RE_INCLUDE : Regex = Regex :: new( r#"^(?:\s)*?(?:#include) "(.+)"\r?"# ) . unwrap( ) ;
5959 static ref RE_INCLUDE_EXTENSION : Regex = Regex :: new( r#"#extension GL_GOOGLE_include_directive ?: ?require"# ) . unwrap( ) ;
@@ -352,7 +352,7 @@ impl MinecraftShaderLanguageServer {
352352 return Ok ( diagnostics) ;
353353 }
354354 } ;
355- diagnostics. extend ( self . parse_validator_stdout ( uri , stdout , "" ) ) ;
355+ diagnostics. extend ( diagnostics_parser :: parse_diagnostics_output ( stdout , uri , self . opengl_context . as_ref ( ) ) ) ;
356356 } else {
357357 let mut all_trees: Vec < ( TreeType , Vec < ( NodeIndex , Option < _ > ) > ) > = Vec :: new ( ) ;
358358
@@ -402,86 +402,14 @@ impl MinecraftShaderLanguageServer {
402402 Some ( s) => s,
403403 None => continue ,
404404 } ;
405- diagnostics. extend ( self . parse_validator_stdout ( uri , stdout , "" ) ) ;
405+ diagnostics. extend ( diagnostics_parser :: parse_diagnostics_output ( stdout , uri , self . opengl_context . as_ref ( ) ) ) ;
406406 }
407407 } ;
408408
409409 back_fill ( & all_sources, & mut diagnostics) ;
410410 Ok ( diagnostics)
411411 }
412412
413- fn parse_validator_stdout ( & self , uri : & Path , stdout : String , _source : & str ) -> HashMap < Url , Vec < Diagnostic > > {
414- let stdout_lines = stdout. split ( '\n' ) ;
415- let mut diagnostics: HashMap < Url , Vec < Diagnostic > > = HashMap :: with_capacity ( stdout_lines. count ( ) ) ;
416- let stdout_lines = stdout. split ( '\n' ) ;
417-
418- for line in stdout_lines {
419- let diagnostic_capture = match RE_DIAGNOSTIC . captures ( line) {
420- Some ( d) => d,
421- None => continue
422- } ;
423-
424- eprintln ! ( "match {:?}" , diagnostic_capture) ;
425-
426- let msg = diagnostic_capture. name ( "output" ) . unwrap ( ) . as_str ( ) ;
427-
428- let line = match diagnostic_capture. name ( "linenum" ) {
429- Some ( c) => c. as_str ( ) . parse :: < u32 > ( ) . unwrap_or ( 0 ) ,
430- None => 0 ,
431- } - 2 ;
432-
433- // TODO: line matching maybe
434- /* let line_text = source_lines[line as usize];
435- let leading_whitespace = line_text.len() - line_text.trim_start().len(); */
436-
437- let severity = match diagnostic_capture. name ( "severity" ) {
438- Some ( c) => match c. as_str ( ) {
439- "error" => DiagnosticSeverity :: Error ,
440- "warning" => DiagnosticSeverity :: Warning ,
441- _ => DiagnosticSeverity :: Information ,
442- }
443- _ => DiagnosticSeverity :: Information ,
444- } ;
445-
446- let origin = match diagnostic_capture. name ( "filepath" ) {
447- Some ( o) => {
448- if o. as_str ( ) == "0" {
449- uri. to_str ( ) . unwrap ( ) . to_string ( )
450- } else {
451- o. as_str ( ) . to_string ( )
452- }
453- } ,
454- None => uri. to_str ( ) . unwrap ( ) . to_string ( ) ,
455- } ;
456-
457- let diagnostic = Diagnostic {
458- range : Range :: new (
459- /* Position::new(line, leading_whitespace as u64),
460- Position::new(line, line_text.len() as u64) */
461- Position :: new ( line, 0 ) ,
462- Position :: new ( line, 1000 ) ,
463- ) ,
464- code : None ,
465- severity : Some ( severity) ,
466- source : Some ( consts:: SOURCE . into ( ) ) ,
467- message : msg. trim ( ) . into ( ) ,
468- related_information : None ,
469- tags : None ,
470- code_description : Option :: None ,
471- data : Option :: None ,
472- } ;
473-
474- let origin_url = Url :: from_file_path ( origin) . unwrap ( ) ;
475- match diagnostics. get_mut ( & origin_url) {
476- Some ( d) => d. push ( diagnostic) ,
477- None => {
478- diagnostics. insert ( origin_url, vec ! [ diagnostic] ) ;
479- } ,
480- } ;
481- }
482- diagnostics
483- }
484-
485413 pub fn get_dfs_for_node ( & self , root : NodeIndex ) -> Result < Vec < ( NodeIndex , Option < NodeIndex > ) > , dfs:: error:: CycleError > {
486414 let graph_ref = self . graph . borrow ( ) ;
487415
0 commit comments