Browse Source

implement code issue to display syntax errors found by the Mono C# parser

newNRvisualizers
Siegfried Pammer 13 years ago
parent
commit
7a033c8aca
  1. 1
      src/AddIns/BackendBindings/CSharpBinding/Project/CSharpBinding.addin
  2. 1
      src/AddIns/BackendBindings/CSharpBinding/Project/CSharpBinding.csproj
  3. 50
      src/AddIns/BackendBindings/CSharpBinding/Project/Src/Refactoring/CSharpSyntaxIssue.cs

1
src/AddIns/BackendBindings/CSharpBinding/Project/CSharpBinding.addin

@ -203,6 +203,7 @@ @@ -203,6 +203,7 @@
<Class class = "ICSharpCode.NRefactory.CSharp.Refactoring.UseVarKeywordIssue" />
<Class class = "ICSharpCode.NRefactory.CSharp.Refactoring.ValueParameterUnusedIssue" />
<Class class = "ICSharpCode.NRefactory.CSharp.Refactoring.VariableDeclaredInWideScopeIssue" />
<Class class = "CSharpBinding.Refactoring.CSharpSyntaxIssue" />
</Path>
<Path path = "/SharpDevelop/ViewContent/TextEditor/C#/ContextActions">

1
src/AddIns/BackendBindings/CSharpBinding/Project/CSharpBinding.csproj

@ -74,6 +74,7 @@ @@ -74,6 +74,7 @@
<Compile Include="Src\Completion\SegmentTrackingOutputFormatter.cs" />
<Compile Include="Src\FormattingStrategy\CSharpFormatter.cs" />
<Compile Include="Src\Parser\FoldingVisitor.cs" />
<Compile Include="Src\Refactoring\CSharpSyntaxIssue.cs" />
<Compile Include="Src\Refactoring\InsertionPoint.cs" />
<Compile Include="Src\Refactoring\IssueOptions.xaml.cs">
<DependentUpon>IssueOptions.xaml</DependentUpon>

50
src/AddIns/BackendBindings/CSharpBinding/Project/Src/Refactoring/CSharpSyntaxIssue.cs

@ -0,0 +1,50 @@ @@ -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<CodeIssue> GetIssues(BaseRefactoringContext context)
{
var refactoringContext = context as SDRefactoringContext;
if (refactoringContext == null)
return Enumerable.Empty<CodeIssue>();
var syntaxTree = context.RootNode as SyntaxTree;
if (syntaxTree == null)
return Enumerable.Empty<CodeIssue>();
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);
}
}
}
Loading…
Cancel
Save