void SetDiagnostics(IEnumerable <CompilerDiagnostic> diags) { Diagnostics.Clear(); Diagnostics.AddRange(diags.OrderBy(a => a, CompilerDiagnosticComparer.Instance). Where(a => a.Severity != CompilerDiagnosticSeverity.Hidden). Select(a => new CompilerDiagnosticVM(a, GetImageReference(a.Severity) ?? default(ImageReference)))); SelectedCompilerDiagnosticVM = Diagnostics.FirstOrDefault(); }
public override BoundNode VisitPatternSwitchStatement(BoundPatternSwitchStatement node) { // The pattern switch statement has computed a state machine, and gathered diagnostics // related to subsumption. We report those here. Diagnostics.AddRange(node.DecisionTreeDiagnostics); return(base.VisitPatternSwitchStatement(node)); }
public void Handle(AutodictorDiagnosticEvent message) { if (message.NameRailwayStation == StationOwner.Name) { Diagnostics.Clear(); Diagnostics.AddRange(message.DiagnosticData); } }
private IEnumerable <SyntaxTree> LoadSources(ICollection <CommandLineSourceFile> paths) { var trees = new SyntaxTree[paths.Count]; var parseOptions = CscArgs.ParseOptions; var scriptParseOptions = CscArgs.ParseOptions.WithKind(SourceCodeKind.Script); var diagnostics = new Diagnostic[paths.Count]; Parallel.ForEach(paths, (path, state, index) => { var file = path.Path; var ext = Path.GetExtension(file) ?? ""; Lazy <Parser> parser; if (_syntaxTreeLoaders.TryGetValue(ext, out parser)) { var fileOpen = false; try { // bufferSize: 1 -> https://github.com/dotnet/roslyn/blob/ec1ea081ff5d84e91cbcb3b2f824655609cc5fc6/src/Compilers/Core/Portable/CommandLine/CommonCompiler.cs#L143 using ( var sourceStream = new FileStream(file, FileMode.Open, FileAccess.Read, FileShare.Read, bufferSize: 1)) { fileOpen = true; trees[index] = parser.Value.GetSyntaxTree(file, sourceStream, path.IsScript ? scriptParseOptions : parseOptions); } } // should be equivalent to CommonCompiler.ToFileReadDiagnostics // see https://github.com/dotnet/roslyn/blob/ddaf4146/src/Compilers/Core/Portable/CommandLine/CommonCompiler.cs#L165 catch (Exception ex) when(!fileOpen && (ex is FileNotFoundException || ex is DirectoryNotFoundException)) { diagnostics[index] = Diagnostic.Create(ERR_FileNotFound, Location.None, file); } catch (InvalidDataException) { diagnostics[index] = Diagnostic.Create(ERR_BinaryFile, AsLocation(file), file); } catch (Exception ex) { diagnostics[index] = Diagnostic.Create(ERR_NoSourceFile, AsLocation(file), file, ex.Message); } } else { diagnostics[index] = Diagnostic.Create(UnknownFileType, AsLocation(file), ext); } }); Diagnostics.AddRange(diagnostics.Where(x => x != null)); return(trees.Where(x => x != null).Concat(GeneratedSyntaxTrees())); }
private EmitResult Emit(CompileContext context) { var compilation = context.BeforeCompileContext.Compilation; var pdbPath = CscArgs.PdbPath; var outputPath = Path.Combine(CscArgs.OutputDirectory, CscArgs.OutputFileName); if (!CscArgs.EmitPdb) { pdbPath = null; } else if (string.IsNullOrWhiteSpace(pdbPath)) { pdbPath = Path.ChangeExtension(outputPath, ".pdb"); } using (var peStream = new MemoryStream()) using (var pdbStream = !string.IsNullOrWhiteSpace(pdbPath) ? new MemoryStream() : null) using (var xmlDocumentationStream = !string.IsNullOrWhiteSpace(CscArgs.DocumentationPath) ? new MemoryStream(): null) using (var win32Resources = CreateWin32Resource(compilation)) { // https://github.com/dotnet/roslyn/blob/41950e21da3ac2c307fb46c2ca8c8509b5059909/src/Compilers/Core/Portable/CommandLine/CommonCompiler.cs#L437 var emitResult = compilation.Emit( peStream: peStream, pdbStream: pdbStream, xmlDocumentationStream: xmlDocumentationStream, win32Resources: win32Resources, manifestResources: CscArgs.ManifestResources, options: CscArgs.EmitOptions, debugEntryPoint: null); Diagnostics.AddRange(emitResult.Diagnostics); context.After(new AfterCompileContext { Arguments = CscArgs, AssemblyStream = peStream, Compilation = compilation, Diagnostics = Diagnostics, SymbolStream = pdbStream, XmlDocStream = xmlDocumentationStream, }); // do not create the output files if emit fails // if the output files are there, msbuild incremental build thinks the previous build succeeded if (emitResult.Success) { Task.WaitAll( DumpToFileAsync(outputPath, peStream), DumpToFileAsync(pdbPath, pdbStream), DumpToFileAsync(CscArgs.DocumentationPath, xmlDocumentationStream)); } return(emitResult); } }
public Parser(SyntaxTree syntaxTree) { var tokens = new List <SyntaxToken>(); var badTokens = new List <SyntaxToken>(); var lexer = new Lexer(syntaxTree); SyntaxToken token; do { token = lexer.Lex(); if (token.Kind == SyntaxKind.BadToken) { badTokens.Add(token); } else { if (badTokens.Count > 0) { var leadingTrivia = token.LeadingTrivia.ToBuilder(); var index = 0; foreach (var badToken in badTokens) { foreach (var lt in badToken.LeadingTrivia) { leadingTrivia.Insert(index++, lt); } var trivia = new SyntaxTrivia(syntaxTree, SyntaxKind.SkippedTextTrivia, badToken.Position, badToken.Text); leadingTrivia.Insert(index++, trivia); foreach (var tt in badToken.TrailingTrivia) { leadingTrivia.Insert(index++, tt); } } badTokens.Clear(); token = new SyntaxToken(token.SyntaxTree, token.Kind, token.Position, token.Text, token.Value, leadingTrivia.ToImmutable(), token.TrailingTrivia); } tokens.Add(token); } } while (token.Kind != SyntaxKind.EndOfFileToken); _syntaxTree = syntaxTree; _text = syntaxTree.Text; _tokens = tokens.ToImmutableArray(); Diagnostics.AddRange(lexer.Diagnostics); }
public Parser(SourceText _text) { List <SyntaxToken> _tokens = new List <SyntaxToken>(); Lexer _lexer = new Lexer(_text); SyntaxToken _token; do { _token = _lexer.Lex(); if (_token.Kind != SyntaxKind.WhitespaceToken && _token.Kind != SyntaxKind.BadToken) { _tokens.Add(_token); } } while (_token.Kind != SyntaxKind.EndOfFileToken); tokens = _tokens.ToImmutableArray(); Diagnostics.AddRange(_lexer.Diagnostics); text = _text; }
public virtual async Task InitializeAsync() { if (Annotations == null && Diagnostics.Count == 0) { throw new InvalidOperationException("Attempted to initialize block before parsing code fence annotations"); } if (_initialized) { return; } _initialized = true; switch (Annotations) { case CodeBlockAnnotations codeBlockAnnotations: var result = await codeBlockAnnotations.TryGetExternalContent(); switch (result) { case SuccessfulCodeBlockContentFetchResult success: SourceCode = success.Content; await AddAttributes(codeBlockAnnotations); break; case ExternalContentNotEnabledResult _: SourceCode = Lines.ToString(); await AddAttributes(codeBlockAnnotations); break; case FailedCodeBlockContentFetchResult failed: Diagnostics.AddRange(failed.ErrorMessages); break; } break; } }
public Parser(string text) { var tokens = new List <SyntaxToken>(); var lexer = new Lexer(text); SyntaxToken token; do { token = lexer.NextToken(); if (token.Kind != SyntaxKind.WhiteSpaceToken && token.Kind != SyntaxKind.BadToken) { tokens.Add(token); } } while (token.Kind != SyntaxKind.EndOfFileToken); _tokens = tokens.ToArray(); Diagnostics.AddRange(lexer.Diagnostics); }
/// <summary> /// Initializes a new instance of the <see cref="Parser"/> class. /// </summary> /// <param name="text">The source document.</param> public Parser(SourceText text) { var tokens = new List <SyntaxToken>(); var lexer = new Lexer(text); SyntaxToken token; do { token = lexer.Lex(); if (token.Kind != SyntaxKind.WhitespaceToken && token.Kind != SyntaxKind.CommentToken && token.Kind != SyntaxKind.BadToken) { tokens.Add(token); } }while (token.Kind != SyntaxKind.EndOfFileToken); this.text = text; this.tokens = tokens.ToImmutableArray(); Diagnostics.AddRange(lexer.Diagnostics); }