Skip to content
This repository was archived by the owner on Mar 14, 2021. It is now read-only.
Closed
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ You can edit Atom keybindings by opening 'Edit → Open Your Keymap'. Here is a
'ctrl-alt-i': 'haskell-ghc-mod:show-info' #this is an example binding
'ctrl-alt-T': 'haskell-ghc-mod:insert-type' #this is an example binding
'': 'haskell-ghc-mod:case-split'
'': 'haskell-ghc-mod:hole-fill'
'': 'haskell-ghc-mod:sig-fill'
'': 'haskell-ghc-mod:show-info-fallback-to-type'
'': 'haskell-ghc-mod:show-type-fallback-to-info'
Expand Down
21 changes: 21 additions & 0 deletions lib/ghc-mod/ghc-modi-process.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,27 @@ class GhcModiProcess
]
replacement: text

doHoleFill: (buffer, crange) =>
return Promise.resolve [] unless buffer.getUri()?
crange = Util.tabShiftForRange(buffer, crange)
@queueCmd 'typeinfo',
interactive: @caps?.interactiveCaseSplit ? false
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's safe to use interactive: true here. interactiveCaseSplit is a workaround for a ghc-mod bug where case-split command crashed interactive mode, but I don't think it's the case with auto.

NB: sig-fill just crashed in most cases since ghc-mod-5.3, and was finally fixed in 5.6 IIRC, so the same workaround is applied there to avoid crashing interactive mode.

buffer: buffer
command: 'auto',
uri: buffer.getUri()
text: buffer.getText() if buffer.isModified()
args: [crange.start.row + 1, crange.start.column + 1]
.then (lines) ->
return null if lines.length == 0 or lines[1] == ""

[line_, rowstart, colstart, rowend, colend, text] = lines[0].match(/^(\d+)\s+(\d+)\s+(\d+)\s+(\d+)/)

range: Range.fromObject [
[parseInt(rowstart) - 1, parseInt(colstart) - 1],
[parseInt(rowend) - 1, parseInt(colend) - 1]
]
suggestions: lines[1..]

doSigFill: (buffer, crange) =>
return Promise.resolve [] unless buffer.getUri()?
crange = Util.tabShiftForRange(buffer, crange)
Expand Down
20 changes: 20 additions & 0 deletions lib/upi-consumer.coffee
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{CompositeDisposable} = require 'atom'
ImportListView = require './views/import-list-view'
SuggestionListView = require './views/suggestion-list-view'

module.exports =
class UPIConsumer
Expand All @@ -24,6 +25,7 @@ class UPIConsumer
'haskell-ghc-mod:show-type': @tooltipCommand @typeTooltip
'haskell-ghc-mod:show-info': @tooltipCommand @infoTooltip
'haskell-ghc-mod:case-split': @caseSplitCommand
'haskell-ghc-mod:hole-fill': @holeFillCommand
'haskell-ghc-mod:sig-fill': @sigFillCommand
'haskell-ghc-mod:go-to-declaration': @goToDeclCommand
'haskell-ghc-mod:show-info-fallback-to-type': @tooltipCommand @infoTypeTooltip
Expand All @@ -40,6 +42,7 @@ class UPIConsumer
{label: 'Show Info', command: 'haskell-ghc-mod:show-info'}
{label: 'Show Type And Info', command: 'haskell-ghc-mod:show-type-and-info'}
{label: 'Case Split', command: 'haskell-ghc-mod:case-split'}
{label: 'Hole Fill', command: 'haskell-ghc-mod:hole-fill'}
{label: 'Sig Fill', command: 'haskell-ghc-mod:sig-fill'}
{label: 'Insert Type', command: 'haskell-ghc-mod:insert-type'}
{label: 'Insert Import', command: 'haskell-ghc-mod:insert-import'}
Expand Down Expand Up @@ -146,6 +149,23 @@ class UPIConsumer
res.forEach ({range, replacement}) ->
editor.setTextInBufferRange(range, replacement)

holeFillCommand: ({target, detail}) =>
editor = target.getModel()
@upi.withEventRange {editor, detail}, ({crange}) =>
@process.doHoleFill(editor.getBuffer(), crange)
.then (res) ->
return null unless res?

{range, suggestions} = res

if suggestions.length == 1
editor.setTextInBufferRange(range, suggestions[0])
else
new SuggestionListView
items: suggestions
onConfirmed: (suggestion) ->
editor.setTextInBufferRange(range, suggestion)

sigFillCommand: ({target, detail}) =>
editor = target.getModel()
@upi.withEventRange {editor, detail}, ({crange}) =>
Expand Down
30 changes: 30 additions & 0 deletions lib/views/suggestion-list-view.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{SelectListView} = require 'atom-space-pen-views'

module.exports=
class SuggestionListView extends SelectListView
initialize: ({@onConfirmed, items}) ->
super
@panel = atom.workspace.addModalPanel
item: this
visible: false
@addClass 'ide-haskell'
@show items

cancelled: ->
@panel.destroy()

getFilterKey: ->
"text"

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

viewForItem: (mod) ->
"<li><pre>#{mod}</pre></li>"

confirmed: (mod) ->
@onConfirmed? mod
@cancel()