Skip to content

Commit 2b60fe2

Browse files
wingyplusbasarat
authored andcommitted
Implement go to declaration with hyperclick provider (#995)
* Implement go to declaration with hyperclick provider Ref #448 * Custom word matching to match token and string Ref #448
1 parent 36e713a commit 2b60fe2

File tree

4 files changed

+46
-0
lines changed

4 files changed

+46
-0
lines changed

lib/hyperclickProvider.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import * as parent from "./worker/parent";
2+
import * as atomUtils from "./main/atom/atomUtils";
3+
import {Set} from "immutable";
4+
5+
const TS_GRAMMARS = Set<string>(["source.ts", "source.tsx"]);
6+
7+
export let providerName = "typescript-hyperclick-provider";
8+
9+
export let wordRegExp = /([A-Za-z0-9])+|['"`](\\.|[^'"`\\\\])*['"`]/g;
10+
11+
export function getSuggestionForWord(textEditor: AtomCore.IEditor, text: string, range: TextBuffer.IRange) {
12+
return {
13+
range: range,
14+
callback() {
15+
if (!TS_GRAMMARS.has(textEditor.getGrammar().scopeName)) {
16+
return null;
17+
}
18+
19+
let filePathPosition = {
20+
filePath: textEditor.getPath(),
21+
position: atomUtils.getEditorPositionForBufferPosition(textEditor, range.start)
22+
};
23+
24+
parent.getDefinitionsAtPosition(filePathPosition).then((res) => {
25+
if (res.definitions.length > 0) {
26+
let definition = res.definitions[0];
27+
atom.workspace.open(definition.filePath, {
28+
initialLine: definition.position.line,
29+
initialColumn: definition.position.col
30+
});
31+
}
32+
});
33+
}
34+
};
35+
}

lib/main/atomts.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,3 +337,8 @@ function waitForGrammarActivation(): Promise<any> {
337337
});
338338
return promise;
339339
}
340+
341+
import * as hyperclickProvider from "../hyperclickProvider";
342+
export function getHyperclickProvider() {
343+
return hyperclickProvider;
344+
}

lib/tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
],
2424
"files": [
2525
"./globals.ts",
26+
"./hyperclickProvider.ts",
2627
"./linter.ts",
2728
"./main/atom/atomConfig.ts",
2829
"./main/atom/atomUtils.ts",

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@
2626
"versions": {
2727
"1.0.0": "provideLinter"
2828
}
29+
},
30+
"hyperclick.provider": {
31+
"versions": {
32+
"0.0.0": "getHyperclickProvider"
33+
}
2934
}
3035
},
3136
"consumedServices": {

0 commit comments

Comments
 (0)