Skip to content
This repository was archived by the owner on Oct 5, 2022. It is now read-only.

upgrade to api 1.0 #34

Merged
merged 21 commits into from
Feb 8, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
a784d36
upgrade to API 1.0
jmquigs Jan 24, 2015
c121ee9
upgrade to API 1.0: require jquery and atom-space-pen-views modules
jmquigs Jan 24, 2015
f34c25f
upgrade to API 1.0: use atom-text-editor::shadow in .less file
jmquigs Jan 24, 2015
8310003
upgrade to API 1.0: use .gutter selector rather than "gutter" property
jmquigs Jan 24, 2015
3e6acf3
upgrade to API 1.0: remove EditorControl's dependencies on editorview
jmquigs Jan 24, 2015
92ffdb0
upgrade to API 1.0: store the haskell controller on the editor model,…
jmquigs Jan 25, 2015
ac005e6
upgrade to API 1.0: fix more misc deprecation warnings, where possible
jmquigs Jan 25, 2015
ac8c81a
upgrade to API 1.0: use editor.onWillSave
jmquigs Jan 26, 2015
e66eb0b
upgrade to API 1.0: use getView to get the editor element for pixelPo…
jmquigs Jan 27, 2015
85171dc
upgrade to API 1.0: after finding the cabal file, store its directory…
jmquigs Jan 27, 2015
408e726
upgrade to API 1.0: use buffer.onDidSave instead of 'saved' event
jmquigs Jan 28, 2015
109be9a
upgrade to API 1.0: upgrade to new autocomplete API
jmquigs Jan 28, 2015
0eb3061
upgrade to API 1.0: use new autocomplete provider interface
jmquigs Feb 5, 2015
e3eefc8
upgrade to API 1.0: rename stylesheets directory to "styles"
jmquigs Feb 5, 2015
197e5c5
upgrade to API 1.0: use the providedServices configuration object to …
jmquigs Feb 5, 2015
0ab9aa8
upgrade to API 1.0: use a weakmap to track editor controllers
jmquigs Feb 6, 2015
eb4846c
upgrade to API 1.0: use a weakmap to track completion providers
jmquigs Feb 6, 2015
42bbf67
upgrade to API 1.0: use rootElement,querySelectorAll for class queries
jmquigs Feb 6, 2015
a7cce26
upgrade to API 1.0: remote atom.project.cabalProjectRoot, replaced by…
jmquigs Feb 6, 2015
feb3a3a
upgrade to API 1.0: fix issue with haskell-ide not activating unless …
jmquigs Feb 6, 2015
a13badb
Upgrade atom version in package.json. Update changelog
jmquigs Feb 6, 2015
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.3.1
* Fixed: Upgrade to atom 1.0 api. Upgrade autocomplete
* Fixed: Fix issue requiring package to be manually deactivated/reactivated

## 0.3.0
* New: Code prettify by `stylish-haskell`.

Expand Down
4 changes: 2 additions & 2 deletions keymaps/ide-haskell.cson
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

# For more detailed documentation see
# https://atom.io/docs/latest/advanced/keymaps
'.workspace':
'atom-workspace':
'ctrl-cmd-o': 'ide-haskell:toggle-output'

'.editor':
'atom-text-editor':
'ctrl-cmd-s': 'ide-haskell:prettify-file'
38 changes: 22 additions & 16 deletions lib/complete-provider.coffee
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
{Provider, Suggestion} = require 'autocomplete-plus'
fuzzaldrin = require 'fuzzaldrin'

{CompletionDatabase} = require './completion-db'
{isHaskellSource} = require './utils'
ArrayHelperModule = require './utils'
{CompleteType} = require './util-data'
{CompositeDisposable} = require 'atom'

ArrayHelperModule.extendArray(Array)


# used regular expressions
REGEXP_MODULE_NAME = "[\\w\\.']"
REGEXP_MODULE_NAME_MAYBE = REGEXP_MODULE_NAME + "*"
Expand Down Expand Up @@ -36,7 +35,13 @@ PREFIX_IMPORT_FUNCTIONS = new RegExp("[\\(\\s,]+(" + REGEXP_FUNCTION_NAME_MAY
# regexps for completion in functions
PREFIX_FUNCTION_NAME = new RegExp("(" + REGEXP_FUNCTION_NAME_JUST + "|" + REGEXP_ALIAS_NAME_CAP + "\\." + REGEXP_FUNCTION_NAME_MAYBE + ")$")

class CompleteProvider extends Provider
class Suggestion

Choose a reason for hiding this comment

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

You can use an anonymous object if you would like; you certainly don't have to, this is acceptable also.

constructor: (options) ->
@word = options.word if options.word?
@prefix = options.prefix if options.prefix?
@label = options.label if options.label?

class CompleteProvider

pragmasWords: [
'LANGUAGE', 'OPTIONS_GHC', 'INCLUDE', 'WARNING', 'DEPRECATED', 'INLINE',
Expand All @@ -53,11 +58,12 @@ class CompleteProvider extends Provider
'then', 'where'
]

initialize: (@editorView, @manager) ->
constructor: (@editor, @manager) ->
@disposables = new CompositeDisposable
# if saved, rebuild completion list
@currentBuffer = @editor.getBuffer()
@currentBuffer.on 'will-be-saved', @onBeforeSaved
@currentBuffer.on 'saved', @onSaved
@disposables.add @currentBuffer.onWillSave @onBeforeSaved
@disposables.add @currentBuffer.onDidSave @onSaved

# if main database updated, rebuild completion list
@manager.mainCDB.on 'rebuild', @buildCompletionList
Expand All @@ -66,11 +72,10 @@ class CompleteProvider extends Provider
@buildCompletionList()

dispose: ->
@currentBuffer?.off 'saved', @onSaved
@currentBuffer?.off 'will-be-saved', @onBeforeSaved
@manager?.mainCDB.off 'rebuild', @buildCompletionList
@manager?.mainCDB.off 'updated', @setUpdatedFlag
@manager.localCDB[@currentBuffer.getUri()]?.off 'updated', @setUpdatedFlag
@disposables.dispose()

setUpdatedFlag: =>
@databaseUpdated = true
Expand All @@ -96,12 +101,13 @@ class CompleteProvider extends Provider
# rebuild local completion database
@buildCompletionList()

# internal method: called by the from the provider requestHandler in the plugin manager
buildSuggestions: ->
# try to rebuild completion list if database changed
@rebuildWordList()
return unless @totalWordList?

selection = @editor.getSelection()
selection = @editor.getLastSelection()
suggestions = @getSelectionSuggestion selection
return unless suggestions.length
return suggestions
Expand Down Expand Up @@ -133,7 +139,7 @@ class CompleteProvider extends Provider
words = fuzzaldrin.filter @pragmasWords, prefix

suggestions = for word in words when word isnt prefix
new Suggestion this, word: word, prefix: prefix
new Suggestion word: word, prefix: prefix
return suggestions

# check for language extensions
Expand All @@ -146,7 +152,7 @@ class CompleteProvider extends Provider
words = fuzzaldrin.filter @manager.mainCDB.extensions, prefix

suggestions = for word in words when word isnt prefix
new Suggestion this, word: word, prefix: prefix
new Suggestion word: word, prefix: prefix
return suggestions

# check for ghc flags
Expand All @@ -159,7 +165,7 @@ class CompleteProvider extends Provider
words = fuzzaldrin.filter @manager.mainCDB.ghcFlags, prefix

suggestions = for word in words when word isnt prefix
new Suggestion this, word: word, prefix: prefix
new Suggestion word: word, prefix: prefix
return suggestions

# check for keywords
Expand All @@ -172,7 +178,7 @@ class CompleteProvider extends Provider
words = fuzzaldrin.filter @keyWords, prefix

suggestions = for word in words when word isnt prefix
new Suggestion this, word: word, prefix: prefix
new Suggestion word: word, prefix: prefix
return suggestions

# completions inside import statement
Expand Down Expand Up @@ -205,14 +211,14 @@ class CompleteProvider extends Provider
return unless prefix? and words?

suggestions = for word in words when word isnt prefix
new Suggestion this, word: word, prefix: prefix
new Suggestion word: word, prefix: prefix
return suggestions

# function scope goes here
isLanguageFunctions: (srange, scope) =>

# check if current cursor is not inside string
[_, scope] = @editor.getCursorScopes()
[_, scope] = @editor.getLastCursor().getScopeDescriptor().getScopesArray()
return if scope? and scope in
[ "string.quoted.single.haskell",
"string.quoted.double.haskell",
Expand All @@ -226,7 +232,7 @@ class CompleteProvider extends Provider
words = fuzzaldrin.filter @totalWordList, prefix, key: 'expr'

suggestions = for word in words when word isnt prefix
new Suggestion this, word: word.expr, prefix: prefix, label: word.type
new Suggestion word: word.expr, prefix: prefix, label: word.type
return suggestions

# get prefix before cursor
Expand Down
49 changes: 26 additions & 23 deletions lib/editor-control.coffee
Original file line number Diff line number Diff line change
@@ -1,38 +1,40 @@
{$, $$, $$$, View} = require 'atom'
{$$, $$$, View} = require 'atom-space-pen-views'
$ = require 'jquery'
{Subscriber} = require 'emissary'

{Channel} = require './pending-backend'
{isHaskellSource, screenPositionFromMouseEvent, pixelPositionFromMouseEvent} = require './utils'
{isHaskellSource, screenPositionFromMouseEvent, pixelPositionFromMouseEvent, getElementsByClass} = require './utils'
{TooltipView} = require './tooltip-view'
utilGhcMod = require './util-ghc-mod'

{CompositeDisposable} = require 'atom'

class EditorControl
className: ['ide-haskell-error', 'ide-haskell-warning', 'ide-haskell-lint']

constructor: (@editorView, @manager) ->
constructor: (@editor, @manager) ->
@checkMarkers = []

@editor = @editorView.getEditor()
@gutter = @editorView.gutter
@scroll = @editorView.find('.scroll-view')
@disposables = new CompositeDisposable
@editorElement = atom.views.getView(@editor)
@gutter = $(getElementsByClass(@editorElement, '.gutter'))
@scroll = $(getElementsByClass(@editorElement, '.scroll-view'))

@subscriber = new Subscriber()

# event for editor updates
@subscriber.subscribe @editorView, 'editor:will-be-removed', =>
@disposables.add @editor.onDidDestroy =>
@deactivate()

# buffer events for automatic check
@subscriber.subscribe @editor.getBuffer(), 'saved', (buffer) =>
buffer = @editor.getBuffer()
@disposables.add buffer.onDidSave () =>
return unless isHaskellSource buffer.getUri()

# TODO if uri was changed, then we have to remove all current markers

workspaceElement = atom.views.getView(atom.workspace)
if atom.config.get('ide-haskell.checkOnFileSave')
atom.workspaceView.trigger 'ide-haskell:check-file'
atom.commands.dispatch workspaceElement, 'ide-haskell:check-file'
if atom.config.get('ide-haskell.lintOnFileSave')
atom.workspaceView.trigger 'ide-haskell:lint-file'
atom.commands.dispatch workspaceElement, 'ide-haskell:lint-file'

# show expression type if mouse stopped somewhere
@subscriber.subscribe @scroll, 'mousemove', (e) =>
Expand All @@ -59,7 +61,7 @@ class EditorControl
@clearExprTypeTimeout()
@hideCheckResult()
@subscriber.unsubscribe()
@editorView.control = undefined
@disposables.dispose()

# helper function to hide tooltip and stop timeout
clearExprTypeTimeout: ->
Expand Down Expand Up @@ -89,7 +91,7 @@ class EditorControl
@checkMarkers = []

markerFromCheckResult: (result) ->
return unless result.uri is @editor.getUri()
return unless result.uri is @editor.getURI()
@checkMarkers[result.type] = [] unless @checkMarkers[result.type]?

# create a new marker
Expand All @@ -108,23 +110,24 @@ class EditorControl

decorateMarker: (m) ->
{ marker, klass } = m
@editor.decorateMarker marker, type: 'gutter', class: klass
@editor.decorateMarker marker, type: 'line-number', class: klass
@editor.decorateMarker marker, type: 'highlight', class: klass
@editor.decorateMarker marker, type: 'line', class: klass

# get expression type under mouse cursor and show it
showExpressionType: (e) ->
return unless isHaskellSource(@editor.getUri()) and not @exprTypeTooltip?
return unless isHaskellSource(@editor.getURI()) and not @exprTypeTooltip?

pixelPt = pixelPositionFromMouseEvent(@editorView, e)
pixelPt = pixelPositionFromMouseEvent(@editor, e)
screenPt = @editor.screenPositionForPixelPosition(pixelPt)
bufferPt = @editor.bufferPositionForScreenPosition(screenPt)
nextCharPixelPt = @editor.pixelPositionForBufferPosition([bufferPt.row, bufferPt.column + 1])
editorElement = atom.views.getView(@editor);
nextCharPixelPt = editorElement.pixelPositionForBufferPosition([bufferPt.row, bufferPt.column + 1])

return if pixelPt.left > nextCharPixelPt.left

# find out show position
offset = @editorView.lineHeight * 0.7
offset = @editor.getLineHeightInPixels() * 0.7
tooltipRect =
left: e.clientX
right: e.clientX
Expand All @@ -137,7 +140,7 @@ class EditorControl
# process start
@manager.pendingProcessController.start Channel.expressionType, utilGhcMod.type, {
pt: bufferPt
fileName: @editor.getUri()
fileName: @editor.getURI()
onResult: (result) =>
@exprTypeTooltip?.updateText(result.type)
}
Expand All @@ -150,7 +153,7 @@ class EditorControl
# show check result when mouse over gutter icon
showCheckResult: (e) ->
@hideCheckResult()
row = @editor.bufferPositionForScreenPosition(screenPositionFromMouseEvent(@editorView, e)).row
row = @editor.bufferPositionForScreenPosition(screenPositionFromMouseEvent(@editor, e)).row

# find best result for row
foundResult = null
Expand All @@ -168,7 +171,7 @@ class EditorControl

# create show position
targetRect = e.currentTarget.getBoundingClientRect()
offset = @editorView.lineHeight * 0.3
offset = @editor.getLineHeightInPixels() * 0.3
rect =
left: targetRect.left - offset
right: targetRect.right + offset
Expand Down
Loading