Skip to content

Commit

Permalink
feat: Dev basepoint (#128)
Browse files Browse the repository at this point in the history
* Setup projectFile path parsing

* Disable the damned OverloadedLists

* Parse JSON config

* Add error

* wip

* wip

* refactor

* Refactor

* wip

* wip

* Fix compilation

* Remove event-sourcing from CLI

* Parse JSON

* Nix file

* Update

* Fix

* deps

* Update

* Fix deps on darwin

* Generate cabal and nix file

* Build properly

* Add neo.build

* Start working on Task

* Refactor errors

* Add utf8 by default

* Update

* Retrieve nhcore

* Evaluate Nix expression

* Update

* update

* Remove optenv-conf

* Update gitignore

* Remove devenv

* "working" build

* Add FIXME comments

* update

* Update

* Update envrc

* Move files into .neohaskell

* Walk dirs

* Update

* Remove leading path

Co-authored-by: CoderCris Æ <[email protected]>

* Update

* Update

* Fix recursive directory copying

---------

Co-authored-by: Nikita Tchayka <[email protected]>
Co-authored-by: Nick Seagull <[email protected]>
Co-authored-by: CoderCris Æ <[email protected]>
  • Loading branch information
4 people authored Mar 7, 2025
1 parent deb9780 commit 6c03d95
Show file tree
Hide file tree
Showing 55 changed files with 1,094 additions and 668 deletions.
4 changes: 1 addition & 3 deletions .envrc
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
source_url "https://raw.githubusercontent.com/cachix/devenv/d1f7b48e35e6dee421cfd0f51481d17f77586997/direnvrc" "sha256-YBzqskFZxmNb3kYVoKD9ZixoPXJh1C9ZvTLGFRkauZ0="

use devenv
use nix
9 changes: 8 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,11 @@ cabal.project.local~
.aider*

# hie cradle generated automatically
hie.yaml
hie.yaml

.neo
sandbox/*.cabal
sandbox/*.nix

example.cabal
result
28 changes: 11 additions & 17 deletions .hlint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@
# This file contains a template configuration file, which is typically
# placed as .hlint.yaml in the root of your project


# Specify additional command line arguments
#
# - arguments: [--color, --cpp-simple, -XQuasiQuotes]


# Control which extensions/flags/modules/functions can be used
#
# - extensions:
Expand All @@ -28,7 +26,6 @@
# - functions:
# - {name: (.), within: []} # Cannot use (.) at all


# Add custom hints for this project
#
# Will suggest replacing "wibbleMany [myvar]" with "wibbleOne myvar"
Expand Down Expand Up @@ -56,25 +53,22 @@
# Warn on use of partial functions
# - group: {name: partial, enabled: true}


# Ignore some builtin hints
# - ignore: {name: Use let}
# - ignore: {name: Use const, within: SpecialModule} # Only within certain modules
- ignore: {name: Eta reduce}
- ignore: {name: Redundant bracket}
- ignore: {name: Use newtype instead of data}
- ignore: {name: Use const}
- ignore: {name: Avoid lambda using `infix`}
- ignore: {name: Avoid lambda}
- ignore: {name: Use /=}
- ignore: {name: Use <$>}
- ignore: {name: Replace case with maybe}
- ignore: {name: Use when}


- ignore: { name: Eta reduce }
- ignore: { name: Redundant bracket }
- ignore: { name: Use newtype instead of data }
- ignore: { name: Use const }
- ignore: { name: Avoid lambda using `infix` }
- ignore: { name: Avoid lambda }
- ignore: { name: Use /= }
- ignore: { name: Use <$> }
- ignore: { name: Replace case with maybe }
- ignore: { name: Use when }
- ignore: { name: Use lambda case }
# Define some custom infix operators
# - fixity: infixr 3 ~^#^~


# To generate a suitable file for HLint do:
# $ hlint --default > .hlint.yaml
9 changes: 8 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,22 @@
"Appendable",
"clippy",
"Defaultable",
"devenv",
"dont",
"foldl",
"fprint",
"GADT",
"hlint",
"Monoid",
"Nanotime",
"NEOHASKELL",
"nhcore",
"nixfmt",
"nixpkgs",
"NOINLINE",
"optparse",
"OVERLAPPABLE",
"pkgs",
"Posix",
"reldir",
"relfile",
Expand All @@ -24,5 +31,5 @@
"Unagi"
],
"haskell.manageHLS": "PATH",
"nixEnvSelector.nixFile": "${workspaceFolder}/devenv.nix"
"nixEnvSelector.nixFile": "${workspaceFolder}/shell.nix"
}
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ different parts of NeoHaskell.

(This assumes that you're using MacOS, WSL2 or Linux)

- Install DevEnv by following [the official instructions](https://devenv.sh/getting-started/).
- Run `devenv shell`
- Install [Nix](https://nixos.org/download/)
- Run `nix-shell`
- Run `cabal update && cabal build all`

The recommended IDE for any NeoHaskell project is [Visual Studio Code](https://code.visualstudio.com/).
Expand Down
3 changes: 2 additions & 1 deletion cabal.project
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
packages:
*/*.cabal
cli/*.cabal
core/*.cabal
7 changes: 4 additions & 3 deletions cli/app/Main.hs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
module Main where

import Core
import qualified Neo
import Neo qualified
import Task qualified


main :: IO Unit
main = Neo.main
main :: IO ()
main = Task.runOrPanic Neo.run
8 changes: 8 additions & 0 deletions cli/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{ pkgs ? import ../nix/nixpkgs.nix { } }:
pkgs.haskellPackages.developPackage {
root = ./.;
source-overrides = {
nhcore = ../core;
};
modifier = drv: pkgs.haskell.lib.dontHaddock drv;
}
10 changes: 9 additions & 1 deletion cli/nhcli.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ common common_cfg
ghc-options: -Wall
-Werror
-threaded
-fno-warn-partial-type-signatures
-fno-warn-name-shadowing
default-extensions:
ApplicativeDo
BlockArguments
Expand All @@ -28,23 +30,29 @@ common common_cfg
ImpredicativeTypes
ImportQualifiedPost
OverloadedStrings
OverloadedLists
OverloadedLabels
OverloadedRecordDot
DuplicateRecordFields
PackageImports
NamedFieldPuns
Strict
TypeFamilies
PartialTypeSignatures

build-depends:
nhcore,



library
import: common_cfg
exposed-modules:
Neo,
Neo.Build,
Neo.Build.Templates.Cabal,
Neo.Build.Templates.Nix,
Neo.Core,
Neo.Core.ProjectConfiguration,
-- other-modules:
-- other-extensions:
hs-source-dirs: src
Expand Down
139 changes: 75 additions & 64 deletions cli/src/Neo.hs
Original file line number Diff line number Diff line change
@@ -1,28 +1,57 @@
module Neo (main) where
{-# OPTIONS_GHC -fno-warn-name-shadowing #-}

module Neo (
run,
) where

import Action qualified
import Array (Array)
import Array qualified
import Command qualified
import Console qualified
import Core
import File qualified
import Json qualified
import Neo.Build qualified as Build
import Service qualified
import Task qualified
import Text qualified


data State = State
{ build :: Build.State
data CommonFlags = CommonFlags
{ projectFile :: Path
}
deriving (Show, Eq, Ord)


data Event
= Build Build.Event
| NoOp
data NeoCommand
= Build CommonFlags
deriving (Show, Eq, Ord)


commandParser :: Command.OptionsParser Event
commandParser = do
run :: Task _ Unit
run = do
let message1 = "⚠️ NEOHASKELL IS IN ITS EARLY DAYS ⚠️"
let message2 = "HERE BE DRAGONS, BEWARE!"
let msgLength = Text.length message1 + 4
let paddedMessage1 = message1 |> Text.pad msgLength ' '
let paddedMessage2 = message2 |> Text.pad msgLength ' '
Console.print ""
Console.print ""
Console.print paddedMessage1
Console.print paddedMessage2
Console.print ""
Console.print ""
let parser =
Command.CommandOptions
{ name = "neo",
description = "NeoHaskell's console helper",
version = Just [Core.version|0.5.0|],
decoder = commandsParser
}
cmd <- Command.parseHandler parser
handleCommand cmd


commandsParser :: Command.OptionsParser NeoCommand
commandsParser = do
let build =
Command.CommandOptions
{ name = "build",
Expand All @@ -34,57 +63,39 @@ commandParser = do
(Array.fromLinkedList [build])


buildParser :: Command.OptionsParser Event
buildParser :: Command.OptionsParser NeoCommand
buildParser = do
event <- Build.commandParser
pure (Build event)


init :: (State, Action Event)
init = do
let emptyState = State {build = Build.initialState}
let action =
Command.parse
Command.CommandOptions
{ name = "neo",
description = "NeoHaskell's console helper",
version = Just [version|0.5.0|],
decoder = commandParser
}
(emptyState, action)


update :: Event -> State -> (State, Action Event)
update event state =
case event of
Build buildEvent -> do
let (newBuildState, buildAction) = Build.update buildEvent state.build
let newState = state {build = newBuildState}
let action = buildAction |> Action.map Build
(newState, action)
NoOp -> do
let newState = state
let action = Action.none
(newState, action)


view :: State -> Text
view s =
if s.build.message == ""
then "Loading"
else s.build.message


triggers :: Array (Trigger Event)
triggers = Array.empty


main :: IO ()
main =
Service.run
Service.UserApp
{ init = init,
view = view,
triggers = triggers,
update = update
}
common <- flagsParser
pure (Build common)


flagsParser :: Command.OptionsParser CommonFlags
flagsParser = do
projectFilePath <-
Command.path
Command.PathConfig
{ metavar = "PATH",
short = 'c',
help = "Path to the project configuration file",
long = "projectConfig",
value = Just [path|neo.json|]
}
pure (CommonFlags {projectFile = projectFilePath})


data Error
= BuildError Build.Error
| Other
deriving (Show)


handleCommand :: NeoCommand -> Task Error ()
handleCommand command =
case command of
Build flags -> do
txt <- File.readText flags.projectFile |> Task.mapError (\_ -> Other)
case Json.decodeText txt of
Err err -> panic err
Ok config ->
Build.handle config
|> Task.mapError (\e -> BuildError e)
Loading

0 comments on commit 6c03d95

Please sign in to comment.