Skip to content

Commit 19387b4

Browse files
committed
Expand documentation for 'CompletionResolveData'
Add explanations and justification for 'NothingToResolve' constructor. Also, include historical note to explain how we end up with this 'CompletionResolveData' version.
1 parent d51c68d commit 19387b4

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

ghcide/src/Development/IDE/Plugin/Completions.hs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,13 @@ dropListFromImportDecl iDecl = let
127127
in f <$> iDecl
128128

129129
resolveCompletion :: ResolveFunction IdeState CompletionResolveData Method_CompletionItemResolve
130-
resolveCompletion _ide _pid comp _uri NothingToResolve = pure comp
130+
resolveCompletion _ide _pid comp _uri NothingToResolve =
131+
-- See docs of 'NothingToResolve' for the reasoning of this
132+
-- NO-OP handler.
133+
--
134+
-- Handle "completion/resolve" requests, even when we don't want to add
135+
-- any additional information to the 'CompletionItem'.
136+
pure comp
131137
resolveCompletion ide _pid comp@CompletionItem{_detail,_documentation,_data_} uri (CompletionResolveData _ needType (NameDetails mod occ)) =
132138
do
133139
file <- getNormalizedFilePathE uri

ghcide/src/Development/IDE/Plugin/Completions/Types.hs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,30 @@ data CompletionResolveData
207207
-- which present on some clients (e.g., emacs) as an error message.
208208
-- See https://github.com/haskell/haskell-language-server/issues/4451 for the issue that
209209
-- triggered this change.
210+
--
211+
-- Clients (i.e., VSCode) request completion items to be resolved if
212+
-- we advertise capabilities for it.
213+
-- However, HLS used to resolve completion items for only a subset of completion items,
214+
-- and reject requests for which there is no additional info available,
215+
-- e.g. function local variables don't have any docs or similar, so we didn't
216+
-- respond to "completion/resolve" requests for these completion items.
217+
-- We rejected these requests by *not* adding `_data_` (i.e., `_data_ = Nothing),
218+
-- which caused HLS to reject "completion/resolve" requests, as we can only thread
219+
-- requests to the appropriate plugin if this `_data_` field is populated and
220+
-- can be deserialised.
221+
-- Since this `_data_` was missing, we rejected the request with:
222+
--
223+
-- @
224+
-- Error processing message (error "No plugins are available to handle this SMethod_CompletionItemResolve request.
225+
-- Plugins installed for this method, but not available to handle this request are:
226+
-- ghcide-completions does not handle resolve requests for (unable to determine resolve owner)).").
227+
-- @
228+
--
229+
-- However, this proved to be annoying as some clients (i.e., emacs) display
230+
-- our request rejection prominently in the user interface.
231+
-- As this is annoying, we insert this "dummy" data 'NothingToResolve',
232+
-- which allows HLS to thread the "completion/resolve" request to this plugin.
233+
-- The plugin then simply returns the original 'CompletionItem',
210234
| CompletionResolveData
211235
-- ^ Data that we use to handle "completion/resolve" requests.
212236
{ itemFile :: Uri

0 commit comments

Comments
 (0)