Commit e86272af authored by Andrew Gibiansky's avatar Andrew Gibiansky

Removing MissingH

parent 17582024
...@@ -73,7 +73,6 @@ library ...@@ -73,7 +73,6 @@ library
haskell-src-exts ==1.16.*, haskell-src-exts ==1.16.*,
http-client == 0.4.*, http-client == 0.4.*,
http-client-tls == 0.2.*, http-client-tls == 0.2.*,
MissingH >=1.2,
mtl >=2.1, mtl >=2.1,
parsec -any, parsec -any,
process >=1.1, process >=1.1,
...@@ -116,6 +115,7 @@ library ...@@ -116,6 +115,7 @@ library
Paths_ihaskell Paths_ihaskell
other-modules: other-modules:
IHaskellPrelude IHaskellPrelude
StringUtils
default-extensions: default-extensions:
NoImplicitPrelude NoImplicitPrelude
...@@ -182,7 +182,6 @@ Test-Suite hspec ...@@ -182,7 +182,6 @@ Test-Suite hspec
haskell-src-exts ==1.16.*, haskell-src-exts ==1.16.*,
hspec -any, hspec -any,
HUnit -any, HUnit -any,
MissingH >=1.2,
mtl >=2.1, mtl >=2.1,
parsec -any, parsec -any,
process >=1.1, process >=1.1,
......
...@@ -13,8 +13,6 @@ import Text.Parsec ...@@ -13,8 +13,6 @@ import Text.Parsec
import Text.Parsec.String import Text.Parsec.String
import Control.Applicative hiding ((<|>), many) import Control.Applicative hiding ((<|>), many)
import Data.String.Utils (startswith)
import Shelly import Shelly
data BrokenPackage = BrokenPackage { packageID :: String, brokenDeps :: [String] } data BrokenPackage = BrokenPackage { packageID :: String, brokenDeps :: [String] }
...@@ -30,8 +28,8 @@ getBrokenPackages = shelly $ do ...@@ -30,8 +28,8 @@ getBrokenPackages = shelly $ do
checkOut <- lastStderr checkOut <- lastStderr
-- Get rid of extraneous things -- Get rid of extraneous things
let rightStart str = startswith "There are problems" str || let rightStart str = "There are problems" `isPrefixOf` str ||
startswith " dependency" str " dependency" `isPrefixOf` str
ghcPkgOutput = unlines . filter rightStart . lines $ T.unpack checkOut ghcPkgOutput = unlines . filter rightStart . lines $ T.unpack checkOut
return $ return $
......
...@@ -56,7 +56,6 @@ import qualified Data.ByteString.Lazy as LBS ...@@ -56,7 +56,6 @@ import qualified Data.ByteString.Lazy as LBS
import qualified Data.ByteString.Char8 as CBS import qualified Data.ByteString.Char8 as CBS
import Data.Serialize as Serialize import Data.Serialize as Serialize
import Data.String.Utils (rstrip)
import qualified Data.ByteString.Base64 as Base64 import qualified Data.ByteString.Base64 as Base64
import Data.Aeson (Value) import Data.Aeson (Value)
import System.Directory (getTemporaryDirectory, setCurrentDirectory) import System.Directory (getTemporaryDirectory, setCurrentDirectory)
...@@ -69,6 +68,7 @@ import System.IO.Unsafe (unsafePerformIO) ...@@ -69,6 +68,7 @@ import System.IO.Unsafe (unsafePerformIO)
import qualified Data.Text.Encoding as E import qualified Data.Text.Encoding as E
import IHaskell.Types import IHaskell.Types
import StringUtils (rstrip)
type Base64 = Text type Base64 = Text
......
...@@ -23,11 +23,9 @@ import Control.Applicative ((<$>)) ...@@ -23,11 +23,9 @@ import Control.Applicative ((<$>))
import Data.ByteString.UTF8 hiding (drop, take, lines, length) import Data.ByteString.UTF8 hiding (drop, take, lines, length)
import Data.Char import Data.Char
import Data.List (nub, init, last, head, elemIndex) import Data.List (nub, init, last, head, elemIndex)
import Data.List.Split import qualified Data.List.Split as Split
import Data.List.Split.Internals import qualified Data.List.Split.Internals as Split
import Data.Maybe (fromJust) import Data.Maybe (fromJust)
import Data.String.Utils (strip, startswith, endswith, replace)
import qualified Data.String.Utils as StringUtils
import System.Environment (getEnv) import System.Environment (getEnv)
import GHC hiding (Qualified) import GHC hiding (Qualified)
...@@ -51,6 +49,7 @@ import System.Console.Haskeline.Completion ...@@ -51,6 +49,7 @@ import System.Console.Haskeline.Completion
import IHaskell.Types import IHaskell.Types
import IHaskell.Eval.Evaluate (Interpreter) import IHaskell.Eval.Evaluate (Interpreter)
import IHaskell.Eval.ParseShell (parseShell) import IHaskell.Eval.ParseShell (parseShell)
import StringUtils (replace, strip, split)
data CompletionType = Empty data CompletionType = Empty
| Identifier String | Identifier String
...@@ -179,17 +178,17 @@ completionType :: String -- ^ The line on which the completion is bei ...@@ -179,17 +178,17 @@ completionType :: String -- ^ The line on which the completion is bei
-> CompletionType -> CompletionType
completionType line loc target completionType line loc target
-- File and directory completions are special -- File and directory completions are special
| startswith ":!" stripped = | ":!" `isPrefixOf` stripped =
fileComplete FilePath fileComplete FilePath
| startswith ":l" stripped = | ":l" `isPrefixOf` stripped =
fileComplete HsFilePath fileComplete HsFilePath
-- Complete :set, :opt, and :ext -- Complete :set, :opt, and :ext
| startswith ":s" stripped = | ":s" `isPrefixOf` stripped =
DynFlag candidate DynFlag candidate
| startswith ":o" stripped = | ":o" `isPrefixOf` stripped =
KernelOption candidate KernelOption candidate
| startswith ":e" stripped = | ":e" `isPrefixOf` stripped =
Extension candidate Extension candidate
-- Use target for other completions. If it's empty, no completion. -- Use target for other completions. If it's empty, no completion.
...@@ -201,7 +200,7 @@ completionType line loc target ...@@ -201,7 +200,7 @@ completionType line loc target
FilePath (getStringTarget lineUpToCursor) (getStringTarget lineUpToCursor) FilePath (getStringTarget lineUpToCursor) (getStringTarget lineUpToCursor)
-- Complete module names in imports and elsewhere. -- Complete module names in imports and elsewhere.
| startswith "import" stripped && isModName = | "import" `isPrefixOf` stripped && isModName =
ModuleName dotted candidate ModuleName dotted candidate
| isModName && (not . null . init) target = | isModName && (not . null . init) target =
Qualified dotted candidate Qualified dotted candidate
...@@ -225,7 +224,7 @@ completionType line loc target ...@@ -225,7 +224,7 @@ completionType line loc target
fileComplete filePath = fileComplete filePath =
case parseShell lineUpToCursor of case parseShell lineUpToCursor of
Right xs -> filePath lineUpToCursor $ Right xs -> filePath lineUpToCursor $
if endswith (last xs) lineUpToCursor if last xs `isSuffixOf` lineUpToCursor
then last xs then last xs
else [] else []
Left _ -> Empty Left _ -> Empty
...@@ -256,14 +255,14 @@ completionTarget :: String -> Int -> [String] ...@@ -256,14 +255,14 @@ completionTarget :: String -> Int -> [String]
completionTarget code cursor = expandCompletionPiece pieceToComplete completionTarget code cursor = expandCompletionPiece pieceToComplete
where where
pieceToComplete = map fst <$> find (elem cursor . map snd) pieces pieceToComplete = map fst <$> find (elem cursor . map snd) pieces
pieces = splitAlongCursor $ split splitter $ zip code [1 ..] pieces = splitAlongCursor $ Split.split splitter $ zip code [1 ..]
splitter = defaultSplitter splitter = Split.defaultSplitter
{ {
-- Split using only the characters, which are the first elements of the (char, index) tuple -- Split using only the characters, which are the first elements of the (char, index) tuple
delimiter = Delimiter [uncurry isDelim] Split.delimiter = Split.Delimiter [uncurry isDelim]
-- Condense multiple delimiters into one and then drop them. -- Condense multiple delimiters into one and then drop them.
, condensePolicy = Condense , Split.condensePolicy = Split.Condense
, delimPolicy = Drop , Split.delimPolicy = Split.Drop
} }
isDelim :: Char -> Int -> Bool isDelim :: Char -> Int -> Bool
...@@ -281,7 +280,7 @@ completionTarget code cursor = expandCompletionPiece pieceToComplete ...@@ -281,7 +280,7 @@ completionTarget code cursor = expandCompletionPiece pieceToComplete
neverIdent = " \n\t(),{}[]\\'\"`" neverIdent = " \n\t(),{}[]\\'\"`"
expandCompletionPiece Nothing = [] expandCompletionPiece Nothing = []
expandCompletionPiece (Just str) = splitOn "." str expandCompletionPiece (Just str) = Split.splitOn "." str
getHome :: IO String getHome :: IO String
getHome = do getHome = do
...@@ -313,7 +312,7 @@ completePathWithExtensions extensions line = ...@@ -313,7 +312,7 @@ completePathWithExtensions extensions line =
acceptAll = const True acceptAll = const True
extensionIsOneOf exts str = any correctEnding exts extensionIsOneOf exts str = any correctEnding exts
where where
correctEnding ext = endswith ext str correctEnding ext = ext `isSuffixOf` str
completePathFilter :: (String -> Bool) -- ^ File filter: test whether to include this file. completePathFilter :: (String -> Bool) -- ^ File filter: test whether to include this file.
-> (String -> Bool) -- ^ Directory filter: test whether to include this directory. -> (String -> Bool) -- ^ Directory filter: test whether to include this directory.
...@@ -334,8 +333,8 @@ completePathFilter includeFile includeDirectory left right = GhcMonad.liftIO $ d ...@@ -334,8 +333,8 @@ completePathFilter includeFile includeDirectory left right = GhcMonad.liftIO $ d
-- everything else. If we wanted to keep original order, we could instead use -- everything else. If we wanted to keep original order, we could instead use
-- filter (`elem` (dirs ++ files)) completions -- filter (`elem` (dirs ++ files)) completions
suggestions <- mapM unDirExpand $ dirs ++ files suggestions <- mapM unDirExpand $ dirs ++ files
let isHidden str = startswith "." . last . StringUtils.split "/" $ let isHidden str = isPrefixOf "." . last . split "/" $
if endswith "/" str if "/" `isSuffixOf` str
then init str then init str
else str else str
visible = filter (not . isHidden) suggestions visible = filter (not . isHidden) suggestions
......
...@@ -24,9 +24,7 @@ import qualified Data.ByteString.Char8 as CBS ...@@ -24,9 +24,7 @@ import qualified Data.ByteString.Char8 as CBS
import Control.Concurrent (forkIO, threadDelay) import Control.Concurrent (forkIO, threadDelay)
import Prelude (putChar, head, tail, last, init, (!!)) import Prelude (putChar, head, tail, last, init, (!!))
import Data.List.Utils
import Data.List (findIndex, and, foldl1, nubBy) import Data.List (findIndex, and, foldl1, nubBy)
import Data.String.Utils
import Text.Printf import Text.Printf
import Data.Char as Char import Data.Char as Char
import Data.Dynamic import Data.Dynamic
...@@ -86,6 +84,7 @@ import qualified IHaskell.Eval.Hoogle as Hoogle ...@@ -86,6 +84,7 @@ import qualified IHaskell.Eval.Hoogle as Hoogle
import IHaskell.Eval.Util import IHaskell.Eval.Util
import IHaskell.BrokenPackages import IHaskell.BrokenPackages
import qualified IHaskell.IPython.Message.UUID as UUID import qualified IHaskell.IPython.Message.UUID as UUID
import StringUtils (replace, split, strip, rstrip)
import Paths_ihaskell (version) import Paths_ihaskell (version)
import Data.Version (versionBranch) import Data.Version (versionBranch)
...@@ -570,7 +569,7 @@ evalCommand _ (Directive LoadFile names) state = wrapExecution state $ do ...@@ -570,7 +569,7 @@ evalCommand _ (Directive LoadFile names) state = wrapExecution state $ do
write state $ "Load: " ++ names write state $ "Load: " ++ names
displays <- forM (words names) $ \name -> do displays <- forM (words names) $ \name -> do
let filename = if endswith ".hs" name let filename = if ".hs" `isSuffixOf` name
then name then name
else name ++ ".hs" else name ++ ".hs"
contents <- liftIO $ readFile filename contents <- liftIO $ readFile filename
...@@ -855,7 +854,7 @@ evalCommand output (Expression expr) state = do ...@@ -855,7 +854,7 @@ evalCommand output (Expression expr) state = do
isShowError (Display errs) = isShowError (Display errs) =
-- Note that we rely on this error message being 'type cleaned', so that `Show` is not displayed as -- Note that we rely on this error message being 'type cleaned', so that `Show` is not displayed as
-- GHC.Show.Show. This is also very fragile! -- GHC.Show.Show. This is also very fragile!
startswith "No instance for (Show" msg && "No instance for (Show" `isPrefixOf` msg &&
isInfixOf "print it" msg isInfixOf "print it" msg
where where
msg = extractPlain errs msg = extractPlain errs
...@@ -1250,7 +1249,7 @@ formatErrorWithClass cls = ...@@ -1250,7 +1249,7 @@ formatErrorWithClass cls =
fixDollarSigns = replace "$" "<span>$</span>" fixDollarSigns = replace "$" "<span>$</span>"
useDashV = "\nUse -v to see a list of the files searched for." useDashV = "\nUse -v to see a list of the files searched for."
isShowError err = isShowError err =
startswith "No instance for (Show" err && "No instance for (Show" `isPrefixOf` err &&
isInfixOf " arising from a use of `print'" err isInfixOf " arising from a use of `print'" err
formatParseError :: StringLoc -> String -> ErrMsg formatParseError :: StringLoc -> String -> ErrMsg
......
...@@ -18,12 +18,12 @@ import qualified Data.ByteString.Char8 as CBS ...@@ -18,12 +18,12 @@ import qualified Data.ByteString.Char8 as CBS
import Network.HTTP.Client import Network.HTTP.Client
import Network.HTTP.Client.TLS import Network.HTTP.Client.TLS
import Data.Aeson import Data.Aeson
import Data.String.Utils
import qualified Data.List as List import qualified Data.List as List
import Data.Char (isAscii, isAlphaNum) import Data.Char (isAscii, isAlphaNum)
import IHaskell.IPython import IHaskell.IPython
import StringUtils (split, strip, replace)
-- | Types of formats to render output to. -- | Types of formats to render output to.
data OutputFormat = Plain -- ^ Render to plain text. data OutputFormat = Plain -- ^ Render to plain text.
...@@ -156,22 +156,22 @@ renderHtml (SearchResult resp) = ...@@ -156,22 +156,22 @@ renderHtml (SearchResult resp) =
renderSelf :: String -> String -> String renderSelf :: String -> String -> String
renderSelf string loc renderSelf string loc
| startswith "package" string = | "package" `isPrefixOf` string =
pkg ++ " " ++ span "hoogle-package" (link loc $ extractPackage string) pkg ++ " " ++ span "hoogle-package" (link loc $ extractPackage string)
| startswith "module" string = | "module" `isPrefixOf` string =
let package = extractPackageName loc let package = extractPackageName loc
in mod ++ " " ++ in mod ++ " " ++
span "hoogle-module" (link loc $ extractModule string) ++ span "hoogle-module" (link loc $ extractModule string) ++
packageSub package packageSub package
| startswith "class" string = | "class" `isPrefixOf` string =
let package = extractPackageName loc let package = extractPackageName loc
in cls ++ " " ++ in cls ++ " " ++
span "hoogle-class" (link loc $ extractClass string) ++ span "hoogle-class" (link loc $ extractClass string) ++
packageSub package packageSub package
| startswith "data" string = | "data" `isPrefixOf` string =
let package = extractPackageName loc let package = extractPackageName loc
in dat ++ " " ++ in dat ++ " " ++
span "hoogle-class" (link loc $ extractData string) ++ span "hoogle-class" (link loc $ extractData string) ++
...@@ -221,9 +221,9 @@ renderDocs doc = ...@@ -221,9 +221,9 @@ renderDocs doc =
let groups = List.groupBy bothAreCode $ lines doc let groups = List.groupBy bothAreCode $ lines doc
nonull = filter (not . null . strip) nonull = filter (not . null . strip)
bothAreCode s1 s2 = bothAreCode s1 s2 =
startswith ">" (strip s1) && isPrefixOf ">" (strip s1) &&
startswith ">" (strip s2) isPrefixOf ">" (strip s2)
isCode (s:_) = startswith ">" $ strip s isCode (s:_) = isPrefixOf ">" $ strip s
makeBlock lines = makeBlock lines =
if isCode lines if isCode lines
then div' "hoogle-code" $ unlines $ nonull lines then div' "hoogle-code" $ unlines $ nonull lines
......
...@@ -9,11 +9,9 @@ import qualified Data.ByteString as BS ...@@ -9,11 +9,9 @@ import qualified Data.ByteString as BS
import qualified Data.ByteString.Lazy as LBS import qualified Data.ByteString.Lazy as LBS
import qualified Data.ByteString.Char8 as CBS import qualified Data.ByteString.Char8 as CBS
import Data.String.Utils (replace, startswith, strip, split)
import Prelude (head, tail, last) import Prelude (head, tail, last)
import Control.Monad import Control.Monad
import Data.List (findIndex) import Data.List (findIndex)
import Text.Printf
import Data.String.Here import Data.String.Here
import Data.Char import Data.Char
import Data.Monoid import Data.Monoid
...@@ -34,6 +32,7 @@ import IHaskell.Types ...@@ -34,6 +32,7 @@ import IHaskell.Types
import IHaskell.Display import IHaskell.Display
import IHaskell.IPython import IHaskell.IPython
import IHaskell.Eval.Parser hiding (line) import IHaskell.Eval.Parser hiding (line)
import StringUtils (replace)
type ExtsModule = SrcExts.Module SrcSpanInfo type ExtsModule = SrcExts.Module SrcSpanInfo
......
...@@ -23,7 +23,6 @@ import qualified Data.ByteString.Lazy as LBS ...@@ -23,7 +23,6 @@ import qualified Data.ByteString.Lazy as LBS
import qualified Data.ByteString.Char8 as CBS import qualified Data.ByteString.Char8 as CBS
import Data.List (maximumBy, inits) import Data.List (maximumBy, inits)
import Data.String.Utils (startswith, strip, split)
import Prelude (head, tail) import Prelude (head, tail)
import Control.Monad (msum) import Control.Monad (msum)
...@@ -31,6 +30,7 @@ import GHC hiding (Located) ...@@ -31,6 +30,7 @@ import GHC hiding (Located)
import Language.Haskell.GHC.Parser import Language.Haskell.GHC.Parser
import IHaskell.Eval.Util import IHaskell.Eval.Util
import StringUtils (strip, split)
-- | A block of code to be evaluated. Each block contains a single element - one declaration, -- | A block of code to be evaluated. Each block contains a single element - one declaration,
-- statement, expression, etc. If parsing of the block failed, the block is instead a ParseError, -- statement, expression, etc. If parsing of the block failed, the block is instead a ParseError,
...@@ -113,11 +113,11 @@ parseString codeString = do ...@@ -113,11 +113,11 @@ parseString codeString = do
-- Test whether a given chunk is a directive. -- Test whether a given chunk is a directive.
isDirective :: String -> Bool isDirective :: String -> Bool
isDirective = startswith ":" . strip isDirective = isPrefixOf ":" . strip
-- Test if a chunk is a pragma. -- Test if a chunk is a pragma.
isPragma :: String -> Bool isPragma :: String -> Bool
isPragma = startswith "{-#" . strip isPragma = isPrefixOf "{-#" . strip
activateExtensions :: GhcMonad m => CodeBlock -> m () activateExtensions :: GhcMonad m => CodeBlock -> m ()
activateExtensions (Directive SetExtension ext) = void $ setExtension ext activateExtensions (Directive SetExtension ext) = void $ setExtension ext
......
...@@ -52,9 +52,10 @@ import qualified Outputable as O ...@@ -52,9 +52,10 @@ import qualified Outputable as O
import Control.Monad (void) import Control.Monad (void)
import Data.Function (on) import Data.Function (on)
import Data.String.Utils (replace)
import Data.List (nubBy) import Data.List (nubBy)
import StringUtils (replace)
-- | A extension flag that can be set or unset. -- | A extension flag that can be set or unset.
data ExtFlag = SetFlag ExtensionFlag data ExtFlag = SetFlag ExtensionFlag
| UnsetFlag ExtensionFlag | UnsetFlag ExtensionFlag
......
...@@ -26,8 +26,6 @@ import qualified Shelly as SH ...@@ -26,8 +26,6 @@ import qualified Shelly as SH
import qualified System.IO as IO import qualified System.IO as IO
import qualified System.FilePath as FP import qualified System.FilePath as FP
import System.Directory import System.Directory
import Data.List.Utils (split)
import Data.String.Utils (rstrip, endswith, strip, replace)
import System.Exit (exitFailure) import System.Exit (exitFailure)
import Data.Aeson (toJSON) import Data.Aeson (toJSON)
import Data.Aeson.Encode (encodeToTextBuilder) import Data.Aeson.Encode (encodeToTextBuilder)
...@@ -40,6 +38,8 @@ import qualified GHC.Paths ...@@ -40,6 +38,8 @@ import qualified GHC.Paths
import IHaskell.Types import IHaskell.Types
import System.Posix.Signals import System.Posix.Signals
import StringUtils (replace, split)
data KernelSpecOptions = data KernelSpecOptions =
KernelSpecOptions KernelSpecOptions
{ kernelSpecGhcLibdir :: String -- ^ GHC libdir. { kernelSpecGhcLibdir :: String -- ^ GHC libdir.
...@@ -258,7 +258,7 @@ getSandboxPackageConf = SH.shelly $ do ...@@ -258,7 +258,7 @@ getSandboxPackageConf = SH.shelly $ do
let pieces = split "/" myPath let pieces = split "/" myPath
sandboxDir = intercalate "/" $ takeWhile (/= sandboxName) pieces ++ [sandboxName] sandboxDir = intercalate "/" $ takeWhile (/= sandboxName) pieces ++ [sandboxName]
subdirs <- map fp <$> SH.ls (SH.fromText $ T.pack sandboxDir) subdirs <- map fp <$> SH.ls (SH.fromText $ T.pack sandboxDir)
let confdirs = filter (endswith ("packages.conf.d" :: String)) subdirs let confdirs = filter (isSuffixOf ("packages.conf.d" :: String)) subdirs
case confdirs of case confdirs of
[] -> return Nothing [] -> return Nothing
dir:_ -> dir:_ ->
......
module StringUtils (
strip,
lstrip,
rstrip,
replace,
split,
) where
import IHaskellPrelude
import qualified Data.Text as T
lstrip :: String -> String
lstrip = dropWhile (`elem` " \t\r\n")
rstrip :: String -> String
rstrip = reverse . lstrip . reverse
strip :: String -> String
strip = rstrip . lstrip
replace :: String -> String -> String -> String
replace needle replacement haystack =
T.unpack $ T.replace (T.pack needle) (T.pack replacement) (T.pack haystack)
split :: String -> String -> [String]
split delim = map T.unpack . T.splitOn (T.pack delim) . T.pack
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment