From 39e6d3a64365fd002222d47da8ad73d23d9f4ba5 Mon Sep 17 00:00:00 2001 From: Georgi Lyubenov Date: Sun, 18 Feb 2024 17:32:39 +0200 Subject: [PATCH 1/2] Add a devShell for developing cornelis --- flake.nix | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/flake.nix b/flake.nix index d2ddc8b..77cd0aa 100644 --- a/flake.nix +++ b/flake.nix @@ -51,6 +51,19 @@ agda = pkgs.agda.withPackages (p: [ p.standard-library ]); in { + devShells.default = let + hsPkgs = pkgs.haskell.packages.${defaultGhcVersion}; + buildInputs = [ + hsPkgs.ghc + hsPkgs.haskell-language-server + pkgs.cabal-install + pkgs.hpack + pkgs.zlib + ]; + in pkgs.mkShell { + buildInputs = buildInputs; + LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath buildInputs; + }; packages = { inherit agda; ${name} = pkgs.${name}; From 25083372deb99d0ed2f3a25d12ca10ef9538f307 Mon Sep 17 00:00:00 2001 From: Georgi Lyubenov Date: Sun, 18 Feb 2024 18:06:47 +0200 Subject: [PATCH 2/2] Allow running a synchronous load --- src/Cornelis/Config.hs | 27 +++++++++++++++++---------- src/Cornelis/Types.hs | 2 ++ src/Cornelis/Utils.hs | 4 ++++ src/Lib.hs | 8 +++++++- 4 files changed, 30 insertions(+), 11 deletions(-) diff --git a/src/Cornelis/Config.hs b/src/Cornelis/Config.hs index c9aed21..eca0505 100644 --- a/src/Cornelis/Config.hs +++ b/src/Cornelis/Config.hs @@ -1,9 +1,10 @@ {-# LANGUAGE OverloadedStrings #-} +{-# LANGUAGE RecordWildCards #-} module Cornelis.Config where import Cornelis.Types -import Cornelis.Utils (objectToInt, objectToText) +import Cornelis.Utils (objectToInt, objectToText, objectToBool) import Data.Maybe (fromMaybe) import qualified Data.Text as T import Neovim @@ -30,12 +31,18 @@ getVarWithAlternatives = fmap getFirst . foldMap (fmap First . getVar) ------------------------------------------------------------------------------ -- | Build a 'CornelisConfig' from .vimrc getConfig :: Neovim env CornelisConfig -getConfig - = CornelisConfig - <$> fmap (fromMaybe 31 . (objectToInt =<<)) - (getVar "cornelis_max_size") - <*> fmap (fromMaybe 31 . (objectToInt =<<)) - (getVar "cornelis_max_width") - <*> (fromMaybe Horizontal . (>>= (readSplitLocation . T.unpack <=< objectToText)) <$> - getVarWithAlternatives ["cornelis_split_location", "cornelis_split_direction"]) - +getConfig = do + cc_max_height <- + fmap + (fromMaybe 31 . (objectToInt =<<)) + (getVar "cornelis_max_size") + cc_max_width <- + fmap + (fromMaybe 31 . (objectToInt =<<)) + (getVar "cornelis_max_width") + cc_split_location <- + fromMaybe Horizontal . (>>= (readSplitLocation . T.unpack <=< objectToText)) <$> + getVarWithAlternatives ["cornelis_split_location", "cornelis_split_direction"] + cc_sync_load <- + (/= (0 :: Int)) . fromMaybe 0 . (objectToInt =<<) <$> getVar "cornelis_sync_load" + pure CornelisConfig {..} diff --git a/src/Cornelis/Types.hs b/src/Cornelis/Types.hs index 46688d2..6ad31e0 100644 --- a/src/Cornelis/Types.hs +++ b/src/Cornelis/Types.hs @@ -107,6 +107,8 @@ data CornelisConfig = CornelisConfig { cc_max_height :: Int64 , cc_max_width :: Int64 , cc_split_location :: SplitLocation + , cc_sync_load :: Bool + -- ^ should the "load the buffer" command be synchronous? } deriving (Show, Generic) diff --git a/src/Cornelis/Utils.hs b/src/Cornelis/Utils.hs index 123f675..4b9b254 100644 --- a/src/Cornelis/Utils.hs +++ b/src/Cornelis/Utils.hs @@ -31,6 +31,10 @@ objectToText :: Object -> Maybe Text objectToText (ObjectString w) = Just $ decodeUtf8 w objectToText _ = Nothing +objectToBool :: Object -> Maybe Bool +objectToBool (ObjectBool b) = Just b +objectToBool _ = Nothing + neovimAsync :: (MonadUnliftIO m) => m a -> m (Async a) neovimAsync m = withRunInIO $ \lower -> diff --git a/src/Lib.hs b/src/Lib.hs index 7b3b07a..9d5f206 100644 --- a/src/Lib.hs +++ b/src/Lib.hs @@ -196,13 +196,19 @@ cornelis = do let rw_complete = CmdComplete "custom,InternalCornelisRewriteModeCompletion" cm_complete = CmdComplete "custom,InternalCornelisComputeModeCompletion" debug_complete = CmdComplete "custom,InternalCornelisDebugCommandCompletion" + let + loadSyncness = + CmdSync $ + if cc_sync_load $ ce_config env + then Sync + else Async wrapPlugin $ Plugin { environment = env , exports = [ $(command "CornelisRestart" 'doRestart) [CmdSync Async] , $(command "CornelisAbort" 'doAbort) [CmdSync Async] - , $(command "CornelisLoad" 'doLoad) [CmdSync Async] + , $(command "CornelisLoad" 'doLoad) [loadSyncness] , $(command "CornelisGoals" 'doAllGoals) [CmdSync Async] , $(command "CornelisSolve" 'solveOne) [CmdSync Async, rw_complete] , $(command "CornelisAuto" 'autoOne) [CmdSync Async]