From 158219a2185e343b34f3242eb2416bb3cabc2c92 Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Thu, 7 Jun 2012 14:40:57 +0200 Subject: [PATCH] Fixed XAML parser (was adding 'null' as top-level type). Added exception handling to CSharpSemanticHighlighter. --- .../Project/Src/CSharpSemanticHighlighter.cs | 12 +++++++++++- .../XamlBinding/XamlBinding/XamlParsedFile.cs | 5 ++++- .../Src/Services/RefactoringService/Reference.cs | 1 - src/Main/SharpDevelop/Parser/ParserService.cs | 9 --------- 4 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/AddIns/BackendBindings/CSharpBinding/Project/Src/CSharpSemanticHighlighter.cs b/src/AddIns/BackendBindings/CSharpBinding/Project/Src/CSharpSemanticHighlighter.cs index 5cccbb9efc..0bd9bfc4fd 100644 --- a/src/AddIns/BackendBindings/CSharpBinding/Project/Src/CSharpSemanticHighlighter.cs +++ b/src/AddIns/BackendBindings/CSharpBinding/Project/Src/CSharpSemanticHighlighter.cs @@ -36,6 +36,7 @@ namespace CSharpBinding List invalidLines = new List(); List cachedLines = new List(); + bool hasCrashed; int lineNumber; HighlightedLine line; @@ -184,6 +185,10 @@ namespace CSharpBinding public HighlightedLine HighlightLine(int lineNumber) { IDocumentLine documentLine = textEditor.Document.GetLineByNumber(lineNumber); + if (hasCrashed) { + // don't highlight anymore after we've crashed + return new HighlightedLine(textEditor.Document, documentLine); + } ITextSourceVersion newVersion = textEditor.Document.Version; CachedLine cachedLine = null; for (int i = 0; i < cachedLines.Count; i++) { @@ -225,7 +230,12 @@ namespace CSharpBinding HighlightedLine line = new HighlightedLine(textEditor.Document, documentLine); this.line = line; this.lineNumber = lineNumber; - parseInfo.CompilationUnit.AcceptVisitor(this); + try { + parseInfo.CompilationUnit.AcceptVisitor(this); + } catch (Exception ex) { + hasCrashed = true; + throw new ApplicationException("Error highlighting line " + lineNumber, ex); + } this.line = null; this.resolver = null; Debug.WriteLine("Semantic highlighting for line {0} - added {1} sections", lineNumber, line.Sections.Count); diff --git a/src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlParsedFile.cs b/src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlParsedFile.cs index d136605e2e..4b50ca21b4 100644 --- a/src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlParsedFile.cs +++ b/src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlParsedFile.cs @@ -43,7 +43,10 @@ namespace ICSharpCode.XamlBinding file.errors.AddRange(document.SyntaxErrors.Select(err => new Error(ErrorType.Error, err.Description))); var visitor = new XamlDocumentVisitor(file, fileContent); visitor.VisitDocument(document); - file.topLevel = new[] { visitor.TypeDefinition }; + if (visitor.TypeDefinition != null) + file.topLevel = new[] { visitor.TypeDefinition }; + else + file.topLevel = new IUnresolvedTypeDefinition[0]; file.lastWriteTime = DateTime.UtcNow; return file; diff --git a/src/Main/Base/Project/Src/Services/RefactoringService/Reference.cs b/src/Main/Base/Project/Src/Services/RefactoringService/Reference.cs index e9bbac85ac..2958fb2498 100644 --- a/src/Main/Base/Project/Src/Services/RefactoringService/Reference.cs +++ b/src/Main/Base/Project/Src/Services/RefactoringService/Reference.cs @@ -15,7 +15,6 @@ namespace ICSharpCode.SharpDevelop.Refactoring /// public class Reference : SearchResultMatch { - DomRegion region; ResolveResult resolveResult; public Reference(DomRegion region, ResolveResult resolveResult, int offset, int length, HighlightedInlineBuilder builder) diff --git a/src/Main/SharpDevelop/Parser/ParserService.cs b/src/Main/SharpDevelop/Parser/ParserService.cs index a6df298bdb..0218d6b829 100644 --- a/src/Main/SharpDevelop/Parser/ParserService.cs +++ b/src/Main/SharpDevelop/Parser/ParserService.cs @@ -84,15 +84,6 @@ namespace ICSharpCode.SharpDevelop.Parser } #endregion - #region Load Solution Projects Thread - public bool LoadSolutionProjectsThreadRunning { - get { return false; } - } - - public event EventHandler LoadSolutionProjectsThreadStarted; - public event EventHandler LoadSolutionProjectsThreadEnded; - #endregion - #region Compilation public ICompilation GetCompilation(IProject project) {