Skip to content

Commit 7ad882a

Browse files
committed
Move traceAst
1 parent 20dcf6c commit 7ad882a

File tree

5 files changed

+13
-41
lines changed

5 files changed

+13
-41
lines changed

ghcide/ghcide.cabal

-1
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,6 @@ library
172172
Development.IDE.GHC.Compat.Util
173173
Development.IDE.Core.Compile
174174
Development.IDE.GHC.CoreFile
175-
Development.IDE.GHC.Dump
176175
Development.IDE.GHC.Error
177176
Development.IDE.GHC.Orphans
178177
Development.IDE.GHC.Util

ghcide/src/Development/IDE/GHC/Dump.hs

+7-8
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
module Development.IDE.GHC.Dump(showAstDataHtml) where
33
import Data.Data hiding (Fixity)
44
import Development.IDE.GHC.Compat hiding (NameAnn)
5+
import Development.IDE.GHC.ExactPrint hiding (NameAnn)
56
#if MIN_VERSION_ghc(8,10,1)
67
import GHC.Hs.Dump
78
#else
@@ -21,18 +22,18 @@ import GhcPlugins
2122
import Prelude hiding ((<>))
2223

2324
-- | Show a GHC syntax tree in HTML.
25+
#if MIN_VERSION_ghc(9,2,1)
26+
showAstDataHtml :: (Data a, ExactPrint a, Outputable a) => a -> SDoc
27+
#else
2428
showAstDataHtml :: (Data a, Outputable a) => a -> SDoc
29+
#endif
2530
showAstDataHtml a0 = html $
2631
header $$
2732
body (tag' [("id",text (show @String "myUL"))] "ul" $ vcat
2833
[
29-
-- #if MIN_VERSION_ghc(9,2,1)
30-
31-
-- #else
3234
#if MIN_VERSION_ghc(9,2,1)
33-
-- li (pre $ text (exactPrint a0)),
34-
-- li (showAstDataHtml' a0),
35-
-- li (nested "Raw" $ pre $ showAstData NoBlankSrcSpan NoBlankEpAnnotations a0)
35+
li (pre $ text (exactPrint a0)),
36+
li (showAstDataHtml' a0),
3637
li (nested "Raw" $ pre $ showAstData NoBlankSrcSpan NoBlankEpAnnotations a0)
3738
#else
3839
li (nested "Raw" $ pre $ showAstData NoBlankSrcSpan a0)
@@ -56,7 +57,6 @@ showAstDataHtml a0 = html $
5657
header = tag "head" $ tag "style" $ text css
5758
html = tag "html"
5859
pre = tag "pre"
59-
{-
6060
#if MIN_VERSION_ghc(9,2,1)
6161
showAstDataHtml' :: Data a => a -> SDoc
6262
showAstDataHtml' =
@@ -282,7 +282,6 @@ showAstDataHtml a0 = html $
282282
Nothing -> text "locatedAnn:unmatched" <+> tag
283283
<+> (text (showConstr (toConstr ss)))
284284
#endif
285-
-}
286285

287286

288287
normalize_newlines :: String -> String

ghcide/src/Development/IDE/GHC/Util.hs

-32
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ module Development.IDE.GHC.Util(
2626
setHieDir,
2727
dontWriteHieFiles,
2828
disableWarningsAsErrors,
29-
traceAst,
3029
printOutputable
3130
) where
3231

@@ -70,7 +69,6 @@ import Debug.Trace
7069
import Development.IDE.GHC.Compat as GHC
7170
import qualified Development.IDE.GHC.Compat.Parser as Compat
7271
import qualified Development.IDE.GHC.Compat.Units as Compat
73-
import Development.IDE.GHC.Dump (showAstDataHtml)
7472
import Development.IDE.Types.Location
7573
import Foreign.ForeignPtr
7674
import Foreign.Ptr
@@ -281,36 +279,6 @@ ioe_dupHandlesNotCompatible h =
281279
--------------------------------------------------------------------------------
282280
-- Tracing exactprint terms
283281

284-
{-# NOINLINE timestamp #-}
285-
timestamp :: POSIXTime
286-
timestamp = utcTimeToPOSIXSeconds $ unsafePerformIO getCurrentTime
287-
288-
debugAST :: Bool
289-
debugAST = unsafePerformIO (getEnvDefault "GHCIDE_DEBUG_AST" "0") == "1"
290-
291-
-- | Prints an 'Outputable' value to stderr and to an HTML file for further inspection
292-
traceAst :: (Data a, Outputable a, HasCallStack) => String -> a -> a
293-
traceAst lbl x
294-
| debugAST = trace doTrace x
295-
| otherwise = x
296-
where
297-
#if MIN_VERSION_ghc(9,2,0)
298-
renderDump = renderWithContext defaultSDocContext{sdocStyle = defaultDumpStyle, sdocPprDebug = True}
299-
#else
300-
renderDump = showSDocUnsafe . ppr
301-
#endif
302-
htmlDump = showAstDataHtml x
303-
doTrace = unsafePerformIO $ do
304-
u <- U.newUnique
305-
let htmlDumpFileName = printf "/tmp/hls/%s-%s-%d.html" (show timestamp) lbl (U.hashUnique u)
306-
writeFile htmlDumpFileName $ renderDump htmlDump
307-
return $ unlines
308-
[prettyCallStack callStack ++ ":"
309-
-- #if MIN_VERSION_ghc(9,2,0)
310-
-- , exactPrint x
311-
-- #endif
312-
, "file://" ++ htmlDumpFileName]
313-
314282
-- Should in `Development.IDE.GHC.Orphans`,
315283
-- leave it here to prevent cyclic module dependency
316284
#if !MIN_VERSION_ghc(8,10,0)

plugins/hls-refactor-plugin/hls-refactor-plugin.cabal

+4
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ library
2121
exposed-modules: Development.IDE.GHC.ExactPrint
2222
Development.IDE.GHC.Compat.ExactPrint
2323
Development.IDE.Plugin.CodeAction
24+
Development.IDE.Plugin.CodeAction.Util
25+
Development.IDE.GHC.Dump
2426
other-modules: Development.IDE.Plugin.CodeAction.Args
2527
Development.IDE.Plugin.CodeAction.ExactPrint
2628
Development.IDE.Plugin.CodeAction.PositionIndexed
@@ -53,6 +55,7 @@ library
5355
, aeson
5456
, base >=4.12 && <5
5557
, ghc
58+
, bytestring
5659
, ghc-boot
5760
, regex-tdfa
5861
, text-rope
@@ -73,6 +76,7 @@ library
7376
, mtl
7477
, lens
7578
, data-default
79+
, time
7680
ghc-options: -Wall -Wno-name-shadowing
7781
default-language: Haskell2010
7882

plugins/hls-refactor-plugin/src/Development/IDE/Plugin/CodeAction/ExactPrint.hs

+2
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ import GHC.Stack (HasCallStack)
3434
import Language.Haskell.GHC.ExactPrint
3535
import Language.LSP.Types
3636

37+
import Development.IDE.Plugin.CodeAction.Util
38+
3739
-- GHC version specific imports. For any supported GHC version, make sure there is no warning in imports.
3840
#if MIN_VERSION_ghc(9,2,0)
3941
import Control.Lens (_head, _last, over)

0 commit comments

Comments
 (0)