@@ -45,7 +45,7 @@ export class FileIndexer {
4545 if ( symbol . isEmpty ( ) ) {
4646 return
4747 }
48- this . document . occurrences . push (
48+ this . pushOccurrence (
4949 new scip . scip . Occurrence ( {
5050 range : [ 0 , 0 , 0 ] ,
5151 symbol : symbol . value ,
@@ -111,7 +111,7 @@ export class FileIndexer {
111111 // Skip empty symbols
112112 continue
113113 }
114- this . document . occurrences . push (
114+ this . pushOccurrence (
115115 new scip . scip . Occurrence ( {
116116 range,
117117 symbol : scipSymbol . value ,
@@ -153,7 +153,7 @@ export class FileIndexer {
153153 if ( scipSymbol . isEmpty ( ) ) {
154154 continue
155155 }
156- this . document . occurrences . push (
156+ this . pushOccurrence (
157157 new scip . scip . Occurrence ( {
158158 range,
159159 symbol : scipSymbol . value ,
@@ -190,7 +190,7 @@ export class FileIndexer {
190190 if ( scipSymbol . isEmpty ( ) ) {
191191 continue
192192 }
193- this . document . occurrences . push (
193+ this . pushOccurrence (
194194 new scip . scip . Occurrence ( {
195195 range,
196196 symbol : scipSymbol . value ,
@@ -227,6 +227,17 @@ export class FileIndexer {
227227 )
228228 }
229229
230+ private pushOccurrence ( occurrence : scip . scip . Occurrence ) : void {
231+ if ( this . document . occurrences . length > 0 ) {
232+ const lastOccurrence =
233+ this . document . occurrences [ this . document . occurrences . length - 1 ]
234+ if ( isEqualOccurrence ( lastOccurrence , occurrence ) ) {
235+ return
236+ }
237+ }
238+ this . document . occurrences . push ( occurrence )
239+ }
240+
230241 private relationships (
231242 declaration : ts . Node ,
232243 declarationSymbol : ScipSymbol
@@ -673,3 +684,26 @@ function scriptElementKind(
673684 }
674685 return ts . ScriptElementKind . unknown
675686}
687+
688+ function isEqualOccurrence (
689+ a : scip . scip . Occurrence ,
690+ b : scip . scip . Occurrence
691+ ) : boolean {
692+ return (
693+ a . symbol_roles === b . symbol_roles &&
694+ a . symbol === b . symbol &&
695+ isEqualArray ( a . range , b . range )
696+ )
697+ }
698+
699+ function isEqualArray < T > ( a : T [ ] , b : T [ ] ) : boolean {
700+ if ( a . length !== b . length ) {
701+ return false
702+ }
703+ for ( let index = 0 ; index < a . length ; index ++ ) {
704+ if ( a [ index ] !== b [ index ] ) {
705+ return false
706+ }
707+ }
708+ return true
709+ }
0 commit comments