MCPcopy Index your code
hub / github.com/VSCodeVim/Vim / evaluateIndex

Method evaluateIndex

src/vimscript/expression/evaluate.ts:402–434  ·  view source on GitHub ↗
(sequence: Value, index: Value)

Source from the content-addressed store, hash-verified

400 }
401
402 private evaluateIndex(sequence: Value, index: Value): Value {
403 switch (sequence.type) {
404 case 'string':
405 case 'number':
406 case 'float': {
407 const idx = toInt(index);
408 return str(idx >= 0 ? (toString(sequence)[idx] ?? '') : '');
409 }
410 case 'list': {
411 let idx = toInt(index);
412 idx = idx < 0 ? sequence.items.length - idx : idx;
413 if (idx < 0 || idx >= sequence.items.length) {
414 throw VimError.ListIndexOutOfRange(idx);
415 }
416 return sequence.items[idx];
417 }
418 case 'dictionary': {
419 const key = toString(index);
420 const result = sequence.items.get(key);
421 if (result === undefined) {
422 throw VimError.KeyNotPresentInDictionary(key);
423 }
424 return result;
425 }
426 case 'funcref': {
427 throw VimError.CannotIndexAFuncref();
428 }
429 case 'blob': {
430 const bytes = new Uint8Array(sequence.data);
431 return int(bytes[toInt(index)]);
432 }
433 }
434 }
435
436 private evaluateSlice(sequence: Value, start: Value, end: Value): Value {
437 let _start = toInt(start);

Callers 1

evaluateMethod · 0.95

Calls 8

strFunction · 0.90
intFunction · 0.90
toIntFunction · 0.85
ListIndexOutOfRangeMethod · 0.80
CannotIndexAFuncrefMethod · 0.80
toStringFunction · 0.70
getMethod · 0.65

Tested by

no test coverage detected