@@ -26,6 +26,7 @@ import {
26
26
Expression ,
27
27
OptionExpression ,
28
28
RegisterExpression ,
29
+ Value ,
29
30
VariableExpression ,
30
31
} from '../../vimscript/expression/types' ;
31
32
import { displayValue } from '../../vimscript/expression/displayValue' ;
@@ -175,27 +176,27 @@ export class LetCommand extends ExCommand {
175
176
}
176
177
177
178
const value = context . evaluate ( this . args . expression ) ;
178
- const newValue = ( _var : Expression ) => {
179
+ const newValue = ( _var : Expression , _value : Value ) => {
179
180
if ( this . args . operation === '+=' ) {
180
- return context . evaluate ( add ( _var , value ) ) ;
181
+ return context . evaluate ( add ( _var , _value ) ) ;
181
182
} else if ( this . args . operation === '-=' ) {
182
- return context . evaluate ( subtract ( _var , value ) ) ;
183
+ return context . evaluate ( subtract ( _var , _value ) ) ;
183
184
} else if ( this . args . operation === '*=' ) {
184
- return context . evaluate ( multiply ( _var , value ) ) ;
185
+ return context . evaluate ( multiply ( _var , _value ) ) ;
185
186
} else if ( this . args . operation === '/=' ) {
186
- return context . evaluate ( divide ( _var , value ) ) ;
187
+ return context . evaluate ( divide ( _var , _value ) ) ;
187
188
} else if ( this . args . operation === '%=' ) {
188
- return context . evaluate ( modulo ( _var , value ) ) ;
189
+ return context . evaluate ( modulo ( _var , _value ) ) ;
189
190
} else if ( this . args . operation === '.=' ) {
190
- return context . evaluate ( concat ( _var , value ) ) ;
191
+ return context . evaluate ( concat ( _var , _value ) ) ;
191
192
} else if ( this . args . operation === '..=' ) {
192
- return context . evaluate ( concat ( _var , value ) ) ;
193
+ return context . evaluate ( concat ( _var , _value ) ) ;
193
194
}
194
- return value ;
195
+ return _value ;
195
196
} ;
196
197
197
198
if ( variable . type === 'variable' ) {
198
- context . setVariable ( variable , newValue ( variable ) , this . args . lock ) ;
199
+ context . setVariable ( variable , newValue ( variable , value ) , this . args . lock ) ;
199
200
} else if ( variable . type === 'register' ) {
200
201
// TODO
201
202
} else if ( variable . type === 'option' ) {
@@ -213,28 +214,34 @@ export class LetCommand extends ExCommand {
213
214
if ( variable . names . length > value . items . length ) {
214
215
throw VimError . fromCode ( ErrorCode . MoreTargetsThanListItems ) ;
215
216
}
216
- for ( const name of variable . names ) {
217
+ for ( const [ i , name ] of variable . names . entries ( ) ) {
217
218
const item : VariableExpression = { type : 'variable' , namespace : undefined , name } ;
218
- context . setVariable ( item , newValue ( item ) , this . args . lock ) ;
219
+ context . setVariable ( item , newValue ( item , value . items [ i ] ) , this . args . lock ) ;
219
220
}
220
221
} else if ( variable . type === 'index' ) {
221
222
const varValue = context . evaluate ( variable . variable ) ;
222
223
if ( varValue . type === 'list' ) {
223
224
const idx = toInt ( context . evaluate ( variable . index ) ) ;
224
- const newItem = newValue ( {
225
- type : 'index' ,
226
- expression : variable . variable ,
227
- index : int ( idx ) ,
228
- } ) ;
225
+ const newItem = newValue (
226
+ {
227
+ type : 'index' ,
228
+ expression : variable . variable ,
229
+ index : int ( idx ) ,
230
+ } ,
231
+ value ,
232
+ ) ;
229
233
varValue . items [ idx ] = newItem ;
230
234
context . setVariable ( variable . variable , varValue , this . args . lock ) ;
231
235
} else if ( varValue . type === 'dict_val' ) {
232
236
const key = toString ( context . evaluate ( variable . index ) ) ;
233
- const newItem = newValue ( {
234
- type : 'entry' ,
235
- expression : variable . variable ,
236
- entryName : key ,
237
- } ) ;
237
+ const newItem = newValue (
238
+ {
239
+ type : 'entry' ,
240
+ expression : variable . variable ,
241
+ entryName : key ,
242
+ } ,
243
+ value ,
244
+ ) ;
238
245
varValue . items . set ( key , newItem ) ;
239
246
context . setVariable ( variable . variable , varValue , this . args . lock ) ;
240
247
} else {
0 commit comments