Skip to content

Commit 7b26300

Browse files
committed
add goto uri 🎉
1 parent b42b7d6 commit 7b26300

File tree

2 files changed

+52
-29
lines changed

2 files changed

+52
-29
lines changed

lib/runtime.coffee

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ module.exports =
1515
debuginfo: require './runtime/debuginfo'
1616
formatter: require './runtime/formatter'
1717
goto: require './runtime/goto'
18+
urihandler: require './runtime/urihandler'
1819
refactor: require './runtime/refactor'
1920

2021
activate: ->
@@ -30,7 +31,7 @@ module.exports =
3031
consumeInk: (ink) ->
3132
@evaluation.ink = ink
3233
@frontend.ink = ink
33-
for mod in [@console, @debugger, @profiler, @linter, @goto, @outline, @refactor]
34+
for mod in [@console, @debugger, @profiler, @linter, @goto, @outline, @urihandler, @refactor]
3435
mod.activate(ink)
3536
for mod in [@workspace, @plots]
3637
mod.ink = ink
@@ -61,4 +62,4 @@ module.exports =
6162
@subs.add(datatipDisposable)
6263
datatipDisposable
6364

64-
handleURI: require './runtime/urihandler'
65+
handleURI: (parsedURI) -> @urihandler.handleURI parsedURI

lib/runtime/urihandler.js

Lines changed: 49 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,59 @@
1-
"use babel"
1+
/** @babel */
22

33
import { client } from '../connection'
44
import { docpane, views } from '../ui'
55

6-
const { moduleinfo } = client.import({ rpc: ['moduleinfo'] })
76
const docs = client.import('docs')
7+
const {
8+
gotosymbol: gotoSymbol,
9+
moduleinfo: moduleInfo
10+
} = client.import({ rpc: [ 'gotosymbol', 'moduleinfo' ] })
811

9-
export default function handleURI (parsedURI) {
10-
const { query } = parsedURI
12+
class URIHandler {
13+
activate(ink) {
14+
this.ink = ink
15+
}
16+
17+
handleURI (parsedURI) {
18+
const { query } = parsedURI
1119

12-
if (query.open) { // open a file
13-
atom.workspace.open(query.file, {
14-
initialLine: Number(query.line),
15-
pending: atom.config.get('core.allowPendingPaneItems')
16-
})
17-
} else if (query.docs) { // show docs
18-
const { word, mod } = query
19-
docs({ word, mod }).then(result => {
20-
if (result.error) return
21-
const view = views.render(result)
22-
docpane.processLinks(view.getElementsByTagName('a'))
23-
docpane.ensureVisible()
24-
docpane.showDocument(view, [])
25-
})
26-
} else if (query.moduleinfo){ // show module info
27-
const { mod } = query
28-
moduleinfo({ mod }).then(({ doc, items }) => {
29-
items.map(item => {
30-
docpane.processItem(item)
20+
if (query.open) { // open a file
21+
atom.workspace.open(query.file, {
22+
initialLine: Number(query.line),
23+
pending: atom.config.get('core.allowPendingPaneItems')
24+
})
25+
} else if (query.docs) { // show docs
26+
const { word, mod } = query
27+
docs({ word, mod }).then(result => {
28+
if (result.error) return
29+
const view = views.render(result)
30+
docpane.processLinks(view.getElementsByTagName('a'))
31+
docpane.ensureVisible()
32+
docpane.showDocument(view, [])
3133
})
32-
const view = views.render(doc)
33-
docpane.ensureVisible()
34-
docpane.showDocument(view, items)
35-
})
34+
} else if (query.goto) {
35+
const { word, mod } = query
36+
gotoSymbol({
37+
word,
38+
mod
39+
}).then(symbols => {
40+
if (symbols.error) return
41+
this.ink.goto.goto(symbols, {
42+
pending: atom.config.get('core.allowPendingPaneItems')
43+
})
44+
})
45+
} else if (query.moduleinfo){ // show module info
46+
const { mod } = query
47+
moduleInfo({ mod }).then(({ doc, items }) => {
48+
items.map(item => {
49+
docpane.processItem(item)
50+
})
51+
const view = views.render(doc)
52+
docpane.ensureVisible()
53+
docpane.showDocument(view, items)
54+
})
55+
}
3656
}
3757
}
58+
59+
export default new URIHandler()

0 commit comments

Comments
 (0)