Skip to content

Commit

Permalink
feat(command line): add a configurable completion timer delay (#1467)
Browse files Browse the repository at this point in the history
* feat: add a configurable completion timer delay

* refactor(command-line): Adjusted completion delay to match existing settings flow
  • Loading branch information
dyl10s committed Sep 20, 2023
1 parent e9928c8 commit 0cb897c
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 9 deletions.
8 changes: 7 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,12 @@
"title": "Neovim width",
"description": "Neovim viewport width. Increase if you're working with long lines and have horizontal scroll problems. Larger values will affect neovim performance"
},
"vscode-neovim.completionDelay": {
"type": "number",
"default": 1500,
"title": "Completion Delay",
"description": "The delay in ms until the wildmenu completions are shown. This is to not bother you when you write :w or :noh."
},
"vscode-neovim.neovimViewportHeightExtend": {
"type": "number",
"default": 1,
Expand Down Expand Up @@ -1295,4 +1301,4 @@
"ts-wcwidth": "^2.0.3",
"neovim": "^4.9.0"
}
}
}
10 changes: 8 additions & 2 deletions src/command_line.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export class CommandLineController implements Disposable {
private logger: Logger,
private client: NeovimClient,
private callbacks: CommandLineCallbacks,
private completionDelay: number,
) {
this.callbacks = callbacks;
this.input = window.createQuickPick();
Expand All @@ -63,11 +64,16 @@ export class CommandLineController implements Disposable {
if (content) {
this.input.value = content;
}
// Display completions only after 1.5secons, so it won't bother for simple things like ":w" or ":noh"
// Display completions only after a configurable amount of time (1.5s default), so it won't bother for simple things like ":w" or ":noh"
this.completionAllowed = false;
this.completionItems = [];
this.input.items = [];
this.completionTimer = setTimeout(this.processCompletionTimer, 1500);

if (this.completionDelay === 0) {
this.processCompletionTimer();
} else {
this.completionTimer = setTimeout(this.processCompletionTimer, this.completionDelay);
}
} else {
const newTitle = prompt || this.getTitle(mode);
if (newTitle !== this.input.title) {
Expand Down
16 changes: 11 additions & 5 deletions src/command_line_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export class CommandLineManager implements Disposable, NeovimRedrawProcessable {
public constructor(
private logger: Logger,
private client: NeovimClient,
private completionDelay: number,
) {}

public dispose(): void {
Expand Down Expand Up @@ -91,11 +92,16 @@ export class CommandLineManager implements Disposable, NeovimRedrawProcessable {

private showCmd = (content: string, firstc: string, prompt: string): void => {
if (!this.commandLine) {
this.commandLine = new CommandLineController(this.logger, this.client, {
onAccepted: this.onCmdAccept,
onCanceled: this.onCmdCancel,
onChanged: this.onCmdChange,
});
this.commandLine = new CommandLineController(
this.logger,
this.client,
{
onAccepted: this.onCmdAccept,
onCanceled: this.onCmdCancel,
onChanged: this.onCmdChange,
},
this.completionDelay,
);
}
this.commandLine.show(content, firstc, prompt);
};
Expand Down
2 changes: 2 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>
const useWsl = isWindows && settings.get("useWSL", false);
const revealCursorScrollLine = settings.get("revealCursorScrollLine", false);
const neovimWidth = settings.get("neovimWidth", 1000);
const completionDelay = settings.get("completionDelay", 1500);
const neovimViewportHeightExtend = settings.get("neovimViewportHeightExtend", 1);
const customInit = getNeovimInitPath() ?? "";
const clean = settings.get("neovimClean", false);
Expand All @@ -43,6 +44,7 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>
neovimViewportWidth: neovimWidth,
neovimViewportHeightExtend: neovimViewportHeightExtend,
revealCursorScrollLine: revealCursorScrollLine,
completionDelay: completionDelay,
logConf: {
logPath,
outputToConsole,
Expand Down
3 changes: 2 additions & 1 deletion src/main_controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export interface ControllerSettings {
neovimViewportWidth: number;
neovimViewportHeightExtend: number;
revealCursorScrollLine: boolean;
completionDelay: number;
logConf: {
level: "none" | "error" | "warn" | "debug";
logPath: string;
Expand Down Expand Up @@ -214,7 +215,7 @@ export class MainController implements vscode.Disposable {
this.typingManager = new TypingManager(this.logger, this.client, this);
this.disposables.push(this.typingManager);

this.commandLineManager = new CommandLineManager(this.logger, this.client);
this.commandLineManager = new CommandLineManager(this.logger, this.client, this.settings.completionDelay);
this.disposables.push(this.commandLineManager);

this.statusLineManager = new StatusLineManager(this.logger, this.client);
Expand Down

0 comments on commit 0cb897c

Please sign in to comment.