ghcide-2.9.0.0: The core of an IDE
Safe HaskellSafe-Inferred
LanguageGHC2021

Development.IDE.GHC.Util

Description

General utility functions, mostly focused around GHC operations.

Synopsis

Documentation

modifyDynFlags :: GhcMonad m => (DynFlags -> DynFlags) -> m () Source #

Used to modify dyn flags in preference to calling setSessionDynFlags, since that function also reloads packages (which is very slow).

evalGhcEnv :: HscEnv -> Ghc b -> IO b Source #

Run a Ghc monad value using an existing HscEnv. Sets up and tears down all the required pieces, but designed to be more efficient than a standard runGhc.

GHC wrappers

printRdrName :: RdrName -> String Source #

Pretty print a RdrName wrapping operators in parens

printName :: Name -> String Source #

Pretty print a Name wrapping operators in parens

data ParseResult a :: TYPE ('SumRep '['TupleRep '[LiftedRep, LiftedRep], LiftedRep]) where #

The result of running a parser.

Bundled Patterns

pattern PFailed :: PState -> ParseResult a

The parser has consumed a (possibly empty) prefix of the input and failed.

The carried parsing state can be used to resume parsing. It is the state right before failure, including the fatal parse error. getPsMessages and getPsErrorMessages must return a non-empty bag of errors.

pattern POk :: PState -> a -> ParseResult a

The parser has consumed a (possibly empty) prefix of the input and produced a result. Use getPsMessages to check for accumulated warnings and non-fatal errors.

The carried parsing state can be used to resume parsing.

lookupPackageConfig :: Unit -> HscEnv -> Maybe UnitInfo Source #

Given a Unit try and find the associated PackageConfig in the environment.

textToStringBuffer :: Text -> StringBuffer Source #

Convert from the text package to the GHC StringBuffer. Currently implemented somewhat inefficiently (if it ever comes up in a profile).

moduleImportPath :: NormalizedFilePath -> ModuleName -> Maybe FilePath Source #

Given a module location, and its parse tree, figure out what is the include directory implied by it. For example, given the file /usr/Test/Foo/Bar.hs with the module name Foo.Bar the directory /usr/Test should be on the include path to find sibling modules.

fingerprintToBS :: Fingerprint -> ByteString Source #

Convert a Fingerprint to a ByteString by copying the byte across. Will produce an 8 byte unreadable ByteString.

General utilities

readFileUtf8 :: FilePath -> IO Text Source #

Read a UTF8 file, with lenient decoding, so it will never raise a decoding error.

hDuplicateTo' :: Handle -> Handle -> IO () Source #

A slightly modified version of hDuplicateTo from GHC. Importantly, it avoids the bug listed in https://gitlab.haskell.org/ghc/ghc/merge_requests/2318.

printOutputable :: Outputable a => a -> Text Source #

Print a GHC value in defaultUserStyle without unique symbols. It uses showSDocUnsafe with unsafeGlobalDynFlags internally.

This is the most common print utility. It will do something additionally compared to what the Outputable instance does.

  1. print with a user-friendly style: a_a4ME as a.
  2. unescape escape sequences of printable unicode characters within a pair of double quotes