fix #295.
This commit is contained in:
parent
e22cc4383b
commit
625d4661e7
@ -133,6 +133,7 @@ Executable ghc-modi
|
|||||||
Default-Language: Haskell2010
|
Default-Language: Haskell2010
|
||||||
Main-Is: GHCModi.hs
|
Main-Is: GHCModi.hs
|
||||||
Other-Modules: Paths_ghc_mod
|
Other-Modules: Paths_ghc_mod
|
||||||
|
Utils
|
||||||
GHC-Options: -Wall -threaded
|
GHC-Options: -Wall -threaded
|
||||||
Default-Extensions: ConstraintKinds, FlexibleContexts
|
Default-Extensions: ConstraintKinds, FlexibleContexts
|
||||||
HS-Source-Dirs: src
|
HS-Source-Dirs: src
|
||||||
|
@ -39,6 +39,8 @@ import System.Directory (setCurrentDirectory)
|
|||||||
import System.Environment (getArgs)
|
import System.Environment (getArgs)
|
||||||
import System.IO (hFlush,stdout)
|
import System.IO (hFlush,stdout)
|
||||||
|
|
||||||
|
import Utils
|
||||||
|
|
||||||
----------------------------------------------------------------
|
----------------------------------------------------------------
|
||||||
|
|
||||||
type Logger = IO String
|
type Logger = IO String
|
||||||
@ -231,7 +233,7 @@ showInfo :: IOish m
|
|||||||
-> FilePath
|
-> FilePath
|
||||||
-> GhcModT m (String, Bool, Set FilePath)
|
-> GhcModT m (String, Bool, Set FilePath)
|
||||||
showInfo set fileArg = do
|
showInfo set fileArg = do
|
||||||
let [file, expr] = words fileArg
|
let [file, expr] = splitN 2 fileArg
|
||||||
set' <- newFileSet set file
|
set' <- newFileSet set file
|
||||||
ret <- info file expr
|
ret <- info file expr
|
||||||
return (ret, True, set')
|
return (ret, True, set')
|
||||||
@ -241,7 +243,7 @@ showType :: IOish m
|
|||||||
-> FilePath
|
-> FilePath
|
||||||
-> GhcModT m (String, Bool, Set FilePath)
|
-> GhcModT m (String, Bool, Set FilePath)
|
||||||
showType set fileArg = do
|
showType set fileArg = do
|
||||||
let [file, line, column] = words fileArg
|
let [file, line, column] = splitN 3 fileArg
|
||||||
set' <- newFileSet set file
|
set' <- newFileSet set file
|
||||||
ret <- types file (read line) (read column)
|
ret <- types file (read line) (read column)
|
||||||
return (ret, True, set')
|
return (ret, True, set')
|
||||||
@ -251,7 +253,7 @@ doSplit :: IOish m
|
|||||||
-> FilePath
|
-> FilePath
|
||||||
-> GhcModT m (String, Bool, Set FilePath)
|
-> GhcModT m (String, Bool, Set FilePath)
|
||||||
doSplit set fileArg = do
|
doSplit set fileArg = do
|
||||||
let [file, line, column] = words fileArg
|
let [file, line, column] = splitN 3 fileArg
|
||||||
set' <- newFileSet set file
|
set' <- newFileSet set file
|
||||||
ret <- splits file (read line) (read column)
|
ret <- splits file (read line) (read column)
|
||||||
return (ret, True, set')
|
return (ret, True, set')
|
||||||
@ -261,7 +263,7 @@ doSig :: IOish m
|
|||||||
-> FilePath
|
-> FilePath
|
||||||
-> GhcModT m (String, Bool, Set FilePath)
|
-> GhcModT m (String, Bool, Set FilePath)
|
||||||
doSig set fileArg = do
|
doSig set fileArg = do
|
||||||
let [file, line, column] = words fileArg
|
let [file, line, column] = splitN 3 fileArg
|
||||||
set' <- newFileSet set file
|
set' <- newFileSet set file
|
||||||
ret <- sig file (read line) (read column)
|
ret <- sig file (read line) (read column)
|
||||||
return (ret, True, set')
|
return (ret, True, set')
|
||||||
@ -271,7 +273,7 @@ doRefine :: IOish m
|
|||||||
-> FilePath
|
-> FilePath
|
||||||
-> GhcModT m (String, Bool, Set FilePath)
|
-> GhcModT m (String, Bool, Set FilePath)
|
||||||
doRefine set fileArg = do
|
doRefine set fileArg = do
|
||||||
let [file, line, column, expr] = words fileArg
|
let [file, line, column, expr] = splitN 4 fileArg
|
||||||
set' <- newFileSet set file
|
set' <- newFileSet set file
|
||||||
ret <- refine file (read line) (read column) expr
|
ret <- refine file (read line) (read column) expr
|
||||||
return (ret, True, set')
|
return (ret, True, set')
|
||||||
@ -281,7 +283,7 @@ doAuto :: IOish m
|
|||||||
-> FilePath
|
-> FilePath
|
||||||
-> GhcModT m (String, Bool, Set FilePath)
|
-> GhcModT m (String, Bool, Set FilePath)
|
||||||
doAuto set fileArg = do
|
doAuto set fileArg = do
|
||||||
let [file, line, column] = words fileArg
|
let [file, line, column] = splitN 3 fileArg
|
||||||
set' <- newFileSet set file
|
set' <- newFileSet set file
|
||||||
ret <- auto file (read line) (read column)
|
ret <- auto file (read line) (read column)
|
||||||
return (ret, True, set')
|
return (ret, True, set')
|
||||||
|
27
src/Utils.hs
Normal file
27
src/Utils.hs
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
module Utils where
|
||||||
|
|
||||||
|
-- |
|
||||||
|
--
|
||||||
|
-- >>> split "foo bar baz"
|
||||||
|
-- ["foo","bar baz"]
|
||||||
|
-- >>> split "foo bar baz"
|
||||||
|
-- ["foo","bar baz"]
|
||||||
|
split :: String -> [String]
|
||||||
|
split xs = [ys, dropWhile isSpace zs]
|
||||||
|
where
|
||||||
|
isSpace = (== ' ')
|
||||||
|
(ys,zs) = break isSpace xs
|
||||||
|
|
||||||
|
-- |
|
||||||
|
--
|
||||||
|
-- >>> splitN 0 "foo bar baz"
|
||||||
|
-- ["foo","bar baz"]
|
||||||
|
-- >>> splitN 2 "foo bar baz"
|
||||||
|
-- ["foo","bar baz"]
|
||||||
|
-- >>> splitN 3 "foo bar baz"
|
||||||
|
-- ["foo","bar","baz"]
|
||||||
|
splitN :: Int -> String -> [String]
|
||||||
|
splitN n xs
|
||||||
|
| n <= 2 = split xs
|
||||||
|
| otherwise = let [ys,zs] = split xs
|
||||||
|
in ys : splitN (n - 1) zs
|
Loading…
Reference in New Issue
Block a user