Skip to content

Commit 6d7f7fc

Browse files
authored
Merge pull request #99 from mdibaiee/trailing-character
(80) fix: use System.FilePath's functions to take filename and dirname
2 parents 28c1527 + c044ed0 commit 6d7f7fc

File tree

2 files changed

+7
-15
lines changed

2 files changed

+7
-15
lines changed

src/common/HaskellDo/Compilation/State.hs

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import qualified System.Process as System
2222
import qualified System.Exit as System
2323
import qualified Data.Text as Text
2424
import System.Directory
25+
import System.FilePath ((</>), takeDirectory, takeFileName, dropTrailingPathSeparator)
2526

2627
import Transient.Move
2728

@@ -32,7 +33,7 @@ initialState = State
3233
{ compiledOutput = ""
3334
, compilationError = "No project has been loaded yet, try opening one?"
3435
, projectPath = ""
35-
, workingFile = "/src/Main.hs"
36+
, workingFile = "src/Main.hs"
3637
}
3738

3839
lastProjectFile :: FilePath
@@ -51,7 +52,7 @@ update Compile state = do
5152

5253
writeWorkingFile :: String -> State -> IO ()
5354
writeWorkingFile content state = do
54-
let fullPath = projectPath state ++ workingFile state
55+
let fullPath = projectPath state </> workingFile state
5556
fileExists <- doesFileExist fullPath
5657
when fileExists (writeCode fullPath content)
5758

@@ -108,23 +109,14 @@ preprocessOutput out =
108109

109110
makeNewProject :: String -> IO ()
110111
makeNewProject path = do
111-
let projectName = dirname path
112-
let parentDir = parent path
112+
let p = dropTrailingPathSeparator path
113+
let projectName = takeFileName p
114+
let parentDir = takeDirectory p
113115
putStrLn path
114116
putStrLn projectName
115117
putStrLn parentDir
116118
_ <- runCommand ("new " ++ projectName ++ " " ++ templateURL) parentDir
117119
return ()
118-
where
119-
dirname p = init p
120-
|> reverse
121-
|> takeWhile (/= '/')
122-
|> reverse
123-
parent p = init p
124-
|> reverse
125-
|> dropWhile (/= '/')
126-
|> tail
127-
|> reverse
128120

129121
runCommand :: String -> FilePath -> IO (System.ExitCode, String, String)
130122
runCommand command projPath = do

src/common/HaskellDo/State.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ update (ToolbarAction Toolbar.LoadProject) appState = do
8282
let filePath = Compilation.workingFile (compilationState appState)
8383
atRemote $ localIO $
8484
when (Toolbar.createProject tbState) (Compilation.makeNewProject projectPath)
85-
readAtRemote (projectPath ++ filePath) >>= \case
85+
readAtRemote (projectPath </> filePath) >>= \case
8686
Left _ -> do
8787
let newTbState = tbState { Toolbar.projectOpened = False }
8888
let newCmpState = cmpState

0 commit comments

Comments
 (0)