Skip to content

Doctest comment parsing using module annotations in Eval Plugin #1232

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 60 commits into from
Jan 31, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
322e26d
WIP: Comment parsing using module annotations
konn Jan 19, 2021
0e3cbe3
Merge branch 'master' into eval-comments-from-parsed-module
konn Jan 20, 2021
e2f4b9d
Line Comment parsers (wip)
konn Jan 20, 2021
b9bbb80
Merge branch 'master' into eval-comments-from-parsed-module
konn Jan 21, 2021
d32a571
Merge branch 'master' into eval-comments-from-parsed-module
konn Jan 21, 2021
155ec6d
Line comment implemented (block comment not implemented)
konn Jan 21, 2021
032bc60
Completely switches to Megaparsec
konn Jan 21, 2021
abc3796
T27 must be fixed
konn Jan 21, 2021
d6b0ad9
We can always assume that comment starts with "--" with no space prep…
konn Jan 22, 2021
f035f37
must be horizontal space, not ANY whitespace
konn Jan 22, 2021
3f25b17
Block parser (WIP)
konn Jan 22, 2021
1c0ca62
We don't need whole range; position suffices
konn Jan 22, 2021
fce4e84
Brutal parsing for block haddock comments
konn Jan 22, 2021
2e64bbe
Brutal line parsing
konn Jan 22, 2021
53476b0
unset Opt_Haddock
konn Jan 22, 2021
261e8a6
Wrong debug messages
konn Jan 22, 2021
d4c1800
Redundant debug output
konn Jan 22, 2021
8ef1d64
Merge branch 'master' into eval-comments-from-parsed-module
konn Jan 24, 2021
abede6b
Hacks for indentation levels and LHS
konn Jan 24, 2021
c9e5636
Updates block comment logic in Literate Haskell
konn Jan 24, 2021
f698add
Updates doctests
konn Jan 24, 2021
d514570
Allows doctest without newline at the end
konn Jan 24, 2021
f7bdb54
Precise handling of line ending
konn Jan 24, 2021
c7b1e64
Merge branch 'master' into eval-comments-from-parsed-module
konn Jan 24, 2021
044fec5
Corrects last-line block eval handling
konn Jan 24, 2021
6525bbc
Makes normal line parsing LHS sensitive
konn Jan 24, 2021
f0bbd70
Removes outdated note on block comments in a single line
konn Jan 24, 2021
b167c3d
Wait a moment before executing each code lenses
konn Jan 24, 2021
5811ac5
Merge branch 'master' into eval-comments-from-parsed-module
konn Jan 24, 2021
6e3c81b
Merge branch 'master' into eval-comments-from-parsed-module
konn Jan 25, 2021
dc30f8f
Sorting tests in order
konn Jan 25, 2021
1d2a1ad
Sorts lenses in order
konn Jan 25, 2021
4fcea60
Reverted to use executCmd
konn Jan 25, 2021
64bc51c
Changes sorting logic
konn Jan 25, 2021
3adb01f
Fixes test case: trailing space
konn Jan 25, 2021
4d33ce2
Dummy commit to re-invoke CI
konn Jan 25, 2021
c63b370
expect fail CPP Eval on Windows
konn Jan 25, 2021
83cb1ef
Corrects typo
konn Jan 25, 2021
606aee0
Merge branch 'master' into eval-comments-from-parsed-module
konn Jan 25, 2021
97c5619
Merge branch 'master' into eval-comments-from-parsed-module
konn Jan 26, 2021
5f4a5a6
Test for #1258
konn Jan 26, 2021
547ff27
Corrects test header
konn Jan 26, 2021
7e1648c
Ad-hoc treatment for ending brace in nested comment block
konn Jan 27, 2021
1decd41
`goldenTest` function from Eval plugin doesn't support multiple tests…
konn Jan 28, 2021
28c97cf
Merge branch 'master' into eval-comments-from-parsed-module
konn Jan 28, 2021
255d6fb
Dummy commit to rerun CI
konn Jan 28, 2021
a2f7115
Merge branch 'eval-comments-from-parsed-module' of github.com:konn/ha…
konn Jan 28, 2021
fcc679e
Merge branch 'master' into eval-comments-from-parsed-module
Ailrun Jan 28, 2021
9985e86
Merge branch 'master' into eval-comments-from-parsed-module
konn Jan 29, 2021
a3b1739
Merge branch 'master' into eval-comments-from-parsed-module
Ailrun Jan 29, 2021
6fdf06c
Merge branch 'master' into eval-comments-from-parsed-module
konn Jan 30, 2021
375aa04
Merge branch 'master' into eval-comments-from-parsed-module
konn Jan 30, 2021
d9114de
Merge branch 'master' into eval-comments-from-parsed-module
konn Jan 30, 2021
557fdd6
Stop using CPP and use `knownBrokenForGhcVersions` and `knownBrokenOn…
konn Jan 30, 2021
72257be
Merge branch 'eval-comments-from-parsed-module' of github.com:konn/ha…
konn Jan 30, 2021
a07b145
Merge branch 'master' into eval-comments-from-parsed-module
konn Jan 31, 2021
5b90f43
Nested `expectedFailure` didn't work as expected
konn Jan 31, 2021
66cdc32
Abolishes `Parser` type synonym
konn Jan 31, 2021
90c86ce
Removes unneccesary comment evals
konn Jan 31, 2021
0e689e3
Skip failed curentRange resolution
konn Jan 31, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion ghcide/src/Development/IDE/Core/Rules.hs
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,9 @@ withOptHaddock = withOption Opt_Haddock
withOption :: GeneralFlag -> ModSummary -> ModSummary
withOption opt ms = ms{ms_hspp_opts= gopt_set (ms_hspp_opts ms) opt}

withoutOption :: GeneralFlag -> ModSummary -> ModSummary
withoutOption opt ms = ms{ms_hspp_opts= gopt_unset (ms_hspp_opts ms) opt}

-- | Given some normal parse errors (first) and some from Haddock (second), merge them.
-- Ignore Haddock errors that are in both. Demote Haddock-only errors to warnings.
mergeParseErrorsHaddock :: [FileDiagnostic] -> [FileDiagnostic] -> [FileDiagnostic]
Expand All @@ -360,7 +363,7 @@ getParsedModuleWithCommentsRule = defineEarlyCutoff $ \GetParsedModuleWithCommen
sess <- use_ GhcSession file
opt <- getIdeOptions

let ms' = withOption Opt_KeepRawTokenStream ms
let ms' = withoutOption Opt_Haddock $ withOption Opt_KeepRawTokenStream ms

liftIO $ getParsedModuleDefinition (hscEnv sess) opt file ms'

Expand Down
1 change: 1 addition & 0 deletions ghcide/src/Development/IDE/GHC/Orphans.hs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import qualified StringBuffer as SB
import Data.Text (Text)
import Data.String (IsString(fromString))
import Retrie.ExactPrint (Annotated)
import Data.List (foldl')


-- Orphan instances for types from the GHC API.
Expand Down
8 changes: 5 additions & 3 deletions plugins/hls-eval-plugin/hls-eval-plugin.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ library
Ide.Plugin.Eval.CodeLens
Ide.Plugin.Eval.GHC
Ide.Plugin.Eval.Parse.Option
Ide.Plugin.Eval.Parse.Parser
Ide.Plugin.Eval.Parse.Section
Ide.Plugin.Eval.Parse.Token
Ide.Plugin.Eval.Parse.Comments
Ide.Plugin.Eval.Types
Ide.Plugin.Eval.Util

Expand All @@ -44,6 +42,7 @@ library
, deepseq
, Diff
, directory
, dlist
, extra
, filepath
, ghc
Expand All @@ -54,6 +53,8 @@ library
, haskell-lsp
, haskell-lsp-types
, hls-plugin-api
, lens
, megaparsec >= 0.9
, parser-combinators
, pretty-simple
, QuickCheck
Expand All @@ -63,6 +64,7 @@ library
, text
, time
, transformers
, mtl
, unordered-containers

ghc-options: -Wall -Wno-name-shadowing
Expand Down
27 changes: 14 additions & 13 deletions plugins/hls-eval-plugin/src/Ide/Plugin/Eval/Code.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,21 @@ import GhcMonad (Ghc, GhcMonad, liftIO)
import Ide.Plugin.Eval.Types (
Language (Plain),
Loc,
Located (Located),
Section (sectionLanguage),
Test (Example, Property, testOutput),
Test (..),
Txt,
locate,
locate0,
locate0, Located(..)
)
import InteractiveEval (runDecls)
import Unsafe.Coerce (unsafeCoerce)
import Control.Lens ((^.))
import Language.Haskell.LSP.Types.Lens (start, line)

-- | Return the ranges of the expression and result parts of the given test
testRanges :: Loc Test -> (Range, Range)
testRanges (Located line tst) =
let startLine = line
testRanges :: Test -> (Range, Range)
testRanges tst =
let startLine = testRange tst ^. start.line
(exprLines, resultLines) = testLenghts tst
resLine = startLine + exprLines
in ( Range
Expand All @@ -44,7 +45,7 @@ testRanges (Located line tst) =
-}

-- |The document range where the result of the test is defined
resultRange :: Loc Test -> Range
resultRange :: Test -> Range
resultRange = snd . testRanges

-- TODO: handle BLANKLINE
Expand All @@ -66,18 +67,18 @@ testCheck (section, test) out
| otherwise = showDiffs $ getDiff (map T.pack $ testOutput test) out

testLenghts :: Test -> (Int, Int)
testLenghts (Example e r) = (NE.length e, length r)
testLenghts (Property _ r) = (1, length r)
testLenghts (Example e r _) = (NE.length e, length r)
testLenghts (Property _ r _) = (1, length r)

-- |A one-line Haskell statement
type Statement = Loc String

asStatements :: Loc Test -> [Statement]
asStatements lt = locate (asStmts <$> lt)
asStatements :: Test -> [Statement]
asStatements lt = locate $ Located (testRange lt ^. start.line) (asStmts lt)

asStmts :: Test -> [Txt]
asStmts (Example e _) = NE.toList e
asStmts (Property t _) =
asStmts (Example e _ _) = NE.toList e
asStmts (Property t _ _) =
["prop11 = " ++ t, "(propEvaluation prop11 :: IO String)"]

-- |Evaluate an expression (either a pure expression or an IO a)
Expand Down
Loading