@@ -14,14 +14,14 @@ module Development.IDE.Plugin.Completions.Logic (
14
14
) where
15
15
16
16
import Control.Applicative
17
- import Data.Char (isUpper )
17
+ import Data.Char (isAlphaNum , isUpper )
18
18
import Data.Generics
19
19
import Data.List.Extra as List hiding
20
20
(stripPrefix )
21
21
import qualified Data.Map as Map
22
22
23
- import Data.Maybe (fromMaybe , isJust ,
24
- mapMaybe , catMaybes )
23
+ import Data.Maybe (catMaybes , fromMaybe ,
24
+ isJust , mapMaybe )
25
25
import qualified Data.Text as T
26
26
import qualified Text.Fuzzy.Parallel as Fuzzy
27
27
@@ -31,7 +31,7 @@ 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
34
+ import qualified Data.Map.Strict as M
35
35
36
36
import qualified Data.HashSet as HashSet
37
37
import Data.Monoid (First (.. ))
@@ -69,11 +69,10 @@ import qualified Language.LSP.VFS as VFS
69
69
import Text.Fuzzy.Parallel (Scored (score ),
70
70
original )
71
71
72
- import Development.IDE
73
- import Data.Coerce ( coerce )
72
+ import Data.Coerce ( coerce )
73
+ import Development.IDE
74
74
75
- import Data.Char (isAlphaNum )
76
- import qualified Data.Rope.UTF16 as Rope
75
+ import qualified Data.Rope.UTF16 as Rope
77
76
78
77
-- Chunk size used for parallelizing fuzzy matching
79
78
chunkSize :: Int
@@ -610,14 +609,14 @@ getCompletions plId ideOpts CC {allModNamesAsNS, anyQualCompls, unqualCompls, qu
610
609
lpos = lowerRange position'
611
610
hpos = upperRange position'
612
611
in getCContext lpos pm <|> getCContext hpos pm
613
-
612
+
614
613
dotFieldSelectorToCompl :: T. Text -> (Bool , CompItem )
615
614
dotFieldSelectorToCompl label = (True , CI CiVariable label (ImportedFrom T. empty) Nothing label Nothing emptySpanDoc False Nothing )
616
615
617
616
-- we need the hieast to be fresh
618
617
-- not fresh, hasfield won't have a chance. it would to another larger change to ghc IfaceTyCon to contain record fields
619
618
tst :: [(Bool , CompItem )]
620
- tst = case maybe_ast_res of
619
+ tst = case maybe_ast_res of
621
620
Just (HAR {hieAst = hieast, hieKind = HieFresh },_) -> concat $ pointCommand hieast (completionPrefixPos prefixInfo) (theFunc HieFresh )
622
621
_ -> []
623
622
@@ -631,7 +630,7 @@ getCompletions plId ideOpts CC {allModNamesAsNS, anyQualCompls, unqualCompls, qu
631
630
g :: Type -> [(Bool , CompItem )]
632
631
g (TyConApp theTyCon _) = map dotFieldSelectorToCompl $ getSels theTyCon
633
632
g _ = []
634
-
633
+
635
634
nodeInfoH :: HieKind a -> HieAST a -> NodeInfo a
636
635
nodeInfoH (HieFromDisk _) = nodeInfo'
637
636
nodeInfoH HieFresh = nodeInfo
@@ -685,7 +684,7 @@ getCompletions plId ideOpts CC {allModNamesAsNS, anyQualCompls, unqualCompls, qu
685
684
thisModName = Local $ nameSrcSpan name
686
685
687
686
compls
688
- | T. null prefixScope = map (notQual,) localCompls ++ map (qual,) unqualCompls ++ ((notQual,) . ($ Nothing ) <$> anyQualCompls)
687
+ | T. null prefixScope = map (notQual,) localCompls ++ map (qual,) unqualCompls ++ ((notQual,) . ($ Nothing ) <$> anyQualCompls)
689
688
| not $ null tst = tst
690
689
| otherwise = ((qual,) <$> Map. findWithDefault [] prefixScope (getQualCompls qualCompls))
691
690
++ ((notQual,) . ($ Just prefixScope) <$> anyQualCompls)
@@ -947,28 +946,28 @@ mergeListsBy cmp all_lists = merge_lists all_lists
947
946
getCompletionPrefix :: (Monad m ) => Position -> VFS. VirtualFile -> m (Maybe PosPrefixInfo )
948
947
getCompletionPrefix pos@ (Position l c) (VFS. VirtualFile _ _ ropetext) =
949
948
return $ Just $ fromMaybe (PosPrefixInfo " " " " " " pos) $ do -- Maybe monad
950
- let headMaybe [] = Nothing
949
+ let headMaybe [] = Nothing
951
950
headMaybe (x: _) = Just x
952
- lastMaybe [] = Nothing
953
- lastMaybe xs = Just $ last xs
951
+ lastMaybe [] = Nothing
952
+ lastMaybe [x] = Just x
953
+ lastMaybe (_: xs) = lastMaybe xs
954
954
955
955
curLine <- headMaybe $ T. lines $ Rope. toText
956
956
$ fst $ Rope. splitAtLine 1 $ snd $ Rope. splitAtLine (fromIntegral l) ropetext
957
957
let beforePos = T. take (fromIntegral c) curLine
958
958
curWord <-
959
- if | T. null beforePos -> Just " "
959
+ if | T. null beforePos -> Just " "
960
960
| T. last beforePos == ' ' -> Just " " -- don't count abc as the curword in 'abc '
961
- | otherwise -> lastMaybe (T. words beforePos)
961
+ | otherwise -> lastMaybe (T. words beforePos)
962
962
963
963
let parts = T. split (== ' .' )
964
964
$ T. takeWhileEnd (\ x -> isAlphaNum x || x `elem` (" ._'" :: String )) curWord
965
965
case reverse parts of
966
966
[] -> Nothing
967
967
(x: xs) -> do
968
- let modParts = dropWhile (\ _ -> False )
969
- $ reverse $ filter (not . T. null ) xs
968
+ let modParts = reverse $ filter (not . T. null ) xs
970
969
modName = T. intercalate " ." modParts
971
970
return $ PosPrefixInfo { fullLine = curLine, prefixScope = modName, prefixText = x, cursorPos = pos }
972
971
973
972
completionPrefixPos :: PosPrefixInfo -> Position
974
- completionPrefixPos PosPrefixInfo { cursorPos = Position ln co, prefixText = str} = Position ln (co - (fromInteger . toInteger . T. length $ str) - 1 )
973
+ completionPrefixPos PosPrefixInfo { cursorPos = Position ln co, prefixText = str} = Position ln (co - (fromInteger . toInteger . T. length $ str) - 1 )
0 commit comments