-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.coffee
54 lines (45 loc) · 1.62 KB
/
index.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
{openExternal} = require 'shell'
{install} = require 'atom-package-deps'
{request} = require 'http'
{name, config} = require './package'#.json
activate = -> install name, false unless atom.inSpecMode()
browsers =
'browser-plus': (repo) -> atom.workspace.open repo
'pane-browser': (repo) ->
atom.clipboard.write repo
context = atom.views.getView atom.workspace
try atom.commands.dispatch context, 'Pane Browser: Open from clipboard'
catch error
atom.notifications.addError error
loaded = Object.keys(browsers).filter (browser) ->
atom.packages.isPackageLoaded browser
config.browser =
description: "Open links in your default browser, or within Atom."
type: 'string'
default: "External"
enum: [ "External", loaded... ]
octolink = ->
providerName: name
priority: 1
grammarScopes: Object.keys config?.registry
wordRegExp: /// (@[.\w_-]+/)? \b[.\w_-]+(?=['"`:]) ///g
getSuggestionForWord: (editor, module, range) ->
{scopeName} = editor.getGrammar()
registry = config?.registry[scopeName]
range: range
callback: ->
get =
host: 'githublinker.herokuapp.com'
path: "/q/#{registry}/#{module}"
request(get, parse).end()
parse = (data) ->
string = ''
data.on 'data', (chunk) -> string += chunk
data.on 'end', -> open JSON.parse string
open = ({url, error, message}) ->
{browser} = atom.config.get name
browse = browsers[browser] ? openExternal
if error? then atom.notifications.addError name, detail: message
else browse url
#-------------------------------------------------------------------------------
module.exports = {config, activate, octolink}