1
1
mirror of https://github.com/github/semantic.git synced 2024-12-30 18:36:27 +03:00
semantic/.ghci
Patrick Thomson d56377aea9 Prevent slowdowns when pretty-printing in ghci.
Right now, when opening a shell with `script/ghci`, you can encounter
a tremendous slowdown by turning on pretty-printing (with `pretty`)
then printing any value (`[0..3]` should work).

This stems from the fact that our `.ghci` specifies the `prettyShow`
function, defined in Semantic.Util, as its `-interactive-print`
function. While this is a good choice of a pretty-printer, the fact
that it is in Util, a file which imports many modules and uses fancy
types, is not good: pretty-printing cannot begin until Util is
recompiled and linked in. This explains why benchmarking this slowdown
revealed nothing but `dlsym` calls: we thought it was due to linking
in the tree-sitter libraries, but it was actually waiting for Util to
compile and link in.

The fix is simple: define `prettyShow` in another module. This should
provide significant speedups to our developer workflow.
2018-10-04 14:38:36 -04:00

43 lines
1.4 KiB
Plaintext

-- Load the pretty-show & hscolour packages for use with :pretty.
:set -package pretty-show -package hscolour
-- See docs/💡ProTip!.md
:undef pretty
:def pretty \ _ -> return ":set -interactive-print Semantic.Util.Pretty.prettyShow"
-- See docs/💡ProTip!.md
:undef no-pretty
:def no-pretty \_ -> return ":set -interactive-print System.IO.print"
-- See docs/💡ProTip!.md
:undef r
:def r \_ -> return (unlines [":reload", ":pretty"])
-- See docs/💡ProTip!.md for documentation & examples.
:{
assignmentExample lang = case lang of
"Python" -> mk "py" "python"
"Go" -> mk "go" "go"
"Ruby" -> mk "rb" "ruby"
"JavaScript" -> mk "js" "typescript"
"TypeScript" -> mk "ts" "typescript"
"Haskell" -> mk "hs" "haskell"
"Markdown" -> mk "md" "markdown"
"JSON" -> mk "json" "json"
"Java" -> mk "java" "java"
"PHP" -> mk "php" "php"
_ -> mk "" ""
where mk fileExtension parser = putStrLn ("example: fmap (() <$) . runTask . parse " ++ parser ++ "Parser =<< Semantic.Util.blob \"example." ++ fileExtension ++ "\"") >> return ("import Parsing.Parser\nimport Semantic.Task\nimport Semantic.Util")
:}
:undef assignment
:def assignment assignmentExample
-- Enable breaking on errors for code written in the repl.
:seti -fbreak-on-error
-- Continue loading after warnings when in the repl.
:set -Wwarn
-- Use a cyan lambda as the prompt.
:set prompt "\ESC[1;36m\STXλ \ESC[m\STX"