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