Skip to content

Commit 99955af

Browse files
authored
Merge pull request #1265 from sverrejoh/master
Added back support for Hyperclick
2 parents 546522d + 1141990 commit 99955af

File tree

6 files changed

+73
-26
lines changed

6 files changed

+73
-26
lines changed

lib/main/atom/commands/goToDeclaration.ts

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -16,30 +16,10 @@ commands.set("typescript:go-to-declaration", deps => {
1616
if (!commandForTypeScript(e)) {
1717
return
1818
}
19-
2019
const location = getFilePathPosition()
2120
const client = await deps.getClient(location.file)
2221
const result = await client.executeDefinition(location)
23-
24-
if (result.body!.length > 1) {
25-
simpleSelectionView({
26-
items: result.body!,
27-
viewForItem: item => {
28-
return `
29-
<span>${item.file}</span>
30-
<div class="pull-right">line: ${item.start.line}</div>
31-
`
32-
},
33-
filterKey: "filePath",
34-
confirmed: item => {
35-
prevCursorPositions.push(location)
36-
open(item)
37-
},
38-
})
39-
} else {
40-
prevCursorPositions.push(location)
41-
open(result.body![0])
42-
}
22+
handleDefinitionResult(result, location)
4323
}
4424
})
4525

@@ -56,3 +36,30 @@ commands.set("typescript:return-from-declaration", deps => {
5636
})
5737
}
5838
})
39+
40+
export function handleDefinitionResult(
41+
result: protocol.DefinitionResponse,
42+
location: FileLocationQuery,
43+
): void {
44+
if (!result.body) {
45+
return
46+
} else if (result.body.length > 1) {
47+
simpleSelectionView({
48+
items: result.body,
49+
viewForItem: item => {
50+
return `
51+
<span>${item.file}</span>
52+
<div class="pull-right">line: ${item.start.line}</div>
53+
`
54+
},
55+
filterKey: "filePath",
56+
confirmed: item => {
57+
prevCursorPositions.push(location)
58+
open(item)
59+
},
60+
})
61+
} else {
62+
prevCursorPositions.push(location)
63+
open(result.body[0])
64+
}
65+
}

lib/main/atom/hyperclickProvider.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import {ClientResolver} from "../../client/clientResolver"
2+
import {simpleSelectionView} from "./views/simpleSelectionView"
3+
import {handleDefinitionResult} from "./commands/goToDeclaration"
4+
import {isTypescriptGrammar} from "./utils"
5+
6+
export function getHyperclickProvider(clientResolver: ClientResolver): any {
7+
return {
8+
providerName: "typescript-hyperclick-provider",
9+
wordRegExp: /([A-Za-z0-9_])+|['"`](\\.|[^'"`\\\\])*['"`]/g,
10+
getSuggestionForWord(editor: AtomCore.IEditor, text: string, range: TextBuffer.IRange) {
11+
if (!isTypescriptGrammar(editor.getGrammar())) {
12+
return null
13+
}
14+
15+
return {
16+
range: range,
17+
callback: async () => {
18+
const location = {
19+
file: editor.getPath(),
20+
line: range.start.row + 1,
21+
offset: range.start.column + 1,
22+
}
23+
const client = await clientResolver.get(location.file)
24+
const result = await client.executeDefinition(location)
25+
handleDefinitionResult(result, location)
26+
},
27+
}
28+
},
29+
}
30+
}

lib/main/atom/utils/atom.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ export function isTypescriptFile(filePath?: string): boolean {
2020
return ext === ".ts" || ext === ".tsx"
2121
}
2222

23+
export function isTypescriptGrammar(grammar: AtomCore.IGrammar): boolean {
24+
return grammar.scopeName === "source.ts" || grammar.scopeName === "source.tsx"
25+
}
26+
2327
export function isAllowedExtension(ext: string) {
2428
return ext == ".ts" || ext == ".tst" || ext == ".tsx"
2529
}

lib/main/atomts.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import * as tsconfig from "tsconfig/dist/tsconfig"
33
import {attach as attachRenameView} from "./atom/views/renameView"
44
import {AutocompleteProvider} from "./atom/autoCompleteProvider"
55
import {ClientResolver} from "../client/clientResolver"
6+
import {getHyperclickProvider} from "./atom/hyperclickProvider"
67
import {CodefixProvider} from "./atom/codefixProvider"
78
import {CompositeDisposable} from "atom"
89
import {debounce} from "lodash"
@@ -181,6 +182,10 @@ export function provideIntentions() {
181182
return codefixProvider
182183
}
183184

185+
export function hyperclickProvider() {
186+
return getHyperclickProvider(clientResolver)
187+
}
188+
184189
export var config = {
185190
unusedAsInfo: {
186191
title: "Show unused values with severity info",

lib/main/typescriptEditorPane.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {$} from "atom-space-pen-views"
22
import {CompositeDisposable} from "atom"
33
import {debounce, flatten} from "lodash"
4-
import {spanToRange, getProjectCodeSettings} from "./atom/utils"
4+
import {spanToRange, isTypescriptGrammar, getProjectCodeSettings} from "./atom/utils"
55
import {StatusPanel} from "./atom/components/statusPanel"
66
import {TypescriptBuffer} from "./typescriptBuffer"
77
import {TypescriptServiceClient} from "../client/client"
@@ -246,7 +246,3 @@ export class TypescriptEditorPane implements AtomCore.Disposable {
246246
tooltipManager.attach(editorView, this.editor)
247247
}
248248
}
249-
250-
function isTypescriptGrammar(grammar: AtomCore.IGrammar): boolean {
251-
return grammar.scopeName === "source.ts" || grammar.scopeName === "source.tsx"
252-
}

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@
3535
"2.0.0": "provide"
3636
}
3737
},
38+
"hyperclick.provider": {
39+
"versions": {
40+
"0.0.0": "hyperclickProvider"
41+
}
42+
},
3843
"intentions:list": {
3944
"versions": {
4045
"1.0.0": "provideIntentions"

0 commit comments

Comments
 (0)