@@ -39,13 +39,26 @@ public override IEnumerable<CodeIssue> GetIssues(BaseRefactoringContext context,
3939 {
4040 var refactoringContext = context as SDRefactoringContext ;
4141 if ( refactoringContext == null )
42- return Enumerable . Empty < CodeIssue > ( ) ;
42+ yield break ;
4343
4444 var syntaxTree = context . RootNode as SyntaxTree ;
4545 if ( syntaxTree == null )
46- return Enumerable . Empty < CodeIssue > ( ) ;
47-
48- return syntaxTree . Errors . Select ( error => CreateCodeIssue ( error , refactoringContext ) ) . Where ( issue => issue != null ) ;
46+ yield break ;
47+
48+ int prevLine = 0 ;
49+ foreach ( var error in syntaxTree . Errors ) {
50+ if ( error . Region . BeginLine == prevLine )
51+ continue ; // show at most one error per line
52+ prevLine = error . Region . BeginLine ;
53+ var issue = CreateCodeIssue ( error , refactoringContext ) ;
54+ if ( issue != null )
55+ yield return issue ;
56+ }
57+ }
58+
59+ static bool IsSpaceOrTab ( char c )
60+ {
61+ return c == ' ' || c == '\t ' ;
4962 }
5063
5164 CodeIssue CreateCodeIssue ( Error error , SDRefactoringContext context )
@@ -55,16 +68,18 @@ CodeIssue CreateCodeIssue(Error error, SDRefactoringContext context)
5568 if ( begin . Line <= 0 || begin . Line > document . LineCount )
5669 return null ;
5770
58- // Columns seem to be zero-based, SD expects 1-based columns
59- int offset = document . GetOffset ( begin . Line , begin . Column + 1 ) ;
71+ int offset = document . GetOffset ( begin . Line , begin . Column ) ;
72+ // the parser sometimes reports errors in the whitespace prior to the invalid token, so search for the next word:
73+ while ( offset < document . TextLength && IsSpaceOrTab ( document . GetCharAt ( offset ) ) )
74+ offset ++ ;
6075 int endOffset = TextUtilities . GetNextCaretPosition ( document , offset , System . Windows . Documents . LogicalDirection . Forward , CaretPositioningMode . WordBorderOrSymbol ) ;
6176 if ( endOffset < 0 ) endOffset = document . TextLength ;
6277 int length = endOffset - offset ;
63-
64- if ( length < 2 ) {
65- // marker should be at least 2 characters long, but take care that we don't make
66- // it longer than the document
67- length = Math . Min ( 2 , document . TextLength - offset ) ;
78+
79+ if ( length < 1 ) {
80+ // marker should be at least 1 characters long,
81+ // but take care that we don't make it longer than the document
82+ length = Math . Min ( 1 , document . TextLength - offset ) ;
6883 }
6984
7085 TextLocation start = document . GetLocation ( offset ) ;
0 commit comments