File tree Expand file tree Collapse file tree 4 files changed +31
-14
lines changed
src/Development/IDE/Plugin Expand file tree Collapse file tree 4 files changed +31
-14
lines changed Original file line number Diff line number Diff line change @@ -127,6 +127,7 @@ dropListFromImportDecl iDecl = let
127
127
in f <$> iDecl
128
128
129
129
resolveCompletion :: ResolveFunction IdeState CompletionResolveData Method_CompletionItemResolve
130
+ resolveCompletion _ide _pid comp _uri NothingToResolve = pure comp
130
131
resolveCompletion ide _pid comp@ CompletionItem {_detail,_documentation,_data_} uri (CompletionResolveData _ needType (NameDetails mod occ)) =
131
132
do
132
133
file <- getNormalizedFilePathE uri
Original file line number Diff line number Diff line change @@ -229,7 +229,9 @@ mkCompl
229
229
_additionalTextEdits = Nothing ,
230
230
_commitCharacters = Nothing ,
231
231
_command = mbCommand,
232
- _data_ = toJSON <$> fmap (CompletionResolveData uri (isNothing typeText)) nameDetails,
232
+ _data_ = Just $ toJSON $ case nameDetails of
233
+ Nothing -> NothingToResolve
234
+ Just nameDets -> CompletionResolveData uri (isNothing typeText) nameDets,
233
235
_labelDetails = Nothing ,
234
236
_textEditText = Nothing }
235
237
removeSnippetsWhen (isJust isInfix) ci
@@ -309,7 +311,7 @@ mkExtCompl label =
309
311
defaultCompletionItemWithLabel :: T. Text -> CompletionItem
310
312
defaultCompletionItemWithLabel label =
311
313
CompletionItem label def def def def def def def def def
312
- def def def def def def def def def
314
+ def def def def def def def def ( Just $ toJSON NothingToResolve )
313
315
314
316
fromIdentInfo :: Uri -> IdentInfo -> Maybe T. Text -> CompItem
315
317
fromIdentInfo doc identInfo@ IdentInfo {.. } q = CI
Original file line number Diff line number Diff line change @@ -199,10 +199,19 @@ instance Show NameDetails where
199
199
-- | The data that is actually sent for resolve support
200
200
-- We need the URI to be able to reconstruct the GHC environment
201
201
-- in the file the completion was triggered in.
202
- data CompletionResolveData = CompletionResolveData
203
- { itemFile :: Uri
204
- , itemNeedsType :: Bool -- ^ Do we need to lookup a type for this item?
205
- , itemName :: NameDetails
206
- }
202
+ data CompletionResolveData
203
+ = NothingToResolve
204
+ -- ^ The client requested to resolve a completion, but there is nothing to resolve,
205
+ -- as we can't add any additional information, such as docs.
206
+ -- We still handle these requests, otherwise HLS will reject "completion/resolve" requests
207
+ -- which present on some clients (e.g., emacs) as an error message.
208
+ -- See https://github.com/haskell/haskell-language-server/issues/4451 for the issue that
209
+ -- triggered this change.
210
+ | CompletionResolveData
211
+ -- ^ Data that we use to handle "completion/resolve" requests.
212
+ { itemFile :: Uri
213
+ , itemNeedsType :: Bool -- ^ Do we need to lookup a type for this item?
214
+ , itemName :: NameDetails
215
+ }
207
216
deriving stock Generic
208
217
deriving anyclass (FromJSON , ToJSON )
Original file line number Diff line number Diff line change @@ -557,19 +557,24 @@ completionDocTests =
557
557
]
558
558
let expected = " *Imported from 'Prelude'*\n "
559
559
test doc (Position 1 7 ) " id" (Just $ T. length expected) [expected]
560
+ , testSessionEmpty " defined in where clause" $ do
561
+ doc <- createDoc " A.hs" " haskell" $ T. unlines
562
+ [ " module A where"
563
+ , " bar = foo"
564
+ , " where foobar = 5"
565
+ ]
566
+ let expected = " *Defined at line 3, column"
567
+ test doc (Position 1 9 ) " foobar" (Just $ T. length expected) [expected]
560
568
]
561
569
where
562
570
test doc pos label mn expected = do
563
571
_ <- waitForDiagnostics
564
572
compls <- getCompletions doc pos
565
573
rcompls <- forM compls $ \ item -> do
566
- if isJust (item ^. L. data_)
567
- then do
568
- rsp <- request SMethod_CompletionItemResolve item
569
- case rsp ^. L. result of
570
- Left err -> liftIO $ assertFailure (" completionItem/resolve failed with: " <> show err)
571
- Right x -> pure x
572
- else pure item
574
+ rsp <- request SMethod_CompletionItemResolve item
575
+ case rsp ^. L. result of
576
+ Left err -> liftIO $ assertFailure (" completionItem/resolve failed with: " <> show err)
577
+ Right x -> pure x
573
578
let compls' = [
574
579
-- We ignore doc uris since it points to the local path which determined by specific machines
575
580
case mn of
You can’t perform that action at this time.
0 commit comments