@@ -702,8 +702,18 @@ public IEnumerable<QsNamespace> GetSyntaxTree() =>
702702 /// Note: this method waits for all currently running or queued tasks to finish
703703 /// before constructing the Compilation object by calling FlushAndExecute.
704704 /// </summary>
705- public Compilation Build ( ) =>
706- this . FlushAndExecute ( ( ) => new Compilation ( this ) ) ;
705+ public Compilation Build ( ) => this . FlushAndExecute ( ( ) =>
706+ {
707+ try
708+ {
709+ return new Compilation ( this ) ;
710+ }
711+ catch ( Exception ex )
712+ {
713+ LogException ( ex ) ;
714+ return null ;
715+ }
716+ } ) ;
707717
708718 /// <summary>
709719 /// Class used to accumulate all information about the state of a compilation unit in immutable form.
@@ -843,46 +853,42 @@ public IEnumerable<NonNullable<string>> SymbolsDefinedInNamespace(NonNullable<st
843853
844854 internal Compilation ( CompilationUnitManager manager )
845855 {
846- try
847- {
848- this . BuiltCompilation = manager . CompilationUnit . Build ( ) ;
849- this . SourceFiles = manager . FileContentManagers . Keys . ToImmutableHashSet ( ) ;
850- this . References = manager . CompilationUnit . Externals . Declarations . Keys . ToImmutableHashSet ( ) ;
851-
852- this . FileContent = this . SourceFiles
853- . Select ( file => ( file , manager . FileContentManagers [ file ] . GetLines ( ) . Select ( line => line . Text ) . ToImmutableArray ( ) ) )
854- . ToImmutableDictionary ( tuple => tuple . Item1 , tuple => tuple . Item2 ) ;
855- this . Tokenization = this . SourceFiles
856- . Select ( file => ( file , manager . FileContentManagers [ file ] . GetTokenizedLines ( ) . Select ( line => line . Select ( frag => frag . Copy ( ) ) . ToImmutableArray ( ) ) . ToImmutableArray ( ) ) )
857- . ToImmutableDictionary ( tuple => tuple . Item1 , tuple => tuple . Item2 ) ;
858- this . SyntaxTree = this . BuiltCompilation . Namespaces . ToImmutableDictionary ( ns => ns . Name ) ;
859-
860- this . OpenDirectivesForEachFile = this . SyntaxTree . Keys . ToImmutableDictionary (
861- nsName => nsName ,
862- nsName => manager . CompilationUnit . GetOpenDirectives ( nsName ) ) ;
863- this . NamespaceDeclarations = this . SourceFiles
864- . Select ( file => ( file , manager . FileContentManagers [ file ] . NamespaceDeclarationTokens ( ) . Select ( t => t . GetFragmentWithClosingComments ( ) ) . ToImmutableArray ( ) ) )
865- . ToImmutableDictionary ( tuple => tuple . Item1 , tuple => tuple . Item2 ) ;
866- this . Callables = this . SyntaxTree . Values . GlobalCallableResolutions ( ) ;
867- this . Types = this . SyntaxTree . Values . GlobalTypeResolutions ( ) ;
868-
869- this . ScopeDiagnostics = this . SourceFiles
870- . Select ( file => ( file , manager . FileContentManagers [ file ] . CurrentScopeDiagnostics ( ) ) )
871- . ToImmutableDictionary ( tuple => tuple . Item1 , tuple => tuple . Item2 ) ;
872- this . SyntaxDiagnostics = this . SourceFiles
873- . Select ( file => ( file , manager . FileContentManagers [ file ] . CurrentSyntaxDiagnostics ( ) ) )
874- . ToImmutableDictionary ( tuple => tuple . Item1 , tuple => tuple . Item2 ) ;
875- this . ContextDiagnostics = this . SourceFiles
876- . Select ( file => ( file , manager . FileContentManagers [ file ] . CurrentContextDiagnostics ( ) ) )
877- . ToImmutableDictionary ( tuple => tuple . Item1 , tuple => tuple . Item2 ) ;
878- this . HeaderDiagnostics = this . SourceFiles
879- . Select ( file => ( file , manager . FileContentManagers [ file ] . CurrentHeaderDiagnostics ( ) ) )
880- . ToImmutableDictionary ( tuple => tuple . Item1 , tuple => tuple . Item2 ) ;
881- this . SemanticDiagnostics = this . SourceFiles
882- . Select ( file => ( file , manager . FileContentManagers [ file ] . CurrentSemanticDiagnostics ( ) ) )
883- . ToImmutableDictionary ( tuple => tuple . Item1 , tuple => tuple . Item2 ) ;
884- }
885- catch ( Exception ex ) { manager . LogException ( ex ) ; }
856+ this . BuiltCompilation = manager . CompilationUnit . Build ( ) ;
857+ this . SourceFiles = manager . FileContentManagers . Keys . ToImmutableHashSet ( ) ;
858+ this . References = manager . CompilationUnit . Externals . Declarations . Keys . ToImmutableHashSet ( ) ;
859+
860+ this . FileContent = this . SourceFiles
861+ . Select ( file => ( file , manager . FileContentManagers [ file ] . GetLines ( ) . Select ( line => line . Text ) . ToImmutableArray ( ) ) )
862+ . ToImmutableDictionary ( tuple => tuple . Item1 , tuple => tuple . Item2 ) ;
863+ this . Tokenization = this . SourceFiles
864+ . Select ( file => ( file , manager . FileContentManagers [ file ] . GetTokenizedLines ( ) . Select ( line => line . Select ( frag => frag . Copy ( ) ) . ToImmutableArray ( ) ) . ToImmutableArray ( ) ) )
865+ . ToImmutableDictionary ( tuple => tuple . Item1 , tuple => tuple . Item2 ) ;
866+ this . SyntaxTree = this . BuiltCompilation . Namespaces . ToImmutableDictionary ( ns => ns . Name ) ;
867+
868+ this . OpenDirectivesForEachFile = this . SyntaxTree . Keys . ToImmutableDictionary (
869+ nsName => nsName ,
870+ nsName => manager . CompilationUnit . GetOpenDirectives ( nsName ) ) ;
871+ this . NamespaceDeclarations = this . SourceFiles
872+ . Select ( file => ( file , manager . FileContentManagers [ file ] . NamespaceDeclarationTokens ( ) . Select ( t => t . GetFragmentWithClosingComments ( ) ) . ToImmutableArray ( ) ) )
873+ . ToImmutableDictionary ( tuple => tuple . Item1 , tuple => tuple . Item2 ) ;
874+ this . Callables = this . SyntaxTree . Values . GlobalCallableResolutions ( ) ;
875+ this . Types = this . SyntaxTree . Values . GlobalTypeResolutions ( ) ;
876+
877+ this . ScopeDiagnostics = this . SourceFiles
878+ . Select ( file => ( file , manager . FileContentManagers [ file ] . CurrentScopeDiagnostics ( ) ) )
879+ . ToImmutableDictionary ( tuple => tuple . Item1 , tuple => tuple . Item2 ) ;
880+ this . SyntaxDiagnostics = this . SourceFiles
881+ . Select ( file => ( file , manager . FileContentManagers [ file ] . CurrentSyntaxDiagnostics ( ) ) )
882+ . ToImmutableDictionary ( tuple => tuple . Item1 , tuple => tuple . Item2 ) ;
883+ this . ContextDiagnostics = this . SourceFiles
884+ . Select ( file => ( file , manager . FileContentManagers [ file ] . CurrentContextDiagnostics ( ) ) )
885+ . ToImmutableDictionary ( tuple => tuple . Item1 , tuple => tuple . Item2 ) ;
886+ this . HeaderDiagnostics = this . SourceFiles
887+ . Select ( file => ( file , manager . FileContentManagers [ file ] . CurrentHeaderDiagnostics ( ) ) )
888+ . ToImmutableDictionary ( tuple => tuple . Item1 , tuple => tuple . Item2 ) ;
889+ this . SemanticDiagnostics = this . SourceFiles
890+ . Select ( file => ( file , manager . FileContentManagers [ file ] . CurrentSemanticDiagnostics ( ) ) )
891+ . ToImmutableDictionary ( tuple => tuple . Item1 , tuple => tuple . Item2 ) ;
886892 }
887893 }
888894 }
0 commit comments