<commit_before>{-# LANGUAGE CPP, DoAndIfThenElse, TypeFamilies, FlexibleContexts #-}

{- |
Description:    Generates tab completion options.

This has a limited amount of context sensitivity. It distinguishes between four contexts at the moment:
- import statements (completed using modules)
- identifiers (completed using in scope values)
- extensions via :ext (completed using GHC extensions)
- qualified identifiers (completed using in-scope values)

-}
module IHaskell.Eval.Completion (complete, completionTarget, completionType, CompletionType(..)) where

import           IHaskellPrelude
import qualified Data.Text as T
import qualified Data.Text.Lazy as LT
import qualified Data.ByteString as BS
import qualified Data.ByteString.Lazy as LBS
import qualified Data.ByteString.Char8 as CBS

import           Control.Applicative ((<$>))
import           Data.ByteString.UTF8 hiding (drop, take, lines, length)
import           Data.Char
import           Data.List (nub, init, last, head, elemIndex, concatMap)
import qualified Data.List.Split as Split
import qualified Data.List.Split.Internals as Split
import           Data.Maybe (fromJust)
import           System.Environment (getEnv)

import           GHC hiding (Qualified)
#if MIN_VERSION_ghc(7,10,0)
import           GHC.PackageDb (ExposedModule(exposedName))
#endif
import           DynFlags
import           GhcMonad
import qualified GhcMonad
import           PackageConfig
import           Outputable (showPpr)
import           MonadUtils (MonadIO)


import           System.Directory
import           System.FilePath
import           Control.Exception (try)

import           System.Console.Haskeline.Completion

import           IHaskell.Types
import           IHaskell.Eval.Evaluate (Interpreter)
import           IHaskell.Eval.ParseShell (parseShell)
import           StringUtils (replace, strip, split)

data CompletionType = Empty
                    | Identifier String
                    | DynFlag String
                    | Qualified String String
                    | ModuleName String String
                    | HsFilePath String String
                    | FilePath String String
                    | KernelOption String
                    | Extension String
  deriving (Show, Eq)
#if MIN_VERSION_ghc(7,10,0)
extName (FlagSpec { flagSpecName = name }) = name
#else<commit_msg>Update src/IHaskell/Eval/Completion.hs<commit_after>{-# LANGUAGE CPP, DoAndIfThenElse, TypeFamilies, FlexibleContexts #-}

{- |
Description:    Generates tab completion options.

This has a limited amount of context sensitivity. It distinguishes between four contexts at the moment:
- import statements (completed using modules)
- identifiers (completed using in scope values)
- extensions via :ext (completed using GHC extensions)
- qualified identifiers (completed using in-scope values)

-}
module IHaskell.Eval.Completion (complete, completionTarget, completionType, CompletionType(..)) where

import           IHaskellPrelude
import qualified Data.Text as T
import qualified Data.Text.Lazy as LT
import qualified Data.ByteString as BS
import qualified Data.ByteString.Lazy as LBS
import qualified Data.ByteString.Char8 as CBS

import           Control.Applicative ((<$>))
import           Data.ByteString.UTF8 hiding (drop, take, lines, length)
import           Data.Char
import           Data.List (nub, init, last, head, elemIndex, concatMap)
import qualified Data.List.Split as Split
import qualified Data.List.Split.Internals as Split
import           Data.Maybe (fromJust)
import           System.Environment (getEnv)

import           GHC hiding (Qualified)
#if MIN_VERSION_ghc(8,2,0)
import           GHC.PackageDb
#elif MIN_VERSION_ghc(7,10,0)
import           GHC.PackageDb (ExposedModule(exposedName))
#endif
import           DynFlags
import           GhcMonad
import qualified GhcMonad
import           PackageConfig
import           Outputable (showPpr)
import           MonadUtils (MonadIO)


import           System.Directory
import           System.FilePath
import           Control.Exception (try)

import           System.Console.Haskeline.Completion

import           IHaskell.Types
import           IHaskell.Eval.Evaluate (Interpreter)
import           IHaskell.Eval.ParseShell (parseShell)
import           StringUtils (replace, strip, split)

data CompletionType = Empty
                    | Identifier String
                    | DynFlag String
                    | Qualified String String
                    | ModuleName String String
                    | HsFilePath String String
                    | FilePath String String
                    | KernelOption String
                    | Extension String
  deriving (Show, Eq)
#if MIN_VERSION_ghc(8,2,0)
exposedName = fst
#endif
#if MIN_VERSION_ghc(7,10,0)
extName (FlagSpec { flagSpecName = name }) = name
#else
{'fraction_non_alphanumeric': 0.06567840230595018, 'fraction_numerical': 0.005353098620547663, 'mean_word_length': 2.5799557848194548, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2863455', 'n_tokens_mistral': 1313, 'n_tokens_neox': 1235, 'n_words': 411}