File tree 3 files changed +49
-48
lines changed
ghcide/src/Development/IDE
3 files changed +49
-48
lines changed Original file line number Diff line number Diff line change @@ -10,14 +10,16 @@ module Development.IDE.GHC.CoreFile
10
10
, typecheckCoreFile
11
11
, readBinCoreFile
12
12
, writeBinCoreFile
13
- , getImplicitBinds ) where
13
+ , getImplicitBinds
14
+ , occNamePrefixes ) where
14
15
15
16
import Control.Monad
16
17
import Control.Monad.IO.Class
17
18
import Data.Foldable
18
19
import Data.IORef
19
20
import Data.List (isPrefixOf )
20
21
import Data.Maybe
22
+ import qualified Data.Text as T
21
23
import GHC.Fingerprint
22
24
23
25
import Development.IDE.GHC.Compat
@@ -228,3 +230,45 @@ tc_iface_bindings (TopIfaceNonRec v e) = do
228
230
tc_iface_bindings (TopIfaceRec vs) = do
229
231
vs' <- traverse (\ (v, e) -> (,) <$> pure v <*> tcIfaceExpr e) vs
230
232
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
+ ]
Original file line number Diff line number Diff line change @@ -42,6 +42,7 @@ import Development.IDE.Core.PositionMapping
42
42
import Development.IDE.GHC.Compat hiding (ppr )
43
43
import qualified Development.IDE.GHC.Compat as GHC
44
44
import Development.IDE.GHC.Compat.Util
45
+ import Development.IDE.GHC.CoreFile (occNamePrefixes )
45
46
import Development.IDE.GHC.Error
46
47
import Development.IDE.GHC.Util
47
48
import Development.IDE.Plugin.Completions.Types
@@ -809,50 +810,7 @@ openingBacktick line prefixModule prefixText Position { _character=(fromIntegral
809
810
-- TODO: Turn this into an alex lexer that discards prefixes as if they were whitespace.
810
811
stripPrefix :: T. Text -> T. Text
811
812
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
856
814
857
815
safeTyThingForRecord :: TyThing -> Maybe (T. Text , [T. Text ])
858
816
safeTyThingForRecord (AnId _) = Nothing
Original file line number Diff line number Diff line change @@ -32,6 +32,7 @@ import Development.IDE.Core.PositionMapping
32
32
import Development.IDE.Core.RuleTypes
33
33
import Development.IDE.GHC.Compat
34
34
import qualified Development.IDE.GHC.Compat.Util as Util
35
+ import Development.IDE.GHC.CoreFile (occNamePrefixes )
35
36
import Development.IDE.GHC.Util (printOutputable )
36
37
import Development.IDE.Spans.Common
37
38
import Development.IDE.Types.Options
@@ -229,12 +230,10 @@ atPoint IdeOptions{} (HAR _ hf _ _ kind) (DKMap dm km) env pos = listToMaybe $ p
229
230
isInternal :: (Identifier , IdentifierDetails a ) -> Bool
230
231
isInternal (Right n, _) =
231
232
let name = printOutputable n
232
- prefix = T. take 2 name
233
- in elem prefix [" $d" , " $c" ]
233
+ in any (`T.isPrefixOf` name) occNamePrefixes
234
234
isInternal (Left _, _) = False
235
235
filteredNames = filter (not . isInternal) names
236
236
types = nodeType info
237
-
238
237
prettyNames :: [T. Text ]
239
238
prettyNames = map prettyName filteredNames
240
239
prettyName (Right n, dets) = T. unlines $
You can’t perform that action at this time.
0 commit comments