mirror of
https://github.com/CrystalSplitter/ghcitui.git
synced 2024-09-11 10:55:29 +03:00
Match on functions that have apostraphes
Apostraphes are of course valid haskell characters in function names. The current ParseContext did not understand this. Fixes #38 hopefully
This commit is contained in:
parent
a0c44d2f0f
commit
676396079a
@ -150,8 +150,10 @@ test-suite spec
|
||||
main-is: Spec.hs
|
||||
type: exitcode-stdio-1.0
|
||||
build-depends: base >= 4.16 && < 5
|
||||
, text
|
||||
, ghcitui
|
||||
, hspec ^>= 2.11.5
|
||||
other-modules: LocSpec
|
||||
, ParseContextSpec
|
||||
, UtilSpec
|
||||
default-language: Haskell2010
|
||||
|
@ -41,9 +41,9 @@ data ParseContextOut = ParseContextOut
|
||||
, filepath :: !FilePath
|
||||
, pcSourceRange :: !Loc.SourceRange
|
||||
}
|
||||
deriving (Show)
|
||||
deriving (Eq, Show)
|
||||
|
||||
data ParseContextReturn = PCError ParseError | PCNoContext | PCContext ParseContextOut
|
||||
data ParseContextReturn = PCError ParseError | PCNoContext | PCContext ParseContextOut deriving (Eq, Show)
|
||||
|
||||
-- | Parse the output from ":show context" for the interpreter state.
|
||||
parseContext :: T.Text -> ParseContextReturn
|
||||
@ -58,7 +58,7 @@ parseContext contextText =
|
||||
let contextTextLines = T.lines contextText
|
||||
in if all (`elem` ["", "()"]) contextTextLines
|
||||
then PCNoContext
|
||||
else PCError (ParseError [i| parsing context: #{e}|])
|
||||
else PCError (ParseError [i|parsing context: #{e}|])
|
||||
|
||||
parseFile :: T.Text -> Either ParseError FilePath
|
||||
parseFile s
|
||||
@ -128,15 +128,15 @@ eInfoLine :: T.Text -> Either ParseError (T.Text, T.Text)
|
||||
eInfoLine "" = Left $ ParseError "Could not find info line in empty string"
|
||||
eInfoLine contextText =
|
||||
note
|
||||
(ParseError $ "Could not match info line: '" <> showT splits <> "'")
|
||||
stopLine
|
||||
(ParseError [i|Could not match info line: '#{showT splits}'|])
|
||||
mStopLine
|
||||
where
|
||||
splits = splitBy ghcidPrompt contextText
|
||||
stopLineMR = foldr (\n acc -> acc <|> stopReg n) Nothing splits
|
||||
stopLine = (\mr -> (mrSubs mr ! 1, mrSubs mr ! 2)) <$> stopLineMR
|
||||
mStopLine = (\mr -> (mrSubs mr ! 1, mrSubs mr ! 2)) <$> mStopLineMatchRes
|
||||
mStopLineMatchRes = foldr (\n acc -> acc <|> stopReg n) Nothing splits
|
||||
-- Match on the "Stopped in ..." line.
|
||||
stopReg :: T.Text -> Maybe (MatchResult T.Text)
|
||||
stopReg s = s =~~ ("^[ \t]*Stopped in ([[:alnum:]_.()]+),(.*)" :: T.Text)
|
||||
stopReg s = s =~~ ("^[ \t]*Stopped in ([[:alnum:]_.()]+'*),(.*)" :: T.Text)
|
||||
|
||||
parseBreakResponse :: T.Text -> Either T.Text [Loc.ModuleLoc]
|
||||
parseBreakResponse t
|
||||
|
32
test/ParseContextSpec.hs
Normal file
32
test/ParseContextSpec.hs
Normal file
@ -0,0 +1,32 @@
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
|
||||
module ParseContextSpec where
|
||||
|
||||
import Data.Text as T
|
||||
import Test.Hspec
|
||||
|
||||
import qualified Ghcitui.Ghcid.ParseContext as PC
|
||||
import qualified Ghcitui.Loc as Loc
|
||||
|
||||
spec :: Spec
|
||||
spec = do
|
||||
describe "parseContext" $ do
|
||||
it "can parse the Ormolu function parseModule' (with an apostraphe)" $ do
|
||||
let apostrapheFixture =
|
||||
T.unlines
|
||||
[ "()"
|
||||
, "[src/Ormolu.hs:(257,51)-(261,35)] #~GHCID-START~#()"
|
||||
, "[src/Ormolu.hs:(257,51)-(261,35)] #~GHCID-START~#--> invoke"
|
||||
, " Stopped in Ormolu.parseModule', src/Ormolu.hs:(257,51)-(261,35)"
|
||||
]
|
||||
let expectedLoc =
|
||||
Loc.SourceRange
|
||||
{ Loc.startLine = Just 257
|
||||
, Loc.startCol = Just 51
|
||||
, Loc.endLine = Just 261
|
||||
, Loc.endCol = Just 35
|
||||
}
|
||||
let expected =
|
||||
PC.PCContext
|
||||
(PC.ParseContextOut "Ormolu.parseModule'" "src/Ormolu.hs" expectedLoc)
|
||||
PC.parseContext apostrapheFixture `shouldBe` expected
|
@ -3,9 +3,11 @@ module Main where
|
||||
import Test.Hspec
|
||||
|
||||
import qualified LocSpec
|
||||
import qualified ParseContextSpec
|
||||
import qualified UtilSpec
|
||||
|
||||
main :: IO ()
|
||||
main = hspec $ do
|
||||
LocSpec.spec
|
||||
UtilSpec.spec
|
||||
ParseContextSpec.spec
|
||||
|
Loading…
Reference in New Issue
Block a user