Skip to content

Commit e9ba0f5

Browse files
authored
Merge pull request #1192 from deanproxy/use-tsserver
add return-to-declaration functionality on the tsserver branch
2 parents 02eddd4 + 805414d commit e9ba0f5

File tree

4 files changed

+56
-16
lines changed

4 files changed

+56
-16
lines changed

dist/main/atom/commands/goToDeclaration.js

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@ const tslib_1 = require("tslib");
44
const registry_1 = require("./registry");
55
const utils_1 = require("../utils");
66
const simpleSelectionView_1 = require("../views/simpleSelectionView");
7+
const prevCursorPositions = [];
8+
function open(item) {
9+
atom.workspace.open(item.file, {
10+
initialLine: item.start.line - 1,
11+
initialColumn: item.start.offset - 1
12+
});
13+
}
714
registry_1.commands.set("typescript:go-to-declaration", deps => {
815
return (e) => tslib_1.__awaiter(this, void 0, void 0, function* () {
916
if (!utils_1.commandForTypeScript(e)) {
@@ -22,17 +29,28 @@ registry_1.commands.set("typescript:go-to-declaration", deps => {
2229
`;
2330
},
2431
filterKey: 'filePath',
25-
confirmed: item => open(item)
32+
confirmed: item => {
33+
prevCursorPositions.push(location);
34+
open(item);
35+
}
2636
});
2737
}
2838
else {
39+
prevCursorPositions.push(location);
2940
open(result.body[0]);
3041
}
31-
function open(item) {
32-
atom.workspace.open(item.file, {
33-
initialLine: item.start.line - 1,
34-
initialColumn: item.start.offset - 1
35-
});
42+
});
43+
});
44+
registry_1.commands.set("typescript:return-from-declaration", deps => {
45+
return (e) => tslib_1.__awaiter(this, void 0, void 0, function* () {
46+
const position = prevCursorPositions.pop();
47+
if (!position) {
48+
atom.notifications.addInfo('AtomTS: Previous position not found.');
49+
return;
3650
}
51+
open({
52+
file: position.file,
53+
start: { line: position.line, offset: position.offset }
54+
});
3755
});
3856
});

keymaps/atom-typescript.cson

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
# Stronger bindings
1313
'atom-workspace':
1414
'f6': 'typescript:build'
15+
'f10': 'typescript:return-from-declaration'
1516
'f12': 'typescript:go-to-declaration'
1617
'ctrl-\'': 'typescript:sync'
1718
'cmd-\'': 'typescript:sync'

lib/main/atom/commands/goToDeclaration.ts

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
11
import {commands} from "./registry"
2-
import {commandForTypeScript, getFilePathPosition} from "../utils"
2+
import {commandForTypeScript, getFilePathPosition, FileLocationQuery} from "../utils"
33
import {simpleSelectionView} from "../views/simpleSelectionView"
44

5+
const prevCursorPositions:FileLocationQuery[] = [];
6+
7+
function open(item: {file: string, start: {line: number, offset: number}}) {
8+
atom.workspace.open(item.file, {
9+
initialLine: item.start.line - 1,
10+
initialColumn: item.start.offset - 1
11+
})
12+
}
13+
514
commands.set("typescript:go-to-declaration", deps => {
615
return async e => {
716
if (!commandForTypeScript(e)) {
@@ -22,17 +31,28 @@ commands.set("typescript:go-to-declaration", deps => {
2231
`
2332
},
2433
filterKey: 'filePath',
25-
confirmed: item => open(item)
34+
confirmed: item => {
35+
prevCursorPositions.push(location);
36+
open(item)
37+
}
2638
})
2739
} else {
40+
prevCursorPositions.push(location);
2841
open(result.body![0])
2942
}
30-
31-
function open(item: {file: string, start: {line: number, offset: number}}) {
32-
atom.workspace.open(item.file, {
33-
initialLine: item.start.line - 1,
34-
initialColumn: item.start.offset - 1
35-
})
36-
}
3743
}
38-
})
44+
});
45+
46+
commands.set("typescript:return-from-declaration", deps => {
47+
return async e => {
48+
const position = prevCursorPositions.pop();
49+
if (!position) {
50+
atom.notifications.addInfo('AtomTS: Previous position not found.');
51+
return;
52+
}
53+
open({
54+
file: position.file,
55+
start: { line: position.line, offset: position.offset }
56+
});
57+
}
58+
});

menus/atomts-menus.cson

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
'submenu': [
88
{ 'label': 'Build', 'command': 'typescript:build' }
99
{ 'label': 'Go To Declaration', 'command': 'typescript:go-to-declaration' }
10+
{ 'label': 'Return From Declaration', 'command': 'typescript:return-from-declaration' }
1011
]
1112
]
1213
}

0 commit comments

Comments
 (0)