Skip to content

Added back support for Hyperclick #1265

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 5 commits into from
Jun 25, 2017
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
49 changes: 28 additions & 21 deletions lib/main/atom/commands/goToDeclaration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,30 +16,10 @@ commands.set("typescript:go-to-declaration", deps => {
if (!commandForTypeScript(e)) {
return
}

const location = getFilePathPosition()
const client = await deps.getClient(location.file)
const result = await client.executeDefinition(location)

if (result.body!.length > 1) {
simpleSelectionView({
items: result.body!,
viewForItem: item => {
return `
<span>${item.file}</span>
<div class="pull-right">line: ${item.start.line}</div>
`
},
filterKey: "filePath",
confirmed: item => {
prevCursorPositions.push(location)
open(item)
},
})
} else {
prevCursorPositions.push(location)
open(result.body![0])
}
handleDefinitionResult(result, location)
}
})

Expand All @@ -56,3 +36,30 @@ commands.set("typescript:return-from-declaration", deps => {
})
}
})

export function handleDefinitionResult(
result: protocol.DefinitionResponse,
location: FileLocationQuery,
): void {
if (!result.body) {
return
} else if (result.body.length > 1) {
simpleSelectionView({
items: result.body,
viewForItem: item => {
return `
<span>${item.file}</span>
<div class="pull-right">line: ${item.start.line}</div>
`
},
filterKey: "filePath",
confirmed: item => {
prevCursorPositions.push(location)
open(item)
},
})
} else {
prevCursorPositions.push(location)
open(result.body[0])
}
}
30 changes: 30 additions & 0 deletions lib/main/atom/hyperclickProvider.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import {ClientResolver} from "../../client/clientResolver"
import {simpleSelectionView} from "./views/simpleSelectionView"
import {handleDefinitionResult} from "./commands/goToDeclaration"
import {isTypescriptGrammar} from "./utils"

export function getHyperclickProvider(clientResolver: ClientResolver): any {
return {
providerName: "typescript-hyperclick-provider",
wordRegExp: /([A-Za-z0-9_])+|['"`](\\.|[^'"`\\\\])*['"`]/g,
getSuggestionForWord(editor: AtomCore.IEditor, text: string, range: TextBuffer.IRange) {
if (!isTypescriptGrammar(editor.getGrammar())) {
return null
}

return {
range: range,
callback: async () => {
const location = {
file: editor.getPath(),
line: range.start.row + 1,
offset: range.start.column + 1,
}
const client = await clientResolver.get(location.file)
const result = await client.executeDefinition(location)
handleDefinitionResult(result, location)
},
}
},
}
}
4 changes: 4 additions & 0 deletions lib/main/atom/utils/atom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ export function isTypescriptFile(filePath?: string): boolean {
return ext === ".ts" || ext === ".tsx"
}

export function isTypescriptGrammar(grammar: AtomCore.IGrammar): boolean {
return grammar.scopeName === "source.ts" || grammar.scopeName === "source.tsx"
}

export function isAllowedExtension(ext: string) {
return ext == ".ts" || ext == ".tst" || ext == ".tsx"
}
Expand Down
5 changes: 5 additions & 0 deletions lib/main/atomts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as tsconfig from "tsconfig/dist/tsconfig"
import {attach as attachRenameView} from "./atom/views/renameView"
import {AutocompleteProvider} from "./atom/autoCompleteProvider"
import {ClientResolver} from "../client/clientResolver"
import {getHyperclickProvider} from "./atom/hyperclickProvider"
import {CodefixProvider} from "./atom/codefixProvider"
import {CompositeDisposable} from "atom"
import {debounce} from "lodash"
Expand Down Expand Up @@ -181,6 +182,10 @@ export function provideIntentions() {
return codefixProvider
}

export function hyperclickProvider() {
return getHyperclickProvider(clientResolver)
}

export var config = {
unusedAsInfo: {
title: "Show unused values with severity info",
Expand Down
6 changes: 1 addition & 5 deletions lib/main/typescriptEditorPane.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {$} from "atom-space-pen-views"
import {CompositeDisposable} from "atom"
import {debounce, flatten} from "lodash"
import {spanToRange, getProjectCodeSettings} from "./atom/utils"
import {spanToRange, isTypescriptGrammar, getProjectCodeSettings} from "./atom/utils"
import {StatusPanel} from "./atom/components/statusPanel"
import {TypescriptBuffer} from "./typescriptBuffer"
import {TypescriptServiceClient} from "../client/client"
Expand Down Expand Up @@ -246,7 +246,3 @@ export class TypescriptEditorPane implements AtomCore.Disposable {
tooltipManager.attach(editorView, this.editor)
}
}

function isTypescriptGrammar(grammar: AtomCore.IGrammar): boolean {
return grammar.scopeName === "source.ts" || grammar.scopeName === "source.tsx"
}
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@
"2.0.0": "provide"
}
},
"hyperclick.provider": {
"versions": {
"0.0.0": "hyperclickProvider"
}
},
"intentions:list": {
"versions": {
"1.0.0": "provideIntentions"
Expand Down