-
-
Notifications
You must be signed in to change notification settings - Fork 367
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
73 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
plugins/hls-refactor-plugin/src/Development/IDE/Plugin/CodeAction/Util.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
module Development.IDE.Plugin.CodeAction.Util where | ||
|
||
#if MIN_VERSION_ghc(9,2,0) | ||
import GHC.Utils.Outputable | ||
#else | ||
import Development.IDE.GHC.Compat.Util | ||
import Development.IDE.GHC.Compat | ||
#endif | ||
import Data.Data (Data) | ||
import qualified Data.Unique as U | ||
import Debug.Trace | ||
import Development.IDE.GHC.Compat.ExactPrint as GHC | ||
import GHC.Stack | ||
import System.Environment.Blank (getEnvDefault) | ||
import System.IO.Unsafe | ||
import Text.Printf | ||
import Development.IDE.GHC.Dump (showAstDataHtml) | ||
import Data.Time.Clock.POSIX (POSIXTime, getCurrentTime, | ||
utcTimeToPOSIXSeconds) | ||
-------------------------------------------------------------------------------- | ||
-- Tracing exactprint terms | ||
|
||
-- Should in `Development.IDE.GHC.Orphans`, | ||
-- leave it here to prevent cyclic module dependency | ||
|
||
#if !MIN_VERSION_ghc(8,10,0) | ||
instance Outputable SDoc where | ||
ppr = id | ||
#endif | ||
|
||
{-# NOINLINE timestamp #-} | ||
timestamp :: POSIXTime | ||
timestamp = utcTimeToPOSIXSeconds $ unsafePerformIO getCurrentTime | ||
|
||
debugAST :: Bool | ||
debugAST = unsafePerformIO (getEnvDefault "GHCIDE_DEBUG_AST" "0") == "1" | ||
|
||
-- | Prints an 'Outputable' value to stderr and to an HTML file for further inspection | ||
traceAst :: (Data a, ExactPrint a, Outputable a, HasCallStack) => String -> a -> a | ||
traceAst lbl x | ||
| debugAST = trace doTrace x | ||
| otherwise = x | ||
where | ||
#if MIN_VERSION_ghc(9,2,0) | ||
renderDump = renderWithContext defaultSDocContext{sdocStyle = defaultDumpStyle, sdocPprDebug = True} | ||
#else | ||
renderDump = showSDocUnsafe . ppr | ||
#endif | ||
htmlDump = showAstDataHtml x | ||
doTrace = unsafePerformIO $ do | ||
u <- U.newUnique | ||
let htmlDumpFileName = printf "/tmp/hls/%s-%s-%d.html" (show timestamp) lbl (U.hashUnique u) | ||
writeFile htmlDumpFileName $ renderDump htmlDump | ||
return $ unlines | ||
[prettyCallStack callStack ++ ":" | ||
#if MIN_VERSION_ghc(9,2,0) | ||
, exactPrint x | ||
#endif | ||
, "file://" ++ htmlDumpFileName] | ||
|