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

Remove state cwd #47

Merged
merged 1 commit into from
Nov 12, 2015
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
18 changes: 18 additions & 0 deletions app/MainHie.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
module Main where

import Control.Monad
import Control.Monad.Trans.Maybe
import Control.Concurrent
import Control.Exception
import Control.Logging
Expand All @@ -24,6 +25,8 @@ import Haskell.Ide.Engine.Transport.JsonStdio
import Haskell.Ide.Engine.Types
import Options.Applicative.Simple
import qualified Paths_haskell_ide_engine as Meta
import System.Directory
import System.Environment

-- ---------------------------------------------------------------------
-- plugins
Expand Down Expand Up @@ -92,6 +95,14 @@ run opts = do
then setLogLevel LevelDebug
else setLogLevel LevelError

-- We change the current working dirextory of HIE to user home
-- directory so that plugins do not depend on cwd. All paths to
-- all project files referenced in commands are expected to be
-- absolute. Cwd is state and we do not want state in what is
-- async system.

getUserHomeDirectory >>= mapM_ setCurrentDirectory

logm $ "run entered for HIE " ++ version
cin <- newChan :: IO (Chan ChannelRequest)

Expand All @@ -114,6 +125,13 @@ run opts = do
-- At least one needs to be launched, othewise a threadDelay with a large
-- number should be given. Or some other waiting action.

getUserHomeDirectory :: IO (Maybe String)
getUserHomeDirectory = do
-- On POSIX-like $HOME points to user home directory.
-- On Windows %USERPROFILE% points to user home directory.
runMaybeT (msum [ MaybeT $ lookupEnv "HOME"
, MaybeT $ lookupEnv "USERPROFILE"])

-- ---------------------------------------------------------------------

-- |Do whatever it takes to get a request from the IDE.
Expand Down
1 change: 1 addition & 0 deletions haskell-ide-engine.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ executable hie
, Cabal >= 1.22
, aeson
, containers
, directory
, ghc
, ghc-mod
, gitrev >= 1.1
Expand Down
37 changes: 0 additions & 37 deletions src/Haskell/Ide/Engine/BasePlugin.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
module Haskell.Ide.Engine.BasePlugin where

import Control.Monad
import Control.Monad.IO.Class
import Data.Aeson
import Data.Foldable
import Data.List
Expand All @@ -20,7 +19,6 @@ import Haskell.Ide.Engine.PluginUtils
import Options.Applicative.Simple (simpleVersion)
import qualified Paths_haskell_ide_engine as Meta
import Prelude hiding (log)
import System.Directory

-- ---------------------------------------------------------------------

Expand Down Expand Up @@ -70,26 +68,6 @@ baseDescriptor = PluginDescriptor
}
, cmdFunc = commandDetailCmd
}
, Command
{ cmdDesc = CommandDesc
{ cmdName = "pwd"
, cmdUiDescription = "return the current working directory for the HIE process"
, cmdFileExtensions = []
, cmdContexts = [CtxNone]
, cmdAdditionalParams = []
}
, cmdFunc = pwdCmd
}
, Command
{ cmdDesc = CommandDesc
{ cmdName = "cwd"
, cmdUiDescription = "change the current working directory for the HIE process"
, cmdFileExtensions = []
, cmdContexts = [CtxNone]
, cmdAdditionalParams = [RP "dir" "the new working directory" PtFile]
}
, cmdFunc = cwdCmd
}
]
, pdExposedServices = []
, pdUsedServices = []
Expand Down Expand Up @@ -136,21 +114,6 @@ commandDetailCmd _ req = do
Right _ -> return (IdeResponseError (IdeError
InternalError "commandDetailCmd: ghc’s exhaustiveness checker is broken" Nothing))


pwdCmd :: CommandFunc
pwdCmd _ _ = do
dir <- liftIO $ getCurrentDirectory
return (IdeResponseOk (String $ T.pack dir))

cwdCmd :: CommandFunc
cwdCmd _ req = do
case Map.lookup "dir" (ideParams req) of
Nothing -> return $ missingParameter "dir"
Just (ParamFileP dir) -> do
liftIO $ setCurrentDirectory (T.unpack dir)
return (IdeResponseOk Null)
Just x -> return $ incorrectParameter "dir" ("ParamFile"::String) x

-- ---------------------------------------------------------------------

version :: String
Expand Down