@@ -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
@@ -615,14 +614,14 @@ getCompletions plugins ideOpts CC {allModNamesAsNS, anyQualCompls, unqualCompls,
615
614
lpos = lowerRange position'
616
615
hpos = upperRange position'
617
616
in getCContext lpos pm <|> getCContext hpos pm
618
-
617
+
619
618
dotFieldSelectorToCompl :: T. Text -> (Bool , CompItem )
620
619
dotFieldSelectorToCompl label = (True , CI CiVariable label (ImportedFrom T. empty) Nothing label Nothing emptySpanDoc False Nothing )
621
620
622
621
-- we need the hieast to be fresh
623
622
-- not fresh, hasfield won't have a chance. it would to another larger change to ghc IfaceTyCon to contain record fields
624
623
tst :: [(Bool , CompItem )]
625
- tst = case maybe_ast_res of
624
+ tst = case maybe_ast_res of
626
625
Just (HAR {hieAst = hieast, hieKind = HieFresh },_) -> concat $ pointCommand hieast (completionPrefixPos prefixInfo) (theFunc HieFresh )
627
626
_ -> []
628
627
@@ -636,7 +635,7 @@ getCompletions plugins ideOpts CC {allModNamesAsNS, anyQualCompls, unqualCompls,
636
635
g :: Type -> [(Bool , CompItem )]
637
636
g (TyConApp theTyCon _) = map dotFieldSelectorToCompl $ getSels theTyCon
638
637
g _ = []
639
-
638
+
640
639
nodeInfoH :: HieKind a -> HieAST a -> NodeInfo a
641
640
nodeInfoH (HieFromDisk _) = nodeInfo'
642
641
nodeInfoH HieFresh = nodeInfo
@@ -690,7 +689,7 @@ getCompletions plugins ideOpts CC {allModNamesAsNS, anyQualCompls, unqualCompls,
690
689
thisModName = Local $ nameSrcSpan name
691
690
692
691
compls
693
- | T. null prefixScope = map (notQual,) localCompls ++ map (qual,) unqualCompls ++ ((notQual,) . ($ Nothing ) <$> anyQualCompls)
692
+ | T. null prefixScope = map (notQual,) localCompls ++ map (qual,) unqualCompls ++ ((notQual,) . ($ Nothing ) <$> anyQualCompls)
694
693
| not $ null tst = tst
695
694
| otherwise = ((qual,) <$> Map. findWithDefault [] prefixScope (getQualCompls qualCompls))
696
695
++ ((notQual,) . ($ Just prefixScope) <$> anyQualCompls)
@@ -953,28 +952,28 @@ mergeListsBy cmp all_lists = merge_lists all_lists
953
952
getCompletionPrefix :: (Monad m ) => Position -> VFS. VirtualFile -> m (Maybe PosPrefixInfo )
954
953
getCompletionPrefix pos@ (Position l c) (VFS. VirtualFile _ _ ropetext) =
955
954
return $ Just $ fromMaybe (PosPrefixInfo " " " " " " pos) $ do -- Maybe monad
956
- let headMaybe [] = Nothing
955
+ let headMaybe [] = Nothing
957
956
headMaybe (x: _) = Just x
958
- lastMaybe [] = Nothing
959
- lastMaybe xs = Just $ last xs
957
+ lastMaybe [] = Nothing
958
+ lastMaybe [x] = Just x
959
+ lastMaybe (_: xs) = lastMaybe xs
960
960
961
961
curLine <- headMaybe $ T. lines $ Rope. toText
962
962
$ fst $ Rope. splitAtLine 1 $ snd $ Rope. splitAtLine (fromIntegral l) ropetext
963
963
let beforePos = T. take (fromIntegral c) curLine
964
964
curWord <-
965
- if | T. null beforePos -> Just " "
965
+ if | T. null beforePos -> Just " "
966
966
| T. last beforePos == ' ' -> Just " " -- don't count abc as the curword in 'abc '
967
- | otherwise -> lastMaybe (T. words beforePos)
967
+ | otherwise -> lastMaybe (T. words beforePos)
968
968
969
969
let parts = T. split (== ' .' )
970
970
$ T. takeWhileEnd (\ x -> isAlphaNum x || x `elem` (" ._'" :: String )) curWord
971
971
case reverse parts of
972
972
[] -> Nothing
973
973
(x: xs) -> do
974
- let modParts = dropWhile (\ _ -> False )
975
- $ reverse $ filter (not . T. null ) xs
974
+ let modParts = reverse $ filter (not . T. null ) xs
976
975
modName = T. intercalate " ." modParts
977
976
return $ PosPrefixInfo { fullLine = curLine, prefixScope = modName, prefixText = x, cursorPos = pos }
978
977
979
978
completionPrefixPos :: PosPrefixInfo -> Position
980
- completionPrefixPos PosPrefixInfo { cursorPos = Position ln co, prefixText = str} = Position ln (co - (fromInteger . toInteger . T. length $ str) - 1 )
979
+ completionPrefixPos PosPrefixInfo { cursorPos = Position ln co, prefixText = str} = Position ln (co - (fromInteger . toInteger . T. length $ str) - 1 )
0 commit comments