File tree Expand file tree Collapse file tree 3 files changed +49
-48
lines changed
ghcide/src/Development/IDE Expand file tree Collapse file tree 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
1010 , typecheckCoreFile
1111 , readBinCoreFile
1212 , writeBinCoreFile
13- , getImplicitBinds ) where
13+ , getImplicitBinds
14+ , occNamePrefixes ) where
1415
1516import Control.Monad
1617import Control.Monad.IO.Class
1718import Data.Foldable
1819import Data.IORef
1920import Data.List (isPrefixOf )
2021import Data.Maybe
22+ import qualified Data.Text as T
2123import GHC.Fingerprint
2224
2325import Development.IDE.GHC.Compat
@@ -228,3 +230,45 @@ tc_iface_bindings (TopIfaceNonRec v e) = do
228230tc_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+ ]
Original file line number Diff line number Diff line change @@ -41,6 +41,7 @@ import Development.IDE.Core.PositionMapping
4141import Development.IDE.GHC.Compat hiding (ppr )
4242import qualified Development.IDE.GHC.Compat as GHC
4343import Development.IDE.GHC.Compat.Util
44+ import Development.IDE.GHC.CoreFile (occNamePrefixes )
4445import Development.IDE.GHC.Error
4546import Development.IDE.GHC.Util
4647import Development.IDE.Plugin.Completions.Types
@@ -767,50 +768,7 @@ openingBacktick line prefixModule prefixText Position { _character=(fromIntegral
767768-- TODO: Turn this into an alex lexer that discards prefixes as if they were whitespace.
768769stripPrefix :: T. Text -> T. Text
769770stripPrefix name = T. takeWhile (/= ' :' ) $ fromMaybe name $
770- getFirst $ foldMap (First . (`T.stripPrefix` name)) prefixes
771-
772- -- | Prefixes that can occur in a GHC OccName
773- prefixes :: [T. Text ]
774- prefixes =
775- [
776- -- long ones
777- " $con2tag_"
778- , " $tag2con_"
779- , " $maxtag_"
780-
781- -- four chars
782- , " $sel:"
783- , " $tc'"
784-
785- -- three chars
786- , " $dm"
787- , " $co"
788- , " $tc"
789- , " $cp"
790- , " $fx"
791-
792- -- two chars
793- , " $W"
794- , " $w"
795- , " $m"
796- , " $b"
797- , " $c"
798- , " $d"
799- , " $i"
800- , " $s"
801- , " $f"
802- , " $r"
803- , " C:"
804- , " N:"
805- , " D:"
806- , " $p"
807- , " $L"
808- , " $f"
809- , " $t"
810- , " $c"
811- , " $m"
812- ]
813-
771+ getFirst $ foldMap (First . (`T.stripPrefix` name)) occNamePrefixes
814772
815773mkRecordSnippetCompItem :: Uri -> Maybe T. Text -> T. Text -> [T. Text ] -> Provenance -> Maybe (LImportDecl GhcPs ) -> CompItem
816774mkRecordSnippetCompItem uri parent ctxStr compl importedFrom imp = r
Original file line number Diff line number Diff line change @@ -34,6 +34,7 @@ import Development.IDE.Core.PositionMapping
3434import Development.IDE.Core.RuleTypes
3535import Development.IDE.GHC.Compat
3636import qualified Development.IDE.GHC.Compat.Util as Util
37+ import Development.IDE.GHC.CoreFile (occNamePrefixes )
3738import Development.IDE.GHC.Util (printOutputable )
3839import Development.IDE.Spans.Common
3940import Development.IDE.Types.Options
@@ -231,12 +232,10 @@ atPoint IdeOptions{} (HAR _ hf _ _ kind) (DKMap dm km) env pos = listToMaybe $ p
231232 isInternal :: (Identifier , IdentifierDetails a ) -> Bool
232233 isInternal (Right n, _) =
233234 let name = printOutputable n
234- prefix = T. take 2 name
235- in elem prefix [" $d" , " $c" ]
235+ in any (`T.isPrefixOf` name) occNamePrefixes
236236 isInternal (Left _, _) = False
237237 filteredNames = filter (not . isInternal) names
238238 types = nodeType info
239-
240239 prettyNames :: [T. Text ]
241240 prettyNames = map prettyName filteredNames
242241 prettyName (Right n, dets) = T. unlines $
You can’t perform that action at this time.
0 commit comments