@@ -33,9 +33,11 @@ export class Encoder {
33
33
readonly #scopeState = { ...DEFAULT_SCOPE_STATE } ;
34
34
readonly #rangeState = { ...DEFAULT_RANGE_STATE } ;
35
35
#encodedItems: string [ ] = [ ] ;
36
-
37
36
#currentItem: string = "" ;
38
37
38
+ #scopeToCount = new Map < OriginalScope , number > ( ) ;
39
+ #scopeCounter = 0 ;
40
+
39
41
constructor ( info : ScopeInfo , names : string [ ] ) {
40
42
this . #info = info ;
41
43
this . #names = names ;
@@ -98,6 +100,8 @@ export class Encoder {
98
100
if ( encodedName !== undefined ) this . #encodeSigned( encodedName ) ;
99
101
if ( encodedKind !== undefined ) this . #encodeSigned( encodedKind ) ;
100
102
this . #finishItem( ) ;
103
+
104
+ this . #scopeToCount. set ( scope , this . #scopeCounter++ ) ;
101
105
}
102
106
103
107
#encodeOriginalScopeEnd( scope : OriginalScope ) {
@@ -134,9 +138,24 @@ export class Encoder {
134
138
this . #rangeState. line = line ;
135
139
this . #rangeState. column = column ;
136
140
141
+ let encodedDefinition ;
142
+ if ( range . originalScope ) {
143
+ const definitionIdx = this . #scopeToCount. get ( range . originalScope ) ;
144
+ if ( definitionIdx === undefined ) {
145
+ throw new Error ( "Unknown OriginalScope for definition!" ) ;
146
+ }
147
+
148
+ flags |= GeneratedRangeFlags . HAS_DEFINITION ;
149
+
150
+ encodedDefinition = definitionIdx - this . #rangeState. defScopeIdx ;
151
+ this . #rangeState. defScopeIdx = definitionIdx ;
152
+ }
153
+
137
154
this . #encodeTag( EncodedTag . GENERATED_RANGE_START ) . #encodeUnsigned( flags ) ;
138
155
if ( encodedLine > 0 ) this . #encodeUnsigned( encodedLine ) ;
139
- this . #encodeUnsigned( encodedColumn ) . #finishItem( ) ;
156
+ this . #encodeUnsigned( encodedColumn ) ;
157
+ if ( encodedDefinition !== undefined ) this . #encodeSigned( encodedDefinition ) ;
158
+ this . #finishItem( ) ;
140
159
}
141
160
142
161
#encodeGeneratedRangeEnd( range : GeneratedRange ) {
0 commit comments