Skip to content

Implement go to declaration with hyperclick provider #995

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 11, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions lib/hyperclickProvider.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import * as parent from "./worker/parent";
import * as atomUtils from "./main/atom/atomUtils";
import {Set} from "immutable";

const TS_GRAMMARS = Set<string>(["source.ts", "source.tsx"]);

export let providerName = "typescript-hyperclick-provider";

export let wordRegExp = /([A-Za-z0-9])+|['"`](\\.|[^'"`\\\\])*['"`]/g;

export function getSuggestionForWord(textEditor: AtomCore.IEditor, text: string, range: TextBuffer.IRange) {
return {
range: range,
callback() {
if (!TS_GRAMMARS.has(textEditor.getGrammar().scopeName)) {
return null;
}

let filePathPosition = {
filePath: textEditor.getPath(),
position: atomUtils.getEditorPositionForBufferPosition(textEditor, range.start)
};

parent.getDefinitionsAtPosition(filePathPosition).then((res) => {
if (res.definitions.length > 0) {
let definition = res.definitions[0];
atom.workspace.open(definition.filePath, {
initialLine: definition.position.line,
initialColumn: definition.position.col
});
}
});
}
};
}
5 changes: 5 additions & 0 deletions lib/main/atomts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -337,3 +337,8 @@ function waitForGrammarActivation(): Promise<any> {
});
return promise;
}

import * as hyperclickProvider from "../hyperclickProvider";
export function getHyperclickProvider() {
return hyperclickProvider;
}
1 change: 1 addition & 0 deletions lib/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
],
"files": [
"./globals.ts",
"./hyperclickProvider.ts",
"./linter.ts",
"./main/atom/atomConfig.ts",
"./main/atom/atomUtils.ts",
Expand Down
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@
"versions": {
"1.0.0": "provideLinter"
}
},
"hyperclick.provider": {
"versions": {
"0.0.0": "getHyperclickProvider"
}
}
},
"consumedServices": {
Expand Down