Skip to content

Commit 821c7f6

Browse files
serrascocreature
authored andcommitted
Remove JSON instances for unused completion code (#305)
* Remove JSON instances for completions, since we are not implementing "resolve" * Remove completion resolve data from tests
1 parent 8f50699 commit 821c7f6

File tree

2 files changed

+8
-60
lines changed

2 files changed

+8
-60
lines changed

src/Development/IDE/Core/Completions.hs

Lines changed: 2 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ module Development.IDE.Core.Completions (
77
) where
88

99
import Control.Applicative
10-
import Data.Aeson
11-
import Data.Aeson.Types
1210
import Data.Char (isSpace)
1311
import Data.Generics
1412
import Data.List as List hiding (stripPrefix)
@@ -18,7 +16,6 @@ import qualified Data.Text as T
1816
import qualified Text.Fuzzy as Fuzzy
1917

2018
import GHC
21-
import Module
2219
import HscTypes
2320
import Name
2421
import RdrName
@@ -39,43 +36,6 @@ import Development.IDE.Spans.Documentation
3936

4037
-- From haskell-ide-engine/src/Haskell/Ide/Engine/Support/HieExtras.hs
4138

42-
data NameDetails
43-
= NameDetails Module OccName
44-
deriving (Eq)
45-
46-
nsJSON :: NameSpace -> Value
47-
nsJSON ns
48-
| isVarNameSpace ns = String "v"
49-
| isDataConNameSpace ns = String "c"
50-
| isTcClsNameSpace ns = String "t"
51-
| isTvNameSpace ns = String "z"
52-
| otherwise = error "namespace not recognized"
53-
54-
parseNs :: Value -> Parser NameSpace
55-
parseNs (String "v") = pure Name.varName
56-
parseNs (String "c") = pure dataName
57-
parseNs (String "t") = pure tcClsName
58-
parseNs (String "z") = pure tvName
59-
parseNs _ = mempty
60-
61-
instance FromJSON NameDetails where
62-
parseJSON v@(Array _)
63-
= do
64-
[modname,modid,namesp,occname] <- parseJSON v
65-
mn <- parseJSON modname
66-
mid <- parseJSON modid
67-
ns <- parseNs namesp
68-
occn <- parseJSON occname
69-
pure $ NameDetails (mkModule (stringToUnitId mid) (mkModuleName mn)) (mkOccName ns occn)
70-
parseJSON _ = mempty
71-
instance ToJSON NameDetails where
72-
toJSON (NameDetails mdl occ) = toJSON [toJSON mname,toJSON mid,nsJSON ns,toJSON occs]
73-
where
74-
mname = moduleNameString $ moduleName mdl
75-
mid = unitIdString $ moduleUnitId mdl
76-
ns = occNameSpace occ
77-
occs = occNameString occ
78-
7939
safeTyThingId :: TyThing -> Maybe Id
8040
safeTyThingId (AnId i) = Just i
8141
safeTyThingId (AConLike (RealDataCon dc)) = Just $ dataConWrapId dc
@@ -175,9 +135,6 @@ getCContext pos pm
175135
| otherwise = Nothing
176136
importInline _ _ = Nothing
177137

178-
type CompItemResolveData
179-
= Maybe NameDetails
180-
181138
occNameToComKind :: OccName -> CompletionItemKind
182139
occNameToComKind oc
183140
| isVarOcc oc = CiFunction
@@ -190,9 +147,8 @@ mkCompl CI{origName,importedFrom,thingType,label,isInfix,docs} =
190147
CompletionItem label kind (Just $ maybe "" (<>"\n") typeText <> importedFrom)
191148
(Just $ CompletionDocMarkup $ MarkupContent MkMarkdown $ T.intercalate sectionSeparator docs)
192149
Nothing Nothing Nothing Nothing (Just insertText) (Just Snippet)
193-
Nothing Nothing Nothing Nothing resolveData
150+
Nothing Nothing Nothing Nothing Nothing
194151
where kind = Just $ occNameToComKind $ occName origName
195-
resolveData = Just (toJSON nameDets)
196152
insertText = case isInfix of
197153
Nothing -> case getArgText <$> thingType of
198154
Nothing -> label
@@ -203,11 +159,6 @@ mkCompl CI{origName,importedFrom,thingType,label,isInfix,docs} =
203159
typeText
204160
| Just t <- thingType = Just . stripForall $ T.pack (showGhc t)
205161
| otherwise = Nothing
206-
nameDets =
207-
case (thingType, nameModule_maybe origName) of
208-
(Just _,_) -> Nothing
209-
(Nothing, Nothing) -> Nothing
210-
(Nothing, Just mdl) -> Just (NameDetails mdl (nameOccName origName))
211162

212163
stripForall :: T.Text -> T.Text
213164
stripForall t
@@ -242,9 +193,7 @@ mkModCompl :: T.Text -> CompletionItem
242193
mkModCompl label =
243194
CompletionItem label (Just CiModule) Nothing
244195
Nothing Nothing Nothing Nothing Nothing Nothing Nothing
245-
Nothing Nothing Nothing Nothing (Just $ toJSON resolveData)
246-
where resolveData :: CompItemResolveData
247-
resolveData = Nothing
196+
Nothing Nothing Nothing Nothing Nothing
248197

249198
mkImportCompl :: T.Text -> T.Text -> CompletionItem
250199
mkImportCompl enteredQual label =

test/exe/Main.hs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import Control.Applicative.Combinators
1212
import Control.Exception (catch)
1313
import Control.Monad
1414
import Control.Monad.IO.Class (liftIO)
15-
import qualified Data.Aeson as Aeson
1615
import Data.Char (toLower)
1716
import Data.Foldable
1817
import Development.IDE.GHC.Util
@@ -1092,27 +1091,27 @@ completionTests
10921091
let source = T.unlines ["module A where", "f = hea"]
10931092
docId <- openDoc' "A.hs" "haskell" source
10941093
compls <- getCompletions docId (Position 1 7)
1095-
liftIO $ compls @?= [complItem "head" ["GHC.List", "base", "v", "head"] (Just CiFunction)]
1094+
liftIO $ compls @?= [complItem "head" (Just CiFunction)]
10961095
, testSessionWait "type" $ do
10971096
let source = T.unlines ["{-# OPTIONS_GHC -Wall #-}", "module A () where", "f :: ()", "f = ()"]
10981097
docId <- openDoc' "A.hs" "haskell" source
10991098
expectDiagnostics [ ("A.hs", [(DsWarning, (3,0), "not used")]) ]
11001099
changeDoc docId [TextDocumentContentChangeEvent Nothing Nothing $ T.unlines ["{-# OPTIONS_GHC -Wall #-}", "module A () where", "f :: Bo", "f = True"]]
11011100
compls <- getCompletions docId (Position 2 7)
11021101
liftIO $ compls @?=
1103-
[ complItem "Bounded" ["GHC.Enum", "base", "t", "Bounded"] (Just CiClass)
1104-
, complItem "Bool" ["GHC.Types", "ghc-prim", "t", "Bool"] (Just CiClass)
1102+
[ complItem "Bounded" (Just CiClass)
1103+
, complItem "Bool" (Just CiClass)
11051104
]
11061105
, testSessionWait "qualified" $ do
11071106
let source = T.unlines ["{-# OPTIONS_GHC -Wunused-binds #-}", "module A () where", "f = ()"]
11081107
docId <- openDoc' "A.hs" "haskell" source
11091108
expectDiagnostics [ ("A.hs", [(DsWarning, (2, 0), "not used")]) ]
11101109
changeDoc docId [TextDocumentContentChangeEvent Nothing Nothing $ T.unlines ["{-# OPTIONS_GHC -Wunused-binds #-}", "module A () where", "f = Prelude.hea"]]
11111110
compls <- getCompletions docId (Position 2 15)
1112-
liftIO $ compls @?= [complItem "head" ["GHC.List", "base", "v", "head"] (Just CiFunction)]
1111+
liftIO $ compls @?= [complItem "head" (Just CiFunction)]
11131112
]
11141113
where
1115-
complItem label xdata kind = CompletionItem
1114+
complItem label kind = CompletionItem
11161115
{ _label = label
11171116
, _kind = kind
11181117
, _detail = Just "Prelude"
@@ -1127,7 +1126,7 @@ completionTests
11271126
, _additionalTextEdits = Nothing
11281127
, _commitCharacters = Nothing
11291128
, _command = Nothing
1130-
, _xdata = Just (Aeson.toJSON (xdata :: [T.Text]))
1129+
, _xdata = Nothing
11311130
}
11321131

11331132
outlineTests :: TestTree

0 commit comments

Comments
 (0)