Skip to content
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

Allow running load synchronously #137

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
13 changes: 13 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Comment on lines +54 to +66
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is to allow nix users who don't have a global haskell setup to develop cornelis

packages = {
inherit agda;
${name} = pkgs.${name};
Expand Down
27 changes: 17 additions & 10 deletions src/Cornelis/Config.hs
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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 {..}
2 changes: 2 additions & 0 deletions src/Cornelis/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
4 changes: 4 additions & 0 deletions src/Cornelis/Utils.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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 ->
Expand Down
8 changes: 7 additions & 1 deletion src/Lib.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
Loading