Skip to content

Commit 6beaa60

Browse files
committed
feat: add hyperclick provider
1 parent 1a9f75e commit 6beaa60

File tree

3 files changed

+71
-4
lines changed

3 files changed

+71
-4
lines changed

lib/clickProvider.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
'use babel';
2+
3+
export class ClickProvider {
4+
constructor(options) {
5+
this.clickHandler = options.clickHandler;
6+
7+
this.suggestionForWordHandler = this.suggestionForWordHandler.bind(this);
8+
this.getProvider = this.getProvider.bind(this);
9+
}
10+
11+
suggestionForWordHandler(textEditor, text, range) {
12+
const targetValue = text && text.trim();
13+
if (!targetValue) return;
14+
15+
return {
16+
range,
17+
callback: () => this.clickHandler(),
18+
};
19+
}
20+
21+
getProvider() {
22+
const grammarScopes = atom.config.get(
23+
'atom-ide-definitions.clickGrammarScopes'
24+
);
25+
const priority = atom.config.get('atom-ide-definitions.clickPriority');
26+
27+
return {
28+
priority,
29+
// Assign value only if at least one scope is available. Falsey triggers default behaviour, "apply to all".
30+
grammarScopes:
31+
(grammarScopes && !!grammarScopes[0] && grammarScopes) || null,
32+
getSuggestionForWord: this.suggestionForWordHandler,
33+
};
34+
}
35+
}

lib/main.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,13 @@
33
import { CompositeDisposable } from 'atom';
44
import goToDefinition from './goToDefinition';
55
import createProviderRegistry from './providerRegistry';
6+
import { ClickProvider } from './clickProvider';
67

78
function package() {
89
const providerRegistry = createProviderRegistry();
10+
const clickProvider = new ClickProvider({
11+
clickHandler: () => goToDefinition(providerRegistry),
12+
});
913
let subscriptions;
1014

1115
function activate() {
@@ -27,7 +31,12 @@ function package() {
2731
providerRegistry.addProvider(provider);
2832
}
2933

30-
return { activate, deactivate, consumeDefinitionsService };
34+
return {
35+
activate,
36+
deactivate,
37+
consumeDefinitionsService,
38+
getClickProvider: clickProvider.getProvider,
39+
};
3140
}
3241

3342
export default package();

package.json

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@
88
"atom-ide",
99
"defintion"
1010
],
11-
"activationCommands": {
12-
"atom-workspace": "atom-ide-go-to-definition:go-to-definition"
13-
},
1411
"repository": "https://github.com/atom-ide-community/atom-ide-definitions",
1512
"license": "MIT",
1613
"engines": {
@@ -50,5 +47,31 @@
5047
"0.1.0": "consumeDefinitionsService"
5148
}
5249
}
50+
},
51+
"providedServices": {
52+
"hyperclick": {
53+
"versions": {
54+
"0.1.0": "getClickProvider"
55+
}
56+
}
57+
},
58+
"configSchema": {
59+
"clickPriority": {
60+
"order": 1,
61+
"title": "Hyperclick Provider Priority",
62+
"description": "Provider priority relative to other providers. For more details see [Hyperclick's provider documentation](https://github.com/facebookarchive/hyperclick#details).",
63+
"type": "number",
64+
"default": 0
65+
},
66+
"clickGrammarScopes": {
67+
"order": 2,
68+
"title": "Hyperclick Grammar Scopes",
69+
"description": "List of scopes to allow action on. For example, `source.js, source.ts, source.go` *Requires reload to take effect.*",
70+
"type": "array",
71+
"default": [],
72+
"items": {
73+
"type": "string"
74+
}
75+
}
5376
}
5477
}

0 commit comments

Comments
 (0)