diff --git a/src/AddIns/BackendBindings/CSharpBinding/Project/CSharpBinding.addin b/src/AddIns/BackendBindings/CSharpBinding/Project/CSharpBinding.addin index e6cf18c6fe..20e713efb8 100644 --- a/src/AddIns/BackendBindings/CSharpBinding/Project/CSharpBinding.addin +++ b/src/AddIns/BackendBindings/CSharpBinding/Project/CSharpBinding.addin @@ -203,6 +203,7 @@ + diff --git a/src/AddIns/BackendBindings/CSharpBinding/Project/CSharpBinding.csproj b/src/AddIns/BackendBindings/CSharpBinding/Project/CSharpBinding.csproj index d5a5435c6e..dc46e7f09f 100644 --- a/src/AddIns/BackendBindings/CSharpBinding/Project/CSharpBinding.csproj +++ b/src/AddIns/BackendBindings/CSharpBinding/Project/CSharpBinding.csproj @@ -74,6 +74,7 @@ + IssueOptions.xaml diff --git a/src/AddIns/BackendBindings/CSharpBinding/Project/Src/Refactoring/CSharpSyntaxIssue.cs b/src/AddIns/BackendBindings/CSharpBinding/Project/Src/Refactoring/CSharpSyntaxIssue.cs new file mode 100644 index 0000000000..bc9eaaf8d4 --- /dev/null +++ b/src/AddIns/BackendBindings/CSharpBinding/Project/Src/Refactoring/CSharpSyntaxIssue.cs @@ -0,0 +1,50 @@ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) +using System; +using System.Collections.Generic; +using System.Linq; +using ICSharpCode.AvalonEdit.Document; +using ICSharpCode.NRefactory; +using ICSharpCode.NRefactory.CSharp; +using ICSharpCode.NRefactory.CSharp.Refactoring; +using ICSharpCode.NRefactory.Editor; +using ICSharpCode.NRefactory.TypeSystem; + +namespace CSharpBinding.Refactoring +{ + public class CSharpSyntaxIssue : ICodeIssueProvider + { + public IEnumerable GetIssues(BaseRefactoringContext context) + { + var refactoringContext = context as SDRefactoringContext; + if (refactoringContext == null) + return Enumerable.Empty(); + + var syntaxTree = context.RootNode as SyntaxTree; + if (syntaxTree == null) + return Enumerable.Empty(); + + return syntaxTree.Errors.Select(error => CreateCodeIssue(error, refactoringContext)); + } + + CodeIssue CreateCodeIssue(Error error, SDRefactoringContext context) + { + IDocument document = context.Document; + TextLocation begin = error.Region.Begin; + + int offset = document.GetOffset(begin.Line, begin.Column); + int endOffset = TextUtilities.GetNextCaretPosition(document, offset, System.Windows.Documents.LogicalDirection.Forward, CaretPositioningMode.WordBorderOrSymbol); + if (endOffset < 0) endOffset = document.TextLength; + int length = endOffset - offset; + + if (length < 2) { + // marker should be at least 2 characters long, but take care that we don't make + // it longer than the document + length = Math.Min(2, document.TextLength - offset); + } + + TextLocation end = document.GetLocation(offset + length); + return new CodeIssue(error.Message, begin, end); + } + } +}