@@ -45,7 +45,7 @@ export class FileIndexer {
45
45
if ( symbol . isEmpty ( ) ) {
46
46
return
47
47
}
48
- this . document . occurrences . push (
48
+ this . pushOccurrence (
49
49
new scip . scip . Occurrence ( {
50
50
range : [ 0 , 0 , 0 ] ,
51
51
symbol : symbol . value ,
@@ -111,7 +111,7 @@ export class FileIndexer {
111
111
// Skip empty symbols
112
112
continue
113
113
}
114
- this . document . occurrences . push (
114
+ this . pushOccurrence (
115
115
new scip . scip . Occurrence ( {
116
116
range,
117
117
symbol : scipSymbol . value ,
@@ -153,7 +153,7 @@ export class FileIndexer {
153
153
if ( scipSymbol . isEmpty ( ) ) {
154
154
continue
155
155
}
156
- this . document . occurrences . push (
156
+ this . pushOccurrence (
157
157
new scip . scip . Occurrence ( {
158
158
range,
159
159
symbol : scipSymbol . value ,
@@ -190,7 +190,7 @@ export class FileIndexer {
190
190
if ( scipSymbol . isEmpty ( ) ) {
191
191
continue
192
192
}
193
- this . document . occurrences . push (
193
+ this . pushOccurrence (
194
194
new scip . scip . Occurrence ( {
195
195
range,
196
196
symbol : scipSymbol . value ,
@@ -227,6 +227,17 @@ export class FileIndexer {
227
227
)
228
228
}
229
229
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
+
230
241
private relationships (
231
242
declaration : ts . Node ,
232
243
declarationSymbol : ScipSymbol
@@ -673,3 +684,26 @@ function scriptElementKind(
673
684
}
674
685
return ts . ScriptElementKind . unknown
675
686
}
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