Skip to content

Commit

Permalink
Support gd (#547)
Browse files Browse the repository at this point in the history
* Add support for `gd` for #529

This commit maps `gd` to VSCode's go to declaration action.

Also, add a missing semicolon.

* Fix go to definition by polling.
  • Loading branch information
johnfn authored Aug 2, 2016
1 parent c3d1bb5 commit 44dfd25
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/actions/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1350,6 +1350,38 @@ class CommandExitVisualLineMode extends BaseCommand {
}
}

@RegisterAction
class CommandGoToDefinition extends BaseCommand {
modes = [ModeName.Normal];
keys = ["g", "d"];

public async exec(position: Position, vimState: VimState): Promise<VimState> {
const startPosition = Position.FromVSCodePosition(vscode.window.activeTextEditor.selection.start);

await vscode.commands.executeCommand("editor.action.goToDeclaration");

// Unfortuantely, the above does not necessarily have to have finished executing
// (even though we do await!). THe only way to ensure it's done is to poll, which is
// a major bummer.

await new Promise(resolve => {
let interval = setInterval(() => {
const positionNow = Position.FromVSCodePosition(vscode.window.activeTextEditor.selection.start);

if (!startPosition.isEqual(positionNow)) {
clearInterval(interval);
resolve();
}
}, 50);
});

vimState.focusChanged = true;
vimState.cursorPosition = Position.FromVSCodePosition(vscode.window.activeTextEditor.selection.start);

return vimState;
}
}

// begin insert commands

@RegisterAction
Expand Down

0 comments on commit 44dfd25

Please sign in to comment.