Browse Source

Fix #377: Underlines are a little off when created by background syntax check and after compilation

pull/463/head
Daniel Grunwald 11 years ago
parent
commit
a2236d7b4c
  1. 37
      src/AddIns/BackendBindings/CSharpBinding/Project/Src/Refactoring/CSharpSyntaxIssue.cs
  2. 8
      src/Main/Base/Project/Src/Services/Tasks/ErrorPainter.cs

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

@ -39,13 +39,26 @@ namespace CSharpBinding.Refactoring @@ -39,13 +39,26 @@ namespace CSharpBinding.Refactoring
{
var refactoringContext = context as SDRefactoringContext;
if (refactoringContext == null)
return Enumerable.Empty<CodeIssue>();
yield break;
var syntaxTree = context.RootNode as SyntaxTree;
if (syntaxTree == null)
return Enumerable.Empty<CodeIssue>();
return syntaxTree.Errors.Select(error => CreateCodeIssue(error, refactoringContext)).Where(issue => issue != null);
yield break;
int prevLine = 0;
foreach (var error in syntaxTree.Errors) {
if (error.Region.BeginLine == prevLine)
continue; // show at most one error per line
prevLine = error.Region.BeginLine;
var issue = CreateCodeIssue(error, refactoringContext);
if (issue != null)
yield return issue;
}
}
static bool IsSpaceOrTab(char c)
{
return c == ' ' || c == '\t';
}
CodeIssue CreateCodeIssue(Error error, SDRefactoringContext context)
@ -55,16 +68,18 @@ namespace CSharpBinding.Refactoring @@ -55,16 +68,18 @@ namespace CSharpBinding.Refactoring
if (begin.Line <= 0 || begin.Line > document.LineCount)
return null;
// Columns seem to be zero-based, SD expects 1-based columns
int offset = document.GetOffset(begin.Line, begin.Column + 1);
int offset = document.GetOffset(begin.Line, begin.Column);
// the parser sometimes reports errors in the whitespace prior to the invalid token, so search for the next word:
while (offset < document.TextLength && IsSpaceOrTab(document.GetCharAt(offset)))
offset++;
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);
if (length < 1) {
// marker should be at least 1 characters long,
// but take care that we don't make it longer than the document
length = Math.Min(1, document.TextLength - offset);
}
TextLocation start = document.GetLocation(offset);

8
src/Main/Base/Project/Src/Services/Tasks/ErrorPainter.cs

@ -206,10 +206,10 @@ namespace ICSharpCode.SharpDevelop @@ -206,10 +206,10 @@ namespace ICSharpCode.SharpDevelop
if (endOffset < 0) endOffset = textEditor.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, textEditor.Document.TextLength - offset);
if (length < 1) {
// marker should be at least 1 characters long,
// but take care that we don't make it longer than the document
length = Math.Min(1, textEditor.Document.TextLength - offset);
}
ITextMarker marker = this.markerService.Create(offset, length);

Loading…
Cancel
Save