Skip to content

Commit

Permalink
refactor and error handling
Browse files Browse the repository at this point in the history
as well as respecting the current module
  • Loading branch information
pfitzseb committed Jan 16, 2016
1 parent 2ca805a commit a99316c
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 4 deletions.
15 changes: 11 additions & 4 deletions lib/eval.coffee
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
client = require './connection/client'
notifications = require './ui/notifications'
modules = require './modules'
methodview = require './ui/method-view'


module.exports =
cursor: ({row, column}) ->
Expand Down Expand Up @@ -37,21 +40,25 @@ module.exports =

# get documentation or methods for the current word
toggleMeta: (type) ->
mod = modules.currentModule()
mod = if mod then mod else 'Main'
editor = atom.workspace.getActiveTextEditor()
[word, range] = @getWord editor
# if we only find numbers or nothing, return prematurely
if word.length == 0 || !isNaN(word) then return
if type == 'docs'
client.msg type, {code: word}, ({result}) =>
if type is 'docs'
client.msg type, {code: word, module: mod}, ({result}) =>
view = if result.type then result.view else result
view = @ink.tree.fromJson(view)[0]
@ink.links.linkify view
r = @ink?.results.toggleUnderline editor, range,
content: view
clas: 'julia'
else
client.msg type, {code: word}, ({result}) =>
@ink.methodview.displayMethodView(result)
methods = new Promise (resolve) =>
client.msg type, {code: word, module: mod}, (result) =>
resolve result
methodview.displayMethodView(methods)

# gets the word and its range in the `editor` which the last cursor is on
getWord: (editor) ->
Expand Down
56 changes: 56 additions & 0 deletions lib/ui/method-view.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
{$$, SelectListView} = require 'atom-space-pen-views'

module.exports =
displayMethodView: (promise) ->
@view ?= new MethodView()
@view.setLoading "Loading..."
@view.show()
promise.then (items) =>
if items.error
@view.setError(items.result)
else
@view.setItems(items.result)

class MethodView extends SelectListView
initialize: ->
super
@panel = atom.workspace.addModalPanel(item: this, visible: false)
@addClass('command-palette')
@addClass('ink')

destroy: ->
@cancel()
@panel.destroy()

# An item has four fields:
# .signature: Method signature, searchable and displayed.
# .file: File in which this method is defined, not displayed.
# .dispfile: Humanized file path, displayed.
# .line: Line of definition.
viewForItem: ({signature, dispfile, line}) ->
$$ ->
@li class: 'two-lines', =>
@div signature, class: 'primary-line'
@div dispfile + ":" + line, class: 'secondary-line'

getFilterKey: -> 'signature'

populate: (items) ->
@setItems(items)
@show()

show: () ->
@storeFocusedElement()
@panel.show()
@focusFilterEditor()

hide: () ->
@panel?.hide()

confirmed: (item) ->
atom.workspace.open item.file,
initialLine: item.line
@hide()

cancelled: ->
@hide()

0 comments on commit a99316c

Please sign in to comment.