|
1 | | -"use babel" |
| 1 | +/** @babel */ |
2 | 2 |
|
3 | 3 | import { client } from '../connection' |
4 | 4 | import { docpane, views } from '../ui' |
5 | 5 |
|
6 | | -const { moduleinfo } = client.import({ rpc: ['moduleinfo'] }) |
7 | 6 | const docs = client.import('docs') |
| 7 | +const { |
| 8 | + gotosymbol: gotoSymbol, |
| 9 | + moduleinfo: moduleInfo |
| 10 | +} = client.import({ rpc: [ 'gotosymbol', 'moduleinfo' ] }) |
8 | 11 |
|
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 |
11 | 19 |
|
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, []) |
31 | 33 | }) |
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 | + } |
36 | 56 | } |
37 | 57 | } |
| 58 | + |
| 59 | +export default new URIHandler() |
0 commit comments