Skip to content

Introduce purs-tidy formatter #46

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Nov 11, 2021
Merged
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
9 changes: 7 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ jobs:

- name: Set up PureScript toolchain
uses: purescript-contrib/setup-purescript@main
with:
purs-tidy: "latest"

- name: Cache PureScript dependencies
uses: actions/cache@v2
Expand All @@ -25,9 +27,9 @@ jobs:
output

- name: Set up Node toolchain
uses: actions/setup-node@v1
uses: actions/setup-node@v2
with:
node-version: "12.x"
node-version: "14.x"

- name: Cache NPM dependencies
uses: actions/cache@v2
Expand All @@ -49,3 +51,6 @@ jobs:

- name: Run tests
run: npm run test

- name: Check formatting
run: purs-tidy check src test
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
!.gitignore
!.github
!.editorconfig
!.tidyrc.json
!.eslintrc.json

output
Expand Down
10 changes: 10 additions & 0 deletions .tidyrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"importSort": "source",
"importWrap": "source",
"indent": 2,
"operatorsFile": null,
"ribbon": 1,
"typeArrowPlacement": "first",
"unicode": "never",
"width": null
}
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ New features:
Bugfixes:

Other improvements:
- Added `purs-tidy` formatter (#46 by @thomashoneyman)

## [v8.0.0](https://github.com/purescript-contrib/purescript-ace/releases/tag/v8.0.0) - 2021-02-26

Expand Down
132 changes: 63 additions & 69 deletions example/src/Main.purs
Original file line number Diff line number Diff line change
Expand Up @@ -50,52 +50,46 @@ main = onLoad $ do
"string"
false
session
>>= Ref.new

let rerenderMarker _ = do
Ref.read markerRef >>= flip Session.removeMarker session
Ace.Position {row: startRow, column: startColumn}
<- Anchor.getPosition startAnchor
Ace.Position {row: endRow, column: endColumn}
<- Anchor.getPosition endAnchor
markRange <- Range.create
startRow
(startColumn - one)
endRow
(endColumn + one)
newMId <- Session.addMarker
markRange
"readonly-highlight"
"string"
false
session

Ref.write newMId markerRef
pure unit
>>= Ref.new

let
rerenderMarker _ = do
Ref.read markerRef >>= flip Session.removeMarker session
Ace.Position { row: startRow, column: startColumn } <- Anchor.getPosition startAnchor
Ace.Position { row: endRow, column: endColumn } <- Anchor.getPosition endAnchor
markRange <- Range.create
startRow
(startColumn - one)
endRow
(endColumn + one)
newMId <- Session.addMarker
markRange
"readonly-highlight"
"string"
false
session

Ref.write newMId markerRef
pure unit

Anchor.onChange startAnchor rerenderMarker
Anchor.onChange endAnchor rerenderMarker

Editor.getKeyBinding editor
>>= KeyBinding.addKeyboardHandler \handler hs kstring kcode _ -> do
if hs == -1 || (kcode <= 40 && kcode >= 37)
then pure Nothing
else do
Ace.Position { row: startRow, column: startColumn }
<- Anchor.getPosition startAnchor
Ace.Position { row: endRow, column: endColumn }
<- Anchor.getPosition endAnchor
if hs == -1 || (kcode <= 40 && kcode >= 37) then pure Nothing
else do
Ace.Position { row: startRow, column: startColumn } <- Anchor.getPosition startAnchor
Ace.Position { row: endRow, column: endColumn } <- Anchor.getPosition endAnchor
selectedRange <- Editor.getSelectionRange handler.editor
newRange <-
if kstring == "backspace"
then Range.create startRow startColumn endRow (endColumn + 1)
else if kstring == "delete" || (kstring == "d" && hs == 1)
then Range.create startRow (startColumn - 1) endRow endColumn
else Range.create startRow startColumn endRow endColumn
if kstring == "backspace" then Range.create startRow startColumn endRow (endColumn + 1)
else if kstring == "delete" || (kstring == "d" && hs == 1) then Range.create startRow (startColumn - 1) endRow endColumn
else Range.create startRow startColumn endRow endColumn
intersected <- Range.intersects newRange selectedRange
pure if intersected
then Just { command: Ace.Null, passEvent: false }
else Nothing
pure
if intersected then Just { command: Ace.Null, passEvent: false }
else Nothing

-- Set the theme
Editor.setTheme "ace/theme/chrome" editor
Expand All @@ -108,7 +102,6 @@ main = onLoad $ do

-- Get the editor session


-- Set the mode
Session.setMode "ace/mode/javascript" session
-- Get the mode
Expand All @@ -117,7 +110,7 @@ main = onLoad $ do
_ <- Ace.createEditSession "" mode Ace.ace

-- Get the document for the session
document `Document.onChange` \(Ace.DocumentEvent {action: ty}) ->
document `Document.onChange` \(Ace.DocumentEvent { action: ty }) ->
log ("Document changed: " <> Ace.showDocumentEventType ty)
Document.setNewLineMode Ace.Windows document

Expand All @@ -127,19 +120,19 @@ main = onLoad $ do
position <- Anchor.getPosition anchor

log $ "Initial anchor position: "
<> show (Ace.getRow position)
<> ", "
<> show (Ace.getColumn position)
<> ". Should be 0, 0"
<> show (Ace.getRow position)
<> ", "
<> show (Ace.getColumn position)
<> ". Should be 0, 0"

-- Update the anchor position
Anchor.setPosition 0 1 true anchor
-- Listen for anchor position changes
anchor `Anchor.onChange` \e -> do
log $ "New anchor position: "
<> show (Ace.getRow e.value)
<> ", "
<> show (Ace.getColumn e.value)
<> show (Ace.getRow e.value)
<> ", "
<> show (Ace.getColumn e.value)
-- Unlisten
Anchor.detach anchor

Expand All @@ -161,14 +154,16 @@ main = onLoad $ do

-- Create a search class
search <- Search.create
_ <- Search.set { needle: "boo"
, backwards: false
, wrap: false
, caseSensitive: false
, wholeWord: true
, regExp: false
, skipCurrent: false
} search
_ <- Search.set
{ needle: "boo"
, backwards: false
, wrap: false
, caseSensitive: false
, wholeWord: true
, regExp: false
, skipCurrent: false
}
search
range' <- Search.find session search
for_ range' \r -> Session.addFold "fold" r session

Expand All @@ -184,32 +179,32 @@ main = onLoad $ do
-- Move the cursor
Editor.moveCursorTo 0 Nothing Nothing editor


Session.setMode "ace/mode/text" session
languageTools <- LanguageTools.languageTools
Editor.setEnableBasicAutocompletion true editor
completer <-
Completer.mkCompleter
(\_ _ _ inp cb -> do
cb $ pure [ { value: inp <> "!!"
, score: 100.0
, caption: pure "???"
, meta: "!!"
}
, { value: "abcde"
, score: 200.0
, caption: Nothing
, meta: "abcde"
} ] )
( \_ _ _ inp cb -> do
cb $ pure
[ { value: inp <> "!!"
, score: 100.0
, caption: pure "???"
, meta: "!!"
}
, { value: "abcde"
, score: 200.0
, caption: Nothing
, meta: "abcde"
}
]
)
LanguageTools.addCompleter completer languageTools


-- Misc. Tests
-- miscTests

pure unit


miscTests :: Effect Unit
miscTests = void do
editor <- Ace.edit "tests" Ace.ace
Expand Down Expand Up @@ -270,7 +265,6 @@ miscTests = void do
_ <- Document.indexToPosition 0 0 document
_ <- Document.positionToIndex position 0 document


undoManager <- UndoManager.create

Session.findMatchingBracket position session
Expand Down
1 change: 0 additions & 1 deletion src/Ace/EditSession.purs
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,5 @@ foreign import createFromLinesImpl :: Fn2 (Array String) (Nullable String) (Effe
createFromLines :: Array String -> Maybe String -> Effect EditSession
createFromLines text mode' = runFn2 createFromLinesImpl text (toNullable mode')


foreign import getMarkers
:: EditSession -> Effect (Array Marker)
35 changes: 23 additions & 12 deletions src/Ace/Editor.purs
Original file line number Diff line number Diff line change
Expand Up @@ -143,17 +143,23 @@ foreign import onImpl

onBlur
:: forall a
. Editor -> (Effect a) -> Effect Unit
. Editor
-> (Effect a)
-> Effect Unit
onBlur self fn = runFn3 onImpl "blur" (\_ -> fn) self

onFocus
:: forall a
. Editor -> (Effect a) -> Effect Unit
. Editor
-> (Effect a)
-> Effect Unit
onFocus self fn = runFn3 onImpl "focus" (\_ -> fn) self

onCopy
:: forall a
. Editor -> (String -> Effect a) -> Effect Unit
. Editor
-> (String -> Effect a)
-> Effect Unit
onCopy self fn = runFn3 onImpl "copy" fn self

onPaste
Expand All @@ -174,8 +180,9 @@ setPasteEventText text e = runFn2 setPasteEventTextImpl text e

onChangeSession
:: Editor
-> ({ oldSession :: EditSession, session :: EditSession }
-> Effect Unit)
-> ( { oldSession :: EditSession, session :: EditSession }
-> Effect Unit
)
-> Effect Unit
onChangeSession self fn = runFn3 onImpl "changeSession" fn self

Expand Down Expand Up @@ -600,7 +607,9 @@ foreign import findNextImpl
:: Fn3 (Nullable SearchOptions) (Nullable Boolean) Editor (Effect Unit)

findNext
:: Maybe SearchOptions -> Maybe Boolean -> Editor
:: Maybe SearchOptions
-> Maybe Boolean
-> Editor
-> Effect Unit
findNext options animate self =
runFn3 findNextImpl (toNullable options) (toNullable animate) self
Expand All @@ -609,7 +618,9 @@ foreign import findPreviousImpl
:: Fn3 (Nullable SearchOptions) (Nullable Boolean) Editor (Effect Unit)

findPrevious
:: Maybe SearchOptions -> Maybe Boolean -> Editor
:: Maybe SearchOptions
-> Maybe Boolean
-> Editor
-> Effect Unit
findPrevious options animate self =
runFn3 findPreviousImpl (toNullable options) (toNullable animate) self
Expand All @@ -624,21 +635,22 @@ foreign import createImpl
:: Fn2 VirtualRenderer (Nullable EditSession) (Effect Editor)

create
:: VirtualRenderer -> Maybe EditSession
:: VirtualRenderer
-> Maybe EditSession
-> Effect Editor
create renderer session = runFn2 createImpl renderer (toNullable session)

foreign import setOption
:: forall a. String -> a -> Editor -> Effect Unit

setMinLines :: Int -> Editor -> Effect Unit
setMinLines :: Int -> Editor -> Effect Unit
setMinLines = setOption "minLines"

setMaxLines :: Int -> Editor -> Effect Unit
setMaxLines :: Int -> Editor -> Effect Unit
setMaxLines = setOption "maxLines"

setAutoScrollEditorIntoView
:: Boolean -> Editor -> Effect Unit
:: Boolean -> Editor -> Effect Unit
setAutoScrollEditorIntoView = setOption "autoScrollEditorIntoView"

setEnableBasicAutocompletion
Expand All @@ -653,6 +665,5 @@ setEnableSnippets
:: Boolean -> Editor -> Effect Unit
setEnableSnippets = setOption "enableSnippets"


foreign import getKeyBinding
:: Editor -> Effect KeyBinding
7 changes: 3 additions & 4 deletions src/Ace/Ext/LanguageTools/Completer.purs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@ type CompleterCallback = Maybe (Array Completion) -> Effect Unit
foreign import mkCompleterImpl
:: forall a
. Fn3 (Editor -> EditSession -> Position -> String -> CompleterCallback -> Effect Unit)
(Maybe a -> Boolean)
(Maybe a -> a)
(Effect Completer)

(Maybe a -> Boolean)
(Maybe a -> a)
(Effect Completer)

mkCompleter
:: (Editor -> EditSession -> Position -> String -> CompleterCallback -> Effect Unit)
Expand Down
4 changes: 2 additions & 2 deletions src/Ace/KeyBinding.purs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import Effect (Effect)
import Partial.Unsafe (unsafePartial)
import Web.UIEvent.KeyboardEvent (KeyboardEvent)

type KeyboardHandler
= { editor :: Editor }
type KeyboardHandler =
{ editor :: Editor }
-> Int
-> String
-> Int
Expand Down
Loading