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

Commit 15a4b91

Browse files
committed
Merge pull request #47 from gracjan/pr-remove-state-cwd
Remove state cwd
2 parents f7f4251 + d0636f8 commit 15a4b91

File tree

3 files changed

+19
-37
lines changed

3 files changed

+19
-37
lines changed

app/MainHie.hs

+18
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
module Main where
66

77
import Control.Monad
8+
import Control.Monad.Trans.Maybe
89
import Control.Concurrent
910
import Control.Exception
1011
import Control.Logging
@@ -24,6 +25,8 @@ import Haskell.Ide.Engine.Transport.JsonStdio
2425
import Haskell.Ide.Engine.Types
2526
import Options.Applicative.Simple
2627
import qualified Paths_haskell_ide_engine as Meta
28+
import System.Directory
29+
import System.Environment
2730

2831
-- ---------------------------------------------------------------------
2932
-- plugins
@@ -92,6 +95,14 @@ run opts = do
9295
then setLogLevel LevelDebug
9396
else setLogLevel LevelError
9497

98+
-- We change the current working dirextory of HIE to user home
99+
-- directory so that plugins do not depend on cwd. All paths to
100+
-- all project files referenced in commands are expected to be
101+
-- absolute. Cwd is state and we do not want state in what is
102+
-- async system.
103+
104+
getUserHomeDirectory >>= mapM_ setCurrentDirectory
105+
95106
logm $ "run entered for HIE " ++ version
96107
cin <- newChan :: IO (Chan ChannelRequest)
97108

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

128+
getUserHomeDirectory :: IO (Maybe String)
129+
getUserHomeDirectory = do
130+
-- On POSIX-like $HOME points to user home directory.
131+
-- On Windows %USERPROFILE% points to user home directory.
132+
runMaybeT (msum [ MaybeT $ lookupEnv "HOME"
133+
, MaybeT $ lookupEnv "USERPROFILE"])
134+
117135
-- ---------------------------------------------------------------------
118136

119137
-- |Do whatever it takes to get a request from the IDE.

haskell-ide-engine.cabal

+1
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ executable hie
6666
, Cabal >= 1.22
6767
, aeson
6868
, containers
69+
, directory
6970
, ghc
7071
, ghc-mod
7172
, gitrev >= 1.1

src/Haskell/Ide/Engine/BasePlugin.hs

-37
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
module Haskell.Ide.Engine.BasePlugin where
55

66
import Control.Monad
7-
import Control.Monad.IO.Class
87
import Data.Aeson
98
import Data.Foldable
109
import Data.List
@@ -20,7 +19,6 @@ import Haskell.Ide.Engine.PluginUtils
2019
import Options.Applicative.Simple (simpleVersion)
2120
import qualified Paths_haskell_ide_engine as Meta
2221
import Prelude hiding (log)
23-
import System.Directory
2422

2523
-- ---------------------------------------------------------------------
2624

@@ -70,26 +68,6 @@ baseDescriptor = PluginDescriptor
7068
}
7169
, cmdFunc = commandDetailCmd
7270
}
73-
, Command
74-
{ cmdDesc = CommandDesc
75-
{ cmdName = "pwd"
76-
, cmdUiDescription = "return the current working directory for the HIE process"
77-
, cmdFileExtensions = []
78-
, cmdContexts = [CtxNone]
79-
, cmdAdditionalParams = []
80-
}
81-
, cmdFunc = pwdCmd
82-
}
83-
, Command
84-
{ cmdDesc = CommandDesc
85-
{ cmdName = "cwd"
86-
, cmdUiDescription = "change the current working directory for the HIE process"
87-
, cmdFileExtensions = []
88-
, cmdContexts = [CtxNone]
89-
, cmdAdditionalParams = [RP "dir" "the new working directory" PtFile]
90-
}
91-
, cmdFunc = cwdCmd
92-
}
9371
]
9472
, pdExposedServices = []
9573
, pdUsedServices = []
@@ -136,21 +114,6 @@ commandDetailCmd _ req = do
136114
Right _ -> return (IdeResponseError (IdeError
137115
InternalError "commandDetailCmd: ghc’s exhaustiveness checker is broken" Nothing))
138116

139-
140-
pwdCmd :: CommandFunc
141-
pwdCmd _ _ = do
142-
dir <- liftIO $ getCurrentDirectory
143-
return (IdeResponseOk (String $ T.pack dir))
144-
145-
cwdCmd :: CommandFunc
146-
cwdCmd _ req = do
147-
case Map.lookup "dir" (ideParams req) of
148-
Nothing -> return $ missingParameter "dir"
149-
Just (ParamFileP dir) -> do
150-
liftIO $ setCurrentDirectory (T.unpack dir)
151-
return (IdeResponseOk Null)
152-
Just x -> return $ incorrectParameter "dir" ("ParamFile"::String) x
153-
154117
-- ---------------------------------------------------------------------
155118

156119
version :: String

0 commit comments

Comments
 (0)