Skip to content

Commit c3dd400

Browse files
authored
Fix the remaining dependency cycles. (#7483)
Fixes #6177
1 parent 63bb909 commit c3dd400

File tree

13 files changed

+82
-35
lines changed

13 files changed

+82
-35
lines changed

extensionBase.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { taskQueue } from './src/taskQueue';
1717
import { Register } from './src/register/register';
1818
import { SpecialKeys } from './src/util/specialKeys';
1919
import { HistoryTracker } from './src/history/historyTracker';
20+
import { exCommandParser } from './src/vimscript/exCommandParser';
2021

2122
let extensionContext: vscode.ExtensionContext;
2223
let previousActiveEditorUri: vscode.Uri | undefined;
@@ -97,6 +98,8 @@ async function loadConfiguration() {
9798
* The extension's entry point
9899
*/
99100
export async function activate(context: vscode.ExtensionContext, handleLocal: boolean = true) {
101+
ExCommandLine.parser = exCommandParser;
102+
100103
// before we do anything else, we need to load the configuration
101104
await loadConfiguration();
102105

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1196,6 +1196,7 @@
11961196
"@types/source-map-support": "0.5.6",
11971197
"@types/vscode": "1.67.0",
11981198
"@vscode/test-electron": "2.2.0",
1199+
"circular-dependency-plugin": "^5.2.2",
11991200
"clean-webpack-plugin": "4.0.0",
12001201
"event-stream": "4.0.1",
12011202
"fork-ts-checker-webpack-plugin": "7.2.13",

src/actions/base.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import { VimState } from './../state/vimState';
1010
export abstract class BaseAction implements IBaseAction {
1111
abstract readonly actionType: ActionType;
1212

13+
public name = '';
14+
1315
/**
1416
* If true, the cursor position will be added to the jump list on completion.
1517
*/

src/actions/commands/actions.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ import { shouldWrapKey } from '../wrapping';
3434
import { ErrorCode, VimError } from '../../error';
3535
import { SearchDirection } from '../../vimscript/pattern';
3636
import { doesFileExist } from 'platform/fs';
37-
import { exCommandParser } from '../../vimscript/exCommandParser';
3837

3938
/**
4039
* A very special snowflake.
@@ -231,6 +230,7 @@ class EnableExtension extends BaseCommand {
231230
export class CommandNumber extends BaseCommand {
232231
modes = [Mode.Normal, Mode.Visual, Mode.VisualLine, Mode.VisualBlock];
233232
keys = ['<number>'];
233+
override name = 'cmd_num';
234234
override isCompleteAction = false;
235235
override actionType = 'number' as const;
236236
override runsOnceForEveryCursor() {
@@ -289,6 +289,7 @@ export class CommandNumber extends BaseCommand {
289289
export class CommandRegister extends BaseCommand {
290290
modes = [Mode.Normal, Mode.Visual, Mode.VisualLine, Mode.VisualBlock];
291291
keys = ['"', '<character>'];
292+
override name = 'cmd_register';
292293
override isCompleteAction = false;
293294

294295
public override async exec(position: Position, vimState: VimState): Promise<void> {
@@ -640,6 +641,10 @@ export class CommandShowCommandHistory extends BaseCommand {
640641
}
641642
}
642643

644+
ExCommandLine.onSearch = async (vimState: VimState) => {
645+
new CommandShowCommandHistory().exec(vimState.cursorStopPosition, vimState);
646+
};
647+
643648
@RegisterAction
644649
export class CommandShowSearchHistory extends BaseCommand {
645650
modes = [Mode.Normal, Mode.Visual, Mode.VisualLine, Mode.VisualBlock];
@@ -690,6 +695,11 @@ export class CommandShowSearchHistory extends BaseCommand {
690695
}
691696
}
692697

698+
// Register the command to execute on CtrlF.
699+
SearchCommandLine.onSearch = async (vimState: VimState, direction: SearchDirection) => {
700+
return new CommandShowSearchHistory(direction).exec(vimState.cursorStopPosition, vimState);
701+
};
702+
693703
@RegisterAction
694704
class CommandDot extends BaseCommand {
695705
modes = [Mode.Normal];
@@ -718,7 +728,7 @@ class CommandRepeatSubstitution extends BaseCommand {
718728
public override async exec(position: Position, vimState: VimState): Promise<void> {
719729
// Parsing the command from a string, while not ideal, is currently
720730
// necessary to make this work with and without neovim integration
721-
await exCommandParser.tryParse('s').command.execute(vimState);
731+
await ExCommandLine.parser.tryParse('s').command.execute(vimState);
722732
}
723733
}
724734

@@ -843,6 +853,7 @@ class CommandDeleteToLineEnd extends BaseCommand {
843853
export class CommandYankFullLine extends BaseCommand {
844854
modes = [Mode.Normal];
845855
keys = ['Y'];
856+
override name = 'yank_full_line';
846857

847858
public override async exec(position: Position, vimState: VimState): Promise<void> {
848859
const linesDown = (vimState.recordedState.count || 1) - 1;
@@ -1334,6 +1345,7 @@ class CommandTabPrevious extends BaseCommand {
13341345
export class ActionDeleteChar extends BaseCommand {
13351346
modes = [Mode.Normal];
13361347
keys = ['x'];
1348+
override name = 'delete_char';
13371349
override createsUndoPoint = true;
13381350

13391351
public override async exec(position: Position, vimState: VimState): Promise<void> {
@@ -1358,6 +1370,7 @@ export class ActionDeleteChar extends BaseCommand {
13581370
export class ActionDeleteCharWithDeleteKey extends BaseCommand {
13591371
modes = [Mode.Normal];
13601372
keys = ['<Del>'];
1373+
override name = 'delete_char_with_del';
13611374
override runsOnceForEachCountPrefix = true;
13621375
override createsUndoPoint = true;
13631376

@@ -1382,6 +1395,7 @@ export class ActionDeleteCharWithDeleteKey extends BaseCommand {
13821395
export class ActionDeleteLastChar extends BaseCommand {
13831396
modes = [Mode.Normal];
13841397
keys = ['X'];
1398+
override name = 'delete_last_char';
13851399
override createsUndoPoint = true;
13861400

13871401
public override async exec(position: Position, vimState: VimState): Promise<void> {
@@ -2116,6 +2130,7 @@ class ActionGoToInsertVisualBlockModeAppend extends BaseCommand {
21162130
export class ActionDeleteCharVisualLineMode extends BaseCommand {
21172131
modes = [Mode.VisualLine];
21182132
keys = ['x'];
2133+
override name = 'delete_char_visual_line_mode';
21192134

21202135
public override async exec(position: Position, vimState: VimState): Promise<void> {
21212136
const [start, end] = sorted(vimState.cursorStartPosition, vimState.cursorStopPosition);

src/actions/commands/commandLine.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,15 @@ class CommandLineEscape extends CommandLineAction {
184184
}
185185
}
186186

187+
@RegisterAction
188+
class CommandLineCtrlF extends CommandLineAction {
189+
keys = ['<C-f>'];
190+
191+
protected override async run(vimState: VimState, commandLine: CommandLine): Promise<void> {
192+
await commandLine.ctrlF(vimState);
193+
}
194+
}
195+
187196
@RegisterAction
188197
class CommandLineBackspace extends CommandLineAction {
189198
keys = [['<BS>'], ['<S-BS>'], ['<C-h>']];

src/actions/operator.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import { Register, RegisterMode } from './../register/register';
77
import { VimState } from './../state/vimState';
88
import { TextEditor } from './../textEditor';
99
import { BaseAction, RegisterAction } from './base';
10-
import { CommandNumber } from './commands/actions';
1110
import { reportLinesChanged, reportLinesYanked } from '../util/statusBarTextUtils';
1211
import { ExCommandLine } from './../cmd_line/commandLine';
1312
import { Position } from 'vscode';
@@ -55,9 +54,7 @@ export abstract class BaseOperator extends BaseAction {
5554
}
5655

5756
public doesRepeatedOperatorApply(vimState: VimState, keysPressed: string[]) {
58-
const nonCountActions = vimState.recordedState.actionsRun.filter(
59-
(x) => !(x instanceof CommandNumber)
60-
);
57+
const nonCountActions = vimState.recordedState.actionsRun.filter((x) => x.name !== 'cmd_num');
6158
const prevAction = nonCountActions[nonCountActions.length - 1];
6259
return (
6360
keysPressed.length === 1 &&
@@ -101,6 +98,7 @@ export abstract class BaseOperator extends BaseAction {
10198

10299
@RegisterAction
103100
export class DeleteOperator extends BaseOperator {
101+
public override name = 'delete_op';
104102
public keys = ['d'];
105103
public modes = [Mode.Normal, Mode.Visual, Mode.VisualLine];
106104

@@ -188,6 +186,7 @@ class DeleteOperatorVisual extends BaseOperator {
188186
export class YankOperator extends BaseOperator {
189187
public keys = ['y'];
190188
public modes = [Mode.Normal, Mode.Visual, Mode.VisualLine];
189+
override name = 'yank_op';
191190
override createsUndoPoint = false;
192191

193192
public async run(vimState: VimState, start: Position, end: Position): Promise<void> {

src/actions/types.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ import type { VimState } from '../state/vimState';
44
export type ActionType = 'command' | 'motion' | 'operator' | 'number';
55

66
export interface IBaseAction {
7-
readonly actionType: ActionType
7+
name: string;
8+
readonly actionType: ActionType;
89
readonly isJump: boolean;
910
readonly createsUndoPoint: boolean;
1011

src/cmd_line/commandLine.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,9 @@ import { VimState } from '../state/vimState';
77
import { configuration } from '../configuration/configuration';
88
import { Register } from '../register/register';
99
import { RecordedState } from '../state/recordedState';
10-
import { exCommandParser } from '../vimscript/exCommandParser';
10+
import { Parser } from 'parsimmon';
1111
import { IndexedPosition, IndexedRange, SearchState } from '../state/searchState';
1212
import { getWordLeftInText, getWordRightInText, WordType } from '../textobject/word';
13-
import { CommandShowCommandHistory, CommandShowSearchHistory } from '../actions/commands/actions';
1413
import { SearchDirection } from '../vimscript/pattern';
1514
import { reportSearch, escapeCSSIcons } from '../util/statusBarTextUtils';
1615
import { SearchDecorations, getDecorationsForSearchMatchRanges } from '../util/decorationUtils';
@@ -190,6 +189,8 @@ export abstract class CommandLine {
190189

191190
export class ExCommandLine extends CommandLine {
192191
static history: CommandLineHistory;
192+
static parser: Parser<{ lineRange: LineRange | undefined; command: ExCommand }>;
193+
static onSearch: (vimState: VimState) => Promise<void>;
193194

194195
public static async loadHistory(context: ExtensionContext): Promise<void> {
195196
ExCommandLine.history = new CommandLineHistory(context);
@@ -231,7 +232,7 @@ export class ExCommandLine extends CommandLine {
231232

232233
try {
233234
// TODO: This eager parsing is costly, and if it's not `:s` or similar, don't need to parse the args at all
234-
const { lineRange, command } = exCommandParser.tryParse(this.commandText);
235+
const { lineRange, command } = ExCommandLine.parser.tryParse(this.commandText);
235236
this.lineRange = lineRange;
236237
this.command = command;
237238
} catch (err) {
@@ -270,7 +271,7 @@ export class ExCommandLine extends CommandLine {
270271
try {
271272
if (this.command === undefined) {
272273
// TODO: A bit gross:
273-
exCommandParser.tryParse(this.text);
274+
ExCommandLine.parser.tryParse(this.text);
274275
throw new Error(`Expected parsing ExCommand '${this.text}' to fail`);
275276
}
276277

@@ -314,13 +315,14 @@ export class ExCommandLine extends CommandLine {
314315
}
315316

316317
public async ctrlF(vimState: VimState): Promise<void> {
317-
new CommandShowCommandHistory().exec(vimState.cursorStopPosition, vimState);
318+
ExCommandLine.onSearch(vimState);
318319
}
319320
}
320321

321322
export class SearchCommandLine extends CommandLine {
322323
public static history: SearchHistory;
323324
public static readonly previousSearchStates: SearchState[] = [];
325+
public static onSearch: (vimState: VimState, direction: SearchDirection) => Promise<void>;
324326

325327
/**
326328
* Shows the search history as a QuickPick (popup list)
@@ -525,10 +527,7 @@ export class SearchCommandLine extends CommandLine {
525527
}
526528

527529
public async ctrlF(vimState: VimState): Promise<void> {
528-
await new CommandShowSearchHistory(this.searchState.direction).exec(
529-
vimState.cursorStopPosition,
530-
vimState
531-
);
530+
await SearchCommandLine.onSearch(vimState, this.searchState.direction);
532531
}
533532

534533
/**

src/configuration/configuration.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import {
2121
import * as packagejson from '../../package.json';
2222
import { SUPPORT_VIMRC } from 'platform/constants';
2323

24-
// https://stackovrflow.com/questions/51465182/how-to-remove-index-signature-using-mapped-types/51956054#51956054
24+
// https://stackoverflow.com/questions/51465182/how-to-remove-index-signature-using-mapped-types/51956054#51956054
2525
type RemoveIndex<T> = {
2626
[P in keyof T as string extends P ? never : number extends P ? never : P]: T[P];
2727
};

src/configuration/vimrc.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import * as vscode from 'vscode';
66
import { IConfiguration, IVimrcKeyRemapping } from './iconfiguration';
77
import { vimrcKeyRemappingBuilder } from './vimrcKeyRemappingBuilder';
88
import { window } from 'vscode';
9-
import { configuration } from './configuration';
109
import { Logger } from '../util/logger';
1110

1211
export class VimrcImpl {
@@ -92,7 +91,13 @@ export class VimrcImpl {
9291
});
9392
if (newVimrc) {
9493
await fs.writeFileAsync(newVimrc.fsPath, '', 'utf-8');
95-
configuration.getConfiguration('vim').update('vimrc.path', newVimrc.fsPath, true);
94+
const document = vscode.window.activeTextEditor?.document;
95+
const resource = document
96+
? { uri: document.uri, languageId: document.languageId }
97+
: undefined;
98+
vscode.workspace
99+
.getConfiguration('vim', resource)
100+
.update('vimrc.path', newVimrc.fsPath, true);
96101
await vscode.workspace.openTextDocument(newVimrc);
97102
// TODO: add some sample remaps/settings in here?
98103
await vscode.window.showTextDocument(newVimrc);

0 commit comments

Comments
 (0)