(call: FunctionCallExpression)
| 693 | } |
| 694 | |
| 695 | private evaluateFunctionCall(call: FunctionCallExpression): Value { |
| 696 | const assertPassed = () => { |
| 697 | return int(0); |
| 698 | }; |
| 699 | const assertFailed = (msg: string) => { |
| 700 | // TODO: Include file & line |
| 701 | this.errors.push(msg); |
| 702 | return int(1); |
| 703 | }; |
| 704 | |
| 705 | const getpos = (arg: string) => { |
| 706 | const pos: Position | undefined = (() => { |
| 707 | if (arg === '.') { |
| 708 | return this.vimState!.cursorStopPosition; |
| 709 | } else if (arg === '$') { |
| 710 | return new Position(this.vimState!.document.lineCount, 0); |
| 711 | } else if (arg.startsWith("'") && arg.length === 2) { |
| 712 | const mark = this.vimState!.historyTracker.getMark(arg[1]); |
| 713 | return mark?.position; |
| 714 | } else if (arg === 'w0') { |
| 715 | return new Position(this.vimState!.editor.visibleRanges[0].start.line, 0); |
| 716 | } else if (arg === 'w$') { |
| 717 | return new Position(this.vimState!.editor.visibleRanges[0].end.line, 0); |
| 718 | } else if (arg === 'v') { |
| 719 | return this.vimState!.cursorStartPosition; |
| 720 | } |
| 721 | return undefined; |
| 722 | })(); |
| 723 | return { |
| 724 | bufnum: 0, // TODO |
| 725 | lnum: (pos?.line ?? -1) + 1, |
| 726 | col: (pos?.character ?? -1) + 1, |
| 727 | off: 0, |
| 728 | }; |
| 729 | }; |
| 730 | |
| 731 | // See `:help non-zero-arg` |
| 732 | const nonZeroArg = (arg: Value): boolean => { |
| 733 | if (arg.type === 'number' && arg.value !== 0) { |
| 734 | return true; |
| 735 | } else if (arg.type === 'string' && arg.value.length !== 0) { |
| 736 | return true; |
| 737 | } |
| 738 | return false; |
| 739 | }; |
| 740 | |
| 741 | const copy = (arg: Value, deep: boolean): Value => { |
| 742 | switch (arg.type) { |
| 743 | case 'list': |
| 744 | return list(deep ? arg.items.map((item) => copy(item, true)) : arg.items); |
| 745 | case 'dictionary': |
| 746 | return dictionary( |
| 747 | new Map(deep ? [...arg.items].map(([k, v]) => [k, copy(v, true)]) : arg.items), |
| 748 | ); |
| 749 | } |
| 750 | return arg; |
| 751 | }; |
| 752 |
no test coverage detected