Skip to content

Commit

Permalink
refactor taskqueue
Browse files Browse the repository at this point in the history
  • Loading branch information
jpoon committed Oct 13, 2017
1 parent 347f5ef commit 9b7c733
Show file tree
Hide file tree
Showing 6 changed files with 127 additions and 175 deletions.
11 changes: 1 addition & 10 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,8 @@
"taskName": "build",
"args": [],
"isBuildCommand": true,
"isWatching": false,
"problemMatcher": "$tsc-watch"
},

{
"taskName": "yolo",
"args": ["nothing"],
"isBuildCommand": true,
"isWatching": false,
"isBackground": false,
"problemMatcher": "$tsc-watch"
}

]
}
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2015 VSCode-Extension
Copyright (c) 2015 VSCodeVim

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
139 changes: 59 additions & 80 deletions extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,66 +213,54 @@ export async function activate(context: vscode.ExtensionContext) {
});

overrideCommand(context, 'type', async args => {
taskQueue.enqueueTask({
promise: async () => {
const mh = await getAndUpdateModeHandler();

if (compositionState.isInComposition) {
compositionState.composingText += args.text;
} else {
await mh.handleKeyEvent(args.text);
}
},
isRunning: false,
taskQueue.enqueueTask(async () => {
const mh = await getAndUpdateModeHandler();

if (compositionState.isInComposition) {
compositionState.composingText += args.text;
} else {
await mh.handleKeyEvent(args.text);
}
});
});

overrideCommand(context, 'replacePreviousChar', async args => {
taskQueue.enqueueTask({
promise: async () => {
const mh = await getAndUpdateModeHandler();

if (compositionState.isInComposition) {
compositionState.composingText =
compositionState.composingText.substr(
0,
compositionState.composingText.length - args.replaceCharCnt
) + args.text;
} else {
await vscode.commands.executeCommand('default:replacePreviousChar', {
text: args.text,
replaceCharCnt: args.replaceCharCnt,
});
mh.vimState.cursorPosition = Position.FromVSCodePosition(
mh.vimState.editor.selection.start
);
mh.vimState.cursorStartPosition = Position.FromVSCodePosition(
mh.vimState.editor.selection.start
);
}
},
isRunning: false,
taskQueue.enqueueTask(async () => {
const mh = await getAndUpdateModeHandler();

if (compositionState.isInComposition) {
compositionState.composingText =
compositionState.composingText.substr(
0,
compositionState.composingText.length - args.replaceCharCnt
) + args.text;
} else {
await vscode.commands.executeCommand('default:replacePreviousChar', {
text: args.text,
replaceCharCnt: args.replaceCharCnt,
});
mh.vimState.cursorPosition = Position.FromVSCodePosition(
mh.vimState.editor.selection.start
);
mh.vimState.cursorStartPosition = Position.FromVSCodePosition(
mh.vimState.editor.selection.start
);
}
});
});

overrideCommand(context, 'compositionStart', async args => {
taskQueue.enqueueTask({
promise: async () => {
compositionState.isInComposition = true;
},
isRunning: false,
taskQueue.enqueueTask(async () => {
compositionState.isInComposition = true;
});
});

overrideCommand(context, 'compositionEnd', async args => {
taskQueue.enqueueTask({
promise: async () => {
const mh = await getAndUpdateModeHandler();
let text = compositionState.composingText;
compositionState = new CompositionState();
await mh.handleMultipleKeyEvents(text.split(''));
},
isRunning: false,
taskQueue.enqueueTask(async () => {
const mh = await getAndUpdateModeHandler();
let text = compositionState.composingText;
compositionState = new CompositionState();
await mh.handleMultipleKeyEvents(text.split(''));
});
});

Expand All @@ -284,29 +272,26 @@ export async function activate(context: vscode.ExtensionContext) {
});

registerCommand(context, 'vim.remap', async (args: ICodeKeybinding) => {
taskQueue.enqueueTask({
promise: async () => {
const mh = await getAndUpdateModeHandler();
if (args.after) {
for (const key of args.after) {
await mh.handleKeyEvent(AngleBracketNotation.Normalize(key));
}
return;
taskQueue.enqueueTask(async () => {
const mh = await getAndUpdateModeHandler();
if (args.after) {
for (const key of args.after) {
await mh.handleKeyEvent(AngleBracketNotation.Normalize(key));
}
return;
}

if (args.commands) {
for (const command of args.commands) {
// Check if this is a vim command by looking for :
if (command.command.slice(0, 1) === ':') {
await runCmdLine(command.command.slice(1, command.command.length), mh);
await mh.updateView(mh.vimState);
} else {
await vscode.commands.executeCommand(command.command, command.args);
}
if (args.commands) {
for (const command of args.commands) {
// Check if this is a vim command by looking for :
if (command.command.slice(0, 1) === ':') {
await runCmdLine(command.command.slice(1, command.command.length), mh);
await mh.updateView(mh.vimState);
} else {
await vscode.commands.executeCommand(command.command, command.args);
}
}
},
isRunning: false,
}
});
});

Expand Down Expand Up @@ -447,11 +432,8 @@ function registerCommand(
async function handleKeyEvent(key: string): Promise<void> {
const mh = await getAndUpdateModeHandler();

taskQueue.enqueueTask({
promise: async () => {
await mh.handleKeyEvent(key);
},
isRunning: false,
taskQueue.enqueueTask(async () => {
await mh.handleKeyEvent(key);
});
}

Expand All @@ -474,15 +456,12 @@ async function handleActiveEditorChange(): Promise<void> {
return;
}

taskQueue.enqueueTask({
promise: async () => {
if (vscode.window.activeTextEditor !== undefined) {
const mh = await getAndUpdateModeHandler();
taskQueue.enqueueTask(async () => {
if (vscode.window.activeTextEditor !== undefined) {
const mh = await getAndUpdateModeHandler();

mh.updateView(mh.vimState, { drawSelection: false, revealRange: false });
}
},
isRunning: false,
mh.updateView(mh.vimState, { drawSelection: false, revealRange: false });
}
});
}

Expand Down
32 changes: 13 additions & 19 deletions src/configuration/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -361,25 +361,19 @@ function overlapSetting(args: {
set: function(value) {
this['_' + propertyKey] = value;

taskQueue.enqueueTask({
promise: async () => {
if (value === undefined || Globals.isTesting) {
return;
}

let codeValue = value;

if (args.codeValueMapping) {
codeValue = args.codeValueMapping[value];
}

await vscode.workspace
.getConfiguration('editor')
.update(args.codeName, codeValue, true);
},
isRunning: false,
queue: 'config',
});
taskQueue.enqueueTask(async () => {
if (value === undefined || Globals.isTesting) {
return;
}

let codeValue = value;

if (args.codeValueMapping) {
codeValue = args.codeValueMapping[value];
}

await vscode.workspace.getConfiguration('editor').update(args.codeName, codeValue, true);
}, 'config');
},
enumerable: true,
configurable: true,
Expand Down
11 changes: 5 additions & 6 deletions src/mode/modeHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -581,16 +581,15 @@ export class ModeHandler implements vscode.Disposable {
return;
}

taskQueue.enqueueTask({
promise: () => this.handleSelectionChange(e),
isRunning: false,

taskQueue.enqueueTask(
() => this.handleSelectionChange(e),
undefined,
/**
* We don't want these to become backlogged! If they do, we'll update
* the selection to an incorrect value and see a jittering cursor.
*/
highPriority: true,
});
true
);
}
);

Expand Down
Loading

0 comments on commit 9b7c733

Please sign in to comment.