Skip to content

Commit

Permalink
Merge branch 'thinned-api' of https://github.com/alanz/ghc-mod into n…
Browse files Browse the repository at this point in the history
…ew-cabal-helper
  • Loading branch information
lukel97 committed May 12, 2019
2 parents 1e15228 + 4347696 commit 28d9769
Show file tree
Hide file tree
Showing 49 changed files with 628 additions and 2,509 deletions.
90 changes: 3 additions & 87 deletions GhcMod.hs
Original file line number Diff line number Diff line change
@@ -1,92 +1,8 @@
-- | The ghc-mod library.

module GhcMod (
-- * Cradle
Cradle(..)
, Project(..)
, findCradle
-- * Options
, Options(..)
, LineSeparator(..)
, OutputStyle(..)
, FileMapping(..)
, defaultOptions
-- * Logging
, GmLogLevel
, increaseLogLevel
, decreaseLogLevel
, gmSetLogLevel
, gmLog
-- * Types
, ModuleString
, Expression(..)
, GhcPkgDb
, Symbol
, SymbolDb
, GhcModError(..)
-- * Monad Types
, GhcModT
, IOish
-- * Monad utilities
, runGhcModT
, withOptions
, dropSession
-- * 'GhcMod' utilities
, boot
, browse
, check
, checkSyntax
, debugInfo
, componentInfo
, expandTemplate
, info
, lint
, pkgDoc
, rootInfo
, types
, test
, splits
, sig
, refine
-- , auto
, modules
, languages
, flags
, findSymbol
, lookupSymbol
, dumpSymbol
-- * SymbolDb
, loadSymbolDb
, isOutdated
-- * Output
, gmPutStr
, gmErrStr
, gmPutStrLn
, gmErrStrLn
-- * FileMapping
, loadMappedFile
, loadMappedFileSource
, unloadMappedFile
splits'
, SplitResult(..)
) where

import GhcMod.Exe.Boot
import GhcMod.Exe.Browse
import GhcMod.Exe.CaseSplit
import GhcMod.Exe.Check
import GhcMod.Exe.Debug
import GhcMod.Exe.FillSig
import GhcMod.Exe.Find
import GhcMod.Exe.Flag
import GhcMod.Exe.Info
import GhcMod.Exe.Lang
import GhcMod.Exe.Lint
import GhcMod.Exe.Modules
import GhcMod.Exe.PkgDoc
import GhcMod.Exe.Test
import GhcMod.Cradle
import GhcMod.FileMapping
import GhcMod.Logging
import GhcMod.Monad
import GhcMod.Output
import GhcMod.Target
import GhcMod.Types
import GhcMod.Exe.CaseSplit ( splits', SplitResult(..) )
29 changes: 0 additions & 29 deletions GhcMod/Exe/Boot.hs

This file was deleted.

170 changes: 0 additions & 170 deletions GhcMod/Exe/Browse.hs

This file was deleted.

44 changes: 11 additions & 33 deletions GhcMod/Exe/CaseSplit.hs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
{-# LANGUAGE CPP #-}

module GhcMod.Exe.CaseSplit (
splits
, splits'
splits'
, SplitResult(..)
) where

Expand All @@ -20,16 +19,18 @@ import qualified TyCon as Ty
import qualified Type as Ty
import Exception

import GhcMod.Convert
import GhcMod.DynFlags
import qualified GhcMod.Gap as Gap
import GhcMod.Monad
import GhcMod.SrcUtils
import GhcMod.Doc
import GhcMod.Logging
import GhcMod.Types
import GhcMod.Convert ( whenFound', emptyResult )
import GhcMod.DynFlags ( deferErrors )
import qualified GhcMod.Gap as Gap ( getType, getSrcSpan, GhcTc )
import GhcMod.Monad ( runGmlT' )
import GhcMod.Monad.Types ( IOish, GhcModT, GmlT(..), cradle, outputOpts, GmLogLevel(..), MonadIO(..) )
import GhcMod.SrcUtils ( showName, listifySpans )
import GhcMod.Doc ( getStyle )
import GhcMod.Logging ( gmLog, text, ($$), nest, showToDoc )
import GhcMod.Types ( cradleCurrentDir )
import GhcMod.Utils (withMappedFile)
import GhcMod.FileMapping (fileModSummaryWithMapping)

import Control.DeepSeq

----------------------------------------------------------------
Expand All @@ -49,29 +50,6 @@ data SplitResult = SplitResult { sStartLine :: Int
, sEndCol :: Int
, sNewText :: T.Text }

-- | Splitting a variable in a equation.
-- Unlike splits', this performs parsing an type checking on every invocation.
-- This is meant for consumption by tools that call ghc-mod as a binary.
splits :: IOish m
=> FilePath -- ^ A target file.
-> Int -- ^ Line number.
-> Int -- ^ Column number.
-> GhcModT m String
splits file lineNo colNo =
ghandle handler $ runGmlT' [Left file] deferErrors $ do
oopts <- outputOpts
crdl <- cradle
modSum <- fileModSummaryWithMapping (cradleCurrentDir crdl </> file)
p <- G.parseModule modSum
tcm <- G.typecheckModule p
whenFound' oopts (performSplit file tcm lineNo colNo) $
\(SplitResult sLine sCol eLine eCol newText) ->
return $!! ((sLine, sCol, eLine, eCol), T.unpack newText)
where
handler (SomeException ex) = do
gmLog GmException "splits" $
text "" $$ nest 4 (showToDoc ex)
emptyResult =<< outputOpts

-- | Split an identifier in a function definition.
-- Meant for library-usage.
Expand Down
Loading

0 comments on commit 28d9769

Please sign in to comment.