Copyright | (c) JP Moresmau 2011 |
---|---|
License | BSD3 |
Maintainer | jpmoresmau@gmail.com |
Stability | beta |
Portability | portable |
Safe Haskell | None |
Language | Haskell98 |
Load relevant module in the GHC AST and get GHC messages and thing at point info. Also use the GHC lexer for syntax highlighting.
- type GHCApplyFunction a = FilePath -> TypecheckedModule -> Ghc a
- getAST :: FilePath -> FilePath -> String -> [String] -> IO (OpResult (Maybe TypecheckedSource))
- withAST :: (TypecheckedModule -> Ghc a) -> FilePath -> FilePath -> String -> [String] -> IO (Maybe a)
- withJSONAST :: (Value -> IO a) -> FilePath -> FilePath -> String -> [String] -> IO (Maybe a)
- withASTNotes :: GHCApplyFunction a -> (FilePath -> FilePath) -> FilePath -> LoadContents -> [String] -> IO (OpResult [a])
- initGHC :: Ghc a -> [String] -> IO a
- ghcWithASTNotes :: GHCApplyFunction a -> (FilePath -> FilePath) -> FilePath -> LoadContents -> Bool -> Ghc (OpResult [a])
- isWarnIsError :: DynFlags -> Bool
- ghcMessagesToNotes :: DynFlags -> FilePath -> Messages -> [BWNote]
- getGhcNamesInScope :: FilePath -> FilePath -> String -> [String] -> IO [String]
- getGhcNameDefsInScope :: FilePath -> FilePath -> String -> [String] -> IO (OpResult (Maybe [NameDef]))
- getGhcNameDefsInScopeLongRunning :: FilePath -> FilePath -> String -> [String] -> IO ()
- getEvalResults :: forall m. GhcMonad m => String -> m [EvalResult]
- name2nd :: GhcMonad m => DynFlags -> Name -> m NameDef
- getThingAtPointJSON :: Int -> Int -> FilePath -> FilePath -> String -> [String] -> IO (Maybe ThingAtPoint)
- getLocalsJSON :: Int -> Int -> Int -> Int -> FilePath -> FilePath -> String -> [String] -> IO [ThingAtPoint]
- eval :: String -> FilePath -> FilePath -> String -> [String] -> IO [EvalResult]
- ghcSpanToLocation :: SrcSpan -> InFileSpan
- ghcSpanToBWLocation :: FilePath -> SrcSpan -> BWLocation
- ghcColToScionCol :: Int -> Int
- scionColToGhcCol :: Int -> Int
- ghctokensArbitrary :: FilePath -> String -> [String] -> IO (Either BWNote [Located Token])
- ghctokensArbitrary' :: FilePath -> String -> Ghc (Either BWNote [Located Token])
- lexTokenStreamH :: StringBuffer -> RealSrcLoc -> DynFlags -> ParseResult [Located Token]
- lexLoc :: RealSrcLoc
- lexerFlags :: [ExtensionFlag]
- ofInterest :: Located Token -> Bool
- tokenToType :: Located Token -> TokenDef
- tokenTypesArbitrary :: FilePath -> String -> Bool -> [String] -> IO (Either BWNote [TokenDef])
- tokenTypesArbitrary' :: FilePath -> String -> Bool -> Ghc (Either BWNote [TokenDef])
- occurrences :: FilePath -> String -> Text -> Bool -> [String] -> IO (Either BWNote [TokenDef])
- occurrences' :: FilePath -> String -> Text -> Bool -> Ghc (Either BWNote [TokenDef])
- generateTokens :: FilePath -> String -> Bool -> [String] -> ([Located Token] -> [TokenDef]) -> ([TokenDef] -> a) -> IO (Either BWNote a)
- generateTokens' :: FilePath -> String -> Bool -> ([Located Token] -> [TokenDef]) -> ([TokenDef] -> a) -> Ghc (Either BWNote a)
- preprocessSource :: String -> Bool -> ([TokenDef], String)
- data PPBehavior
- ghcErrMsgToNote :: DynFlags -> FilePath -> ErrMsg -> BWNote
- ghcWarnMsgToNote :: DynFlags -> FilePath -> WarnMsg -> BWNote
- ghcMsgToNote :: DynFlags -> BWNoteStatus -> FilePath -> ErrMsg -> BWNote
- removeStatus :: BWNoteStatus -> String -> String
- mkUnqualTokenValue :: FastString -> Text
- mkQualifiedTokenValue :: FastString -> FastString -> Text
- mkTokenName :: Token -> Text
- tokenType :: Token -> Text
- dotFS :: FastString
- tokenValue :: Bool -> Token -> Text
- start :: SrcSpan -> (Int, Int)
- end :: SrcSpan -> (Int, Int)
- type AliasMap = Map ModuleName [ModuleName]
- ghcImportToUsage :: Text -> LImportDecl Name -> ([Usage], AliasMap) -> Ghc ([Usage], AliasMap)
- ghcLIEToUsage :: DynFlags -> Maybe Text -> Text -> Text -> LIE Name -> [Usage]
- ghcExportToUsage :: DynFlags -> Text -> Text -> AliasMap -> LIE Name -> Ghc [Usage]
- ghcNameToUsage :: DynFlags -> Maybe Text -> Text -> Text -> Name -> SrcSpan -> Bool -> Usage
- type ImportMap = Map Text (LImportDecl Name, [Text])
- ghcImportMap :: LImportDecl Name -> Ghc ImportMap
- type TypeMap = Map Text (Map Text (Set Text))
- type FinalImportValue = (LImportDecl Name, Map Text (Set Text))
- type FinalImportMap = Map Text FinalImportValue
- ghcCleanImports :: FilePath -> FilePath -> String -> [String] -> Bool -> IO (OpResult [ImportClean])
Documentation
type GHCApplyFunction a = FilePath -> TypecheckedModule -> Ghc a Source
a function taking the file name and typechecked module as parameters
:: FilePath | the source file |
-> FilePath | the base directory |
-> String | the module name |
-> [String] | the GHC options |
-> IO (OpResult (Maybe TypecheckedSource)) |
get the GHC typechecked AST
:: (TypecheckedModule -> Ghc a) | the action |
-> FilePath | the source file |
-> FilePath | the base directory |
-> String | the module name |
-> [String] | the GHC options |
-> IO (Maybe a) |
perform an action on the GHC Typechecked module
:: (Value -> IO a) | the action |
-> FilePath | the source file |
-> FilePath | the base directory |
-> String | the module name |
-> [String] | the GHC options |
-> IO (Maybe a) |
perform an action on the GHC JSON AST
:: GHCApplyFunction a | the final action to perform on the result |
-> (FilePath -> FilePath) | transform given file path to find bwinfo path |
-> FilePath | the base directory |
-> LoadContents | what to load |
-> [String] | the GHC options |
-> IO (OpResult [a]) |
the main method loading the source contents into GHC
:: GHCApplyFunction a | the final action to perform on the result |
-> (FilePath -> FilePath) | transform given file path to find bwinfo path |
-> FilePath | the base directory |
-> LoadContents | what to load |
-> Bool | add the target? |
-> Ghc (OpResult [a]) |
run a GHC action and get results with notes
isWarnIsError :: DynFlags -> Bool Source
do we have -Werror
Convert Messages
to '[BWNote]'.
This will mix warnings and errors, but you can split them back up
by filtering the '[BWNote]' based on the bw_status
.
:: FilePath | source path |
-> FilePath | base directory |
-> String | module name |
-> [String] | build options |
-> IO [String] |
get all names in scope
:: FilePath | source path |
-> FilePath | base directory |
-> String | module name |
-> [String] | build options |
-> IO (OpResult (Maybe [NameDef])) |
get all names in scope, packaged in NameDefs
getGhcNameDefsInScopeLongRunning Source
get all names in scope, packaged in NameDefs, and keep running a loop listening to commands
getEvalResults :: forall m. GhcMonad m => String -> m [EvalResult] Source
evaluate expression in the GHC monad
:: Int | line |
-> Int | column -> Bool ^ do we want the result qualified by the module -> Bool ^ do we want the full type or just the haddock type |
-> FilePath | source file path |
-> FilePath | base directory |
-> String | module name |
-> [String] | build flags |
-> IO (Maybe ThingAtPoint) |
get the "thing" at a particular point (line/column) in the source this is using the saved JSON info if available
:: Int | start line |
-> Int | start column |
-> Int | end line |
-> Int | end column |
-> FilePath | source file path |
-> FilePath | base directory |
-> String | module name |
-> [String] | build flags |
-> IO [ThingAtPoint] |
get the "thing" at a particular point (line/column) in the source this is using the saved JSON info if available
:: String | the expression |
-> FilePath | source file path |
-> FilePath | base directory |
-> String | module name |
-> [String] | build flags |
-> IO [EvalResult] |
evaluate an expression
ghcSpanToLocation :: SrcSpan -> InFileSpan Source
convert a GHC SrcSpan to a Span, ignoring the actual file info
:: FilePath | Base directory |
-> SrcSpan | |
-> BWLocation |
convert a GHC SrcSpan to a BWLocation
ghcColToScionCol :: Int -> Int Source
convert a column info from GHC to our system (1 based)
scionColToGhcCol :: Int -> Int Source
convert a column info from our system (1 based) to GHC
:: FilePath | The file path to the document |
-> String | The document's contents |
-> [String] | The options |
-> IO (Either BWNote [Located Token]) |
Get a stream of tokens generated by the GHC lexer from the current document
:: FilePath | The file path to the document |
-> String | The document's contents |
-> Ghc (Either BWNote [Located Token]) |
Get a stream of tokens generated by the GHC lexer from the current document
lexTokenStreamH :: StringBuffer -> RealSrcLoc -> DynFlags -> ParseResult [Located Token] Source
like lexTokenStream, but keep Haddock flag
get lexer initial location
lexerFlags :: [ExtensionFlag] Source
get lexer flags
ofInterest :: Located Token -> Bool Source
Filter tokens whose span appears legitimate (start line is less than end line, start column is less than end column.)
tokenToType :: Located Token -> TokenDef Source
Convert a GHC token to an interactive token (abbreviated token type)
tokenTypesArbitrary :: FilePath -> String -> Bool -> [String] -> IO (Either BWNote [TokenDef]) Source
Generate the interactive token list used by EclipseFP for syntax highlighting, in the IO monad
tokenTypesArbitrary' :: FilePath -> String -> Bool -> Ghc (Either BWNote [TokenDef]) Source
Generate the interactive token list used by EclipseFP for syntax highlighting, when already in a GHC session
:: FilePath | Project root or base directory for absolute path conversion |
-> String | Contents to be parsed |
-> Text | Token value to find |
-> Bool | Literate source flag (True = literate, False = ordinary) |
-> [String] | Options |
-> IO (Either BWNote [TokenDef]) |
Extract occurrences based on lexing
:: FilePath | Project root or base directory for absolute path conversion |
-> String | Contents to be parsed |
-> Text | Token value to find |
-> Bool | Literate source flag (True = literate, False = ordinary) |
-> Ghc (Either BWNote [TokenDef]) |
Extract occurrences based on lexing
:: FilePath | The project's root directory |
-> String | The current document contents, to be parsed |
-> Bool | Literate Haskell flag |
-> [String] | The options |
-> ([Located Token] -> [TokenDef]) | Transform function from GHC tokens to TokenDefs |
-> ([TokenDef] -> a) | The TokenDef filter function |
-> IO (Either BWNote a) |
Parse the current document, generating a TokenDef list, filtered by a function
:: FilePath | The project's root directory |
-> String | The current document contents, to be parsed |
-> Bool | Literate Haskell flag |
-> ([Located Token] -> [TokenDef]) | Transform function from GHC tokens to TokenDefs |
-> ([TokenDef] -> a) | The TokenDef filter function |
-> Ghc (Either BWNote a) |
Parse the current document, generating a TokenDef list, filtered by a function
:: String | the source contents |
-> Bool | is the source literate Haskell |
-> ([TokenDef], String) | the preprocessor tokens and the final valid Haskell source |
Preprocess some source, returning the literate and Haskell source as tuple.
data PPBehavior Source
preprocessor behavior data
ghcErrMsgToNote :: DynFlags -> FilePath -> ErrMsg -> BWNote Source
convert a GHC error message to our note type
ghcWarnMsgToNote :: DynFlags -> FilePath -> WarnMsg -> BWNote Source
convert a GHC warning message to our note type
ghcMsgToNote :: DynFlags -> BWNoteStatus -> FilePath -> ErrMsg -> BWNote Source
convert a GHC message to our note type Note that we do *not* include the extra info, since that information is only useful in the case where we do not show the error location directly in the source.
removeStatus :: BWNoteStatus -> String -> String Source
remove the initial status text from a message
:: FastString | the qualifier |
-> FastString | the name |
-> Text |
make qualified token: join the qualifier and the name by a dot
mkTokenName :: Token -> Text Source
make a text name from a token
a dot as a FastString
tokenValue :: Bool -> Token -> Text Source
generate a token value
type AliasMap = Map ModuleName [ModuleName] Source
map of module aliases
ghcImportToUsage :: Text -> LImportDecl Name -> ([Usage], AliasMap) -> Ghc ([Usage], AliasMap) Source
get usages from GHC imports
ghcLIEToUsage :: DynFlags -> Maybe Text -> Text -> Text -> LIE Name -> [Usage] Source
get usages from GHC IE
ghcExportToUsage :: DynFlags -> Text -> Text -> AliasMap -> LIE Name -> Ghc [Usage] Source
get usage from GHC exports
ghcNameToUsage :: DynFlags -> Maybe Text -> Text -> Text -> Name -> SrcSpan -> Bool -> Usage Source
generate a usage for a name
ghcImportMap :: LImportDecl Name -> Ghc ImportMap Source
build an import map from all imports
type FinalImportValue = (LImportDecl Name, Map Text (Set Text)) Source
mapping to import declaration to actually needed names
type FinalImportMap = Map Text FinalImportValue Source
map from original text to needed names