@@ -31,7 +31,6 @@ import Data.Either (fromRight)
31
31
import Data.Function (on )
32
32
import Data.Functor
33
33
import qualified Data.HashMap.Strict as HM
34
- import qualified Data.Map.Strict as M
35
34
36
35
import qualified Data.HashSet as HashSet
37
36
import Data.Monoid (First (.. ))
@@ -70,10 +69,10 @@ import qualified Language.LSP.VFS as VFS
70
69
import Text.Fuzzy.Parallel (Scored (score ),
71
70
original )
72
71
73
- import Data.Coerce (coerce )
74
72
import Development.IDE
75
73
76
74
import qualified Data.Rope.UTF16 as Rope
75
+ import Development.IDE.Spans.AtPoint (pointCommand )
77
76
78
77
-- Chunk size used for parallelizing fuzzy matching
79
78
chunkSize :: Int
@@ -617,52 +616,35 @@ getCompletions plugins ideOpts CC {allModNamesAsNS, anyQualCompls, unqualCompls,
617
616
hpos = upperRange position'
618
617
in getCContext lpos pm <|> getCContext hpos pm
619
618
620
- dotFieldSelectorToCompl :: T. Text -> (Bool , CompItem )
621
- dotFieldSelectorToCompl label = (True , CI CiVariable label (ImportedFrom T. empty) Nothing label Nothing emptySpanDoc False Nothing )
622
619
623
620
-- we need the hieast to be fresh
624
621
-- not fresh, hasfield won't have a chance. it would to another larger change to ghc IfaceTyCon to contain record fields
625
- tst :: [(Bool , CompItem )]
626
- tst = case maybe_ast_res of
627
- Just (HAR {hieAst = hieast, hieKind = HieFresh },_) -> concat $ pointCommand hieast (completionPrefixPos prefixInfo) (theFunc HieFresh )
622
+ recordDotSyntaxCompls :: [(Bool , CompItem )]
623
+ recordDotSyntaxCompls = case maybe_ast_res of
624
+ Just (HAR {hieAst = hieast, hieKind = HieFresh },_) -> concat $ pointCommand hieast (completionPrefixPos prefixInfo) nodeCompletions
628
625
_ -> []
629
-
630
- getSels :: GHC. TyCon -> [T. Text ]
631
- getSels tycon = let f fieldLabel = printOutputable fieldLabel
632
- in map f $ tyConFieldLabels tycon
633
-
634
- theFunc :: HieKind Type -> HieAST Type -> [(Bool , CompItem )]
635
- theFunc kind node = concatMap g (nodeType $ nodeInfoH kind node)
636
626
where
627
+ nodeCompletions :: HieAST Type -> [(Bool , CompItem )]
628
+ nodeCompletions node = concatMap g (nodeType $ nodeInfo node)
637
629
g :: Type -> [(Bool , CompItem )]
638
- g (TyConApp theTyCon _) = map dotFieldSelectorToCompl $ getSels theTyCon
630
+ g (TyConApp theTyCon _) = map ( dotFieldSelectorToCompl (printOutputable $ GHC. tyConName theTyCon)) $ getSels theTyCon
639
631
g _ = []
640
-
641
- nodeInfoH :: HieKind a -> HieAST a -> NodeInfo a
642
- nodeInfoH (HieFromDisk _) = nodeInfo'
643
- nodeInfoH HieFresh = nodeInfo
644
-
645
- pointCommand :: HieASTs t -> Position -> (HieAST t -> a ) -> [a ]
646
- pointCommand hf pos k =
647
- catMaybes $ M. elems $ flip M. mapWithKey (getAsts hf) $ \ fs ast ->
648
- -- Since GHC 9.2:
649
- -- getAsts :: Map HiePath (HieAst a)
650
- -- type HiePath = LexialFastString
651
- --
652
- -- but before:
653
- -- getAsts :: Map HiePath (HieAst a)
654
- -- type HiePath = FastString
655
- --
656
- -- 'coerce' here to avoid an additional function for maintaining
657
- -- backwards compatibility.
658
- case selectSmallestContaining (sp $ coerce fs) ast of
659
- Nothing -> Nothing
660
- Just ast' -> Just $ k ast'
661
- where
662
- sloc fs = mkRealSrcLoc fs (fromIntegral $ line+ 1 ) (fromIntegral $ cha+ 1 )
663
- sp fs = mkRealSrcSpan (sloc fs) (sloc fs)
664
- line = _line pos
665
- cha = _character pos
632
+ getSels :: GHC. TyCon -> [T. Text ]
633
+ getSels tycon = let f fieldLabel = printOutputable fieldLabel
634
+ in map f $ tyConFieldLabels tycon
635
+ dotFieldSelectorToCompl :: T. Text -> T. Text -> (Bool , CompItem )
636
+ -- dotFieldSelectorToCompl label = (True, CI CiVariable label (ImportedFrom T.empty) Nothing label Nothing emptySpanDoc False Nothing)
637
+ dotFieldSelectorToCompl recname label = (True , CI
638
+ { compKind = CiField
639
+ , insertText = label
640
+ , provenance = DefinedIn recname
641
+ , typeText = Nothing
642
+ , label = label
643
+ , isInfix = Nothing
644
+ , docs = emptySpanDoc
645
+ , isTypeCompl = False
646
+ , additionalTextEdits = Nothing
647
+ })
666
648
667
649
-- completions specific to the current context
668
650
ctxCompls' = case mcc of
@@ -692,7 +674,7 @@ getCompletions plugins ideOpts CC {allModNamesAsNS, anyQualCompls, unqualCompls,
692
674
693
675
compls
694
676
| T. null prefixScope = map (notQual,) localCompls ++ map (qual,) unqualCompls ++ ((notQual,) . ($ Nothing ) <$> anyQualCompls)
695
- | not $ null tst = tst
677
+ | not $ null recordDotSyntaxCompls = recordDotSyntaxCompls
696
678
| otherwise = ((qual,) <$> Map. findWithDefault [] prefixScope (getQualCompls qualCompls))
697
679
++ ((notQual,) . ($ Just prefixScope) <$> anyQualCompls)
698
680
0 commit comments