Skip to content

Commit

Permalink
feat : support goto declaration menu item
Browse files Browse the repository at this point in the history
closes #96
  • Loading branch information
basarat committed Feb 18, 2015
1 parent 8832b5e commit aa606df
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
9 changes: 6 additions & 3 deletions lib/main/atom/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,13 @@ function registerCommands() {
buildView.setBuildOutput(resp.outputs);
});
});
atom.commands.add('atom-text-editor', 'typescript:go-to-declaration', function (e) {
var handleGoToDeclaration = function (e) {
if (!commandForTypeScript(e))
return;
var editor = atom.workspace.getActiveTextEditor();
var filePath = editor.getPath();
parent.getDefinitionsAtPosition({ filePath: filePath, position: atomUtils.getEditorPosition(editor) }).then(function (res) {
var position = atomUtils.getEditorPosition(editor);
parent.getDefinitionsAtPosition({ filePath: filePath, position: position }).then(function (res) {
var definitions = res.definitions;
if (!definitions || !definitions.length) {
atom.notifications.addInfo('AtomTS: No definition found.');
Expand All @@ -63,7 +64,9 @@ function registerCommands() {
newWindow: false
});
});
});
};
atom.commands.add('atom-text-editor', 'typescript:go-to-declaration', handleGoToDeclaration);
atom.commands.add('atom-text-editor', 'symbols-view:go-to-declaration', handleGoToDeclaration);
atom.commands.add('atom-text-editor', 'typescript:context-actions', function (e) {
atom.notifications.addSuccess('Context options coming soon!');
});
Expand Down
11 changes: 8 additions & 3 deletions lib/main/atom/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,14 @@ export function registerCommands() {
buildView.setBuildOutput(resp.outputs);
});
});
atom.commands.add('atom-text-editor', 'typescript:go-to-declaration',(e) => {

var handleGoToDeclaration = (e) => {
if (!commandForTypeScript(e)) return;

var editor = atom.workspace.getActiveTextEditor();
var filePath = editor.getPath();
parent.getDefinitionsAtPosition({ filePath: filePath, position: atomUtils.getEditorPosition(editor) }).then(res=> {
var position = atomUtils.getEditorPosition(editor);
parent.getDefinitionsAtPosition({ filePath: filePath, position: position }).then(res=> {
var definitions = res.definitions;
if (!definitions || !definitions.length) {
atom.notifications.addInfo('AtomTS: No definition found.');
Expand All @@ -82,8 +84,11 @@ export function registerCommands() {
newWindow: false
});
});
});
};

atom.commands.add('atom-text-editor', 'typescript:go-to-declaration', handleGoToDeclaration);
// This exists by default in the right click menu https://github.com/TypeStrong/atom-typescript/issues/96
atom.commands.add('atom-text-editor', 'symbols-view:go-to-declaration', handleGoToDeclaration);

atom.commands.add('atom-text-editor', 'typescript:context-actions',(e) => {
atom.notifications.addSuccess('Context options coming soon!');
Expand Down

0 comments on commit aa606df

Please sign in to comment.