Skip to content

Commit

Permalink
feat: warn on empty vscode-neovim.send args (#1455)
Browse files Browse the repository at this point in the history
* feat: warn on empty `vscode-neovim.send` args

* fix: escape command do not need this

* chore: tweak message

---------

Co-authored-by: Theo Lemay <theol0403@gmail.com>
  • Loading branch information
xiyaowong and theol0403 committed Sep 17, 2023
1 parent 237e795 commit d1cbcf9
Showing 1 changed file with 29 additions and 18 deletions.
47 changes: 29 additions & 18 deletions src/typing_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,26 +55,37 @@ export class TypingManager implements Disposable {
private client: NeovimClient,
private main: MainController,
) {
const warnOnEmptyKey = (method: (key: string) => Promise<void>): typeof method => {
return (key: string) => {
if (key) {
return method.apply(this, [key]);
} else {
const link =
"command:workbench.action.openGlobalKeybindings?" +
encodeURIComponent('["vscode-neovim.send"]');
window.showErrorMessage(
`No args provided to vscode-neovim.send. Please check your [keybinds](${link}) ` +
"to ensure that all send commands include the args parameter.",
);
return Promise.resolve();
}
};
};
this.registerType();
this.registerReplacePrevChar();
this.disposables.push(commands.registerCommand("vscode-neovim.send", this.onSendCommand));
this.disposables.push(commands.registerCommand("vscode-neovim.send-blocking", this.onSendBlockingCommand));
this.disposables.push(commands.registerCommand("vscode-neovim.escape", this.onEscapeKeyCommand));
this.disposables.push(commands.registerCommand("vscode-neovim.enable", () => this.onEnableCommand("enable")));
this.disposables.push(commands.registerCommand("vscode-neovim.disable", () => this.onEnableCommand("disable")));
this.disposables.push(commands.registerCommand("vscode-neovim.toggle", () => this.onEnableCommand("toggle")));
this.disposables.push(
commands.registerCommand("vscode-neovim.compositeEscape1", (key: string) =>
this.handleCompositeEscapeFirstKey(key),
),
);
this.disposables.push(
commands.registerCommand("vscode-neovim.compositeEscape2", (key: string) =>
this.handleCompositeEscapeSecondKey(key),
),
);
this.disposables.push(commands.registerCommand("compositionStart", this.onCompositionStart));
this.disposables.push(commands.registerCommand("compositionEnd", this.onCompositionEnd));
const registerCommand = (cmd: string, cb: (...args: any[]) => any) => {

Check warning on line 76 in src/typing_manager.ts

View workflow job for this annotation

GitHub Actions / Build & Test (macos-latest)

Missing return type on function

Check warning on line 76 in src/typing_manager.ts

View workflow job for this annotation

GitHub Actions / Build & Test (macos-latest)

Unexpected any. Specify a different type

Check warning on line 76 in src/typing_manager.ts

View workflow job for this annotation

GitHub Actions / Build & Test (macos-latest)

Unexpected any. Specify a different type

Check warning on line 76 in src/typing_manager.ts

View workflow job for this annotation

GitHub Actions / Build & Test (ubuntu-latest)

Missing return type on function

Check warning on line 76 in src/typing_manager.ts

View workflow job for this annotation

GitHub Actions / Build & Test (ubuntu-latest)

Unexpected any. Specify a different type

Check warning on line 76 in src/typing_manager.ts

View workflow job for this annotation

GitHub Actions / Build & Test (ubuntu-latest)

Unexpected any. Specify a different type

Check warning on line 76 in src/typing_manager.ts

View workflow job for this annotation

GitHub Actions / Build & Test (windows-latest)

Missing return type on function

Check warning on line 76 in src/typing_manager.ts

View workflow job for this annotation

GitHub Actions / Build & Test (windows-latest)

Unexpected any. Specify a different type

Check warning on line 76 in src/typing_manager.ts

View workflow job for this annotation

GitHub Actions / Build & Test (windows-latest)

Unexpected any. Specify a different type
this.disposables.push(commands.registerCommand(cmd, cb, this));
};
registerCommand("vscode-neovim.send", warnOnEmptyKey(this.onSendCommand));
registerCommand("vscode-neovim.send-blocking", warnOnEmptyKey(this.onSendBlockingCommand));
registerCommand("vscode-neovim.escape", this.onEscapeKeyCommand);
registerCommand("vscode-neovim.enable", () => this.onEnableCommand("enable"));
registerCommand("vscode-neovim.disable", () => this.onEnableCommand("disable"));
registerCommand("vscode-neovim.toggle", () => this.onEnableCommand("toggle"));
registerCommand("vscode-neovim.compositeEscape1", warnOnEmptyKey(this.handleCompositeEscapeFirstKey));
registerCommand("vscode-neovim.compositeEscape2", warnOnEmptyKey(this.handleCompositeEscapeSecondKey));
registerCommand("compositionStart", this.onCompositionStart);
registerCommand("compositionEnd", this.onCompositionEnd);
this.main.modeManager.onModeChange(this.onModeChange);
}

Expand Down

0 comments on commit d1cbcf9

Please sign in to comment.