Skip to content

Commit 7372136

Browse files
committed
Relocated list of OccName prefixes from the Completions plugin to the CoreFile module. Updated the check for GHC-generated OccName prefixes in AtPoint to use the shared list of OccName prefixes.
1 parent 46b4068 commit 7372136

File tree

3 files changed

+49
-48
lines changed

3 files changed

+49
-48
lines changed

ghcide/src/Development/IDE/GHC/CoreFile.hs

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,16 @@ module Development.IDE.GHC.CoreFile
1010
, typecheckCoreFile
1111
, readBinCoreFile
1212
, writeBinCoreFile
13-
, getImplicitBinds) where
13+
, getImplicitBinds
14+
, occNamePrefixes) where
1415

1516
import Control.Monad
1617
import Control.Monad.IO.Class
1718
import Data.Foldable
1819
import Data.IORef
1920
import Data.List (isPrefixOf)
2021
import Data.Maybe
22+
import qualified Data.Text as T
2123
import GHC.Fingerprint
2224

2325
import Development.IDE.GHC.Compat
@@ -228,3 +230,45 @@ tc_iface_bindings (TopIfaceNonRec v e) = do
228230
tc_iface_bindings (TopIfaceRec vs) = do
229231
vs' <- traverse (\(v, e) -> (,) <$> pure v <*> tcIfaceExpr e) vs
230232
pure $ Rec vs'
233+
234+
-- | Prefixes that can occur in a GHC OccName
235+
occNamePrefixes :: [T.Text]
236+
occNamePrefixes =
237+
[
238+
-- long ones
239+
"$con2tag_"
240+
, "$tag2con_"
241+
, "$maxtag_"
242+
243+
-- four chars
244+
, "$sel:"
245+
, "$tc'"
246+
247+
-- three chars
248+
, "$dm"
249+
, "$co"
250+
, "$tc"
251+
, "$cp"
252+
, "$fx"
253+
254+
-- two chars
255+
, "$W"
256+
, "$w"
257+
, "$m"
258+
, "$b"
259+
, "$c"
260+
, "$d"
261+
, "$i"
262+
, "$s"
263+
, "$f"
264+
, "$r"
265+
, "C:"
266+
, "N:"
267+
, "D:"
268+
, "$p"
269+
, "$L"
270+
, "$f"
271+
, "$t"
272+
, "$c"
273+
, "$m"
274+
]

ghcide/src/Development/IDE/Plugin/Completions/Logic.hs

Lines changed: 2 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import Development.IDE.Core.PositionMapping
4242
import Development.IDE.GHC.Compat hiding (ppr)
4343
import qualified Development.IDE.GHC.Compat as GHC
4444
import Development.IDE.GHC.Compat.Util
45+
import Development.IDE.GHC.CoreFile (occNamePrefixes)
4546
import Development.IDE.GHC.Error
4647
import Development.IDE.GHC.Util
4748
import Development.IDE.Plugin.Completions.Types
@@ -809,50 +810,7 @@ openingBacktick line prefixModule prefixText Position { _character=(fromIntegral
809810
-- TODO: Turn this into an alex lexer that discards prefixes as if they were whitespace.
810811
stripPrefix :: T.Text -> T.Text
811812
stripPrefix name = T.takeWhile (/=':') $ fromMaybe name $
812-
getFirst $ foldMap (First . (`T.stripPrefix` name)) prefixes
813-
814-
-- | Prefixes that can occur in a GHC OccName
815-
prefixes :: [T.Text]
816-
prefixes =
817-
[
818-
-- long ones
819-
"$con2tag_"
820-
, "$tag2con_"
821-
, "$maxtag_"
822-
823-
-- four chars
824-
, "$sel:"
825-
, "$tc'"
826-
827-
-- three chars
828-
, "$dm"
829-
, "$co"
830-
, "$tc"
831-
, "$cp"
832-
, "$fx"
833-
834-
-- two chars
835-
, "$W"
836-
, "$w"
837-
, "$m"
838-
, "$b"
839-
, "$c"
840-
, "$d"
841-
, "$i"
842-
, "$s"
843-
, "$f"
844-
, "$r"
845-
, "C:"
846-
, "N:"
847-
, "D:"
848-
, "$p"
849-
, "$L"
850-
, "$f"
851-
, "$t"
852-
, "$c"
853-
, "$m"
854-
]
855-
813+
getFirst $ foldMap (First . (`T.stripPrefix` name)) occNamePrefixes
856814

857815
safeTyThingForRecord :: TyThing -> Maybe (T.Text, [T.Text])
858816
safeTyThingForRecord (AnId _) = Nothing

ghcide/src/Development/IDE/Spans/AtPoint.hs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import Development.IDE.Core.PositionMapping
3232
import Development.IDE.Core.RuleTypes
3333
import Development.IDE.GHC.Compat
3434
import qualified Development.IDE.GHC.Compat.Util as Util
35+
import Development.IDE.GHC.CoreFile (occNamePrefixes)
3536
import Development.IDE.GHC.Util (printOutputable)
3637
import Development.IDE.Spans.Common
3738
import Development.IDE.Types.Options
@@ -229,12 +230,10 @@ atPoint IdeOptions{} (HAR _ hf _ _ kind) (DKMap dm km) env pos = listToMaybe $ p
229230
isInternal :: (Identifier, IdentifierDetails a) -> Bool
230231
isInternal (Right n, _) =
231232
let name = printOutputable n
232-
prefix = T.take 2 name
233-
in elem prefix ["$d", "$c"]
233+
in any (`T.isPrefixOf` name) occNamePrefixes
234234
isInternal (Left _, _) = False
235235
filteredNames = filter (not . isInternal) names
236236
types = nodeType info
237-
238237
prettyNames :: [T.Text]
239238
prettyNames = map prettyName filteredNames
240239
prettyName (Right n, dets) = T.unlines $

0 commit comments

Comments
 (0)