Skip to content

Commit 763f34c

Browse files
jetjinsermichaelpjmergify[bot]
authored
Provide explicit import in inlay hints (#4235)
* Provide explicit import in inlay hints * Filter explict imports inlay hints by visible range * Update lsp dep by source-repository-package to writing test before new release of haskell/lsp. * Add test for hls-explicit-imports-plugin inlay hints * Comment inlay hints start position * Use `isSubrangeOf` to test if the range is visible * Remove inlayHintsResolveProvider placeholder for now * Use explicit InlayHintKind_Type * Revert "Update lsp dep by source-repository-package" This reverts commit 245049a. * Combine InlayHints by sconcat them and remove `instance PluginRequestMethod Method_InlayHintResolve` since have not decide how to combine. * compress multiple spaces in abbr import tilte * update test to match inlay hints kind * rename squashedAbbreviateImportTitle to abbreviateImportTitleWithoutModule * Request inlay hints with testEdits * ExplicitImports fallback to codelens when inlay hints not support * fix explicitImports inlayHints test * simplify isInlayHintsSupported * comment fallback * empty list instead of null codeLens * clearify name `paddingLeft` * fix clientCapabilities * add test for inlay hints without its client caps * use codeActionNoInlayHintsCaps to avoid error * simplify isInlayHintSupported * comment about paddingLeft * use null as inlay hints kind * add tooltip for explicit imports inlay hints to improve UX * chore comments * refactor * comment InL [] to indicate no info * ignore refine inlay hints * add plcInlayHintsOn config * update func-test * keep order to make Parser works * always provide refine in code lens --------- Co-authored-by: Michael Peyton Jones <[email protected]> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
1 parent 3862e7a commit 763f34c

File tree

12 files changed

+226
-36
lines changed

12 files changed

+226
-36
lines changed

hls-plugin-api/src/Ide/Plugin/Config.hs

+4-3
Original file line numberDiff line numberDiff line change
@@ -63,19 +63,20 @@ parsePlugins (IdePlugins plugins) = A.withObject "Config.plugins" $ \o -> do
6363
-- ---------------------------------------------------------------------
6464

6565
parsePluginConfig :: PluginConfig -> Value -> A.Parser PluginConfig
66-
parsePluginConfig def = A.withObject "PluginConfig" $ \o -> PluginConfig
66+
parsePluginConfig def = A.withObject "PluginConfig" $ \o -> PluginConfig
6767
<$> o .:? "globalOn" .!= plcGlobalOn def
6868
<*> o .:? "callHierarchyOn" .!= plcCallHierarchyOn def
69-
<*> o .:? "semanticTokensOn" .!= plcSemanticTokensOn def
7069
<*> o .:? "codeActionsOn" .!= plcCodeActionsOn def
7170
<*> o .:? "codeLensOn" .!= plcCodeLensOn def
71+
<*> o .:? "inlayHintsOn" .!= plcInlayHintsOn def
7272
<*> o .:? "diagnosticsOn" .!= plcDiagnosticsOn def -- AZ
7373
<*> o .:? "hoverOn" .!= plcHoverOn def
7474
<*> o .:? "symbolsOn" .!= plcSymbolsOn def
7575
<*> o .:? "completionOn" .!= plcCompletionOn def
7676
<*> o .:? "renameOn" .!= plcRenameOn def
7777
<*> o .:? "selectionRangeOn" .!= plcSelectionRangeOn def
78-
<*> o .:? "foldingRangeOn" .!= plcFoldingRangeOn def
78+
<*> o .:? "foldingRangeOn" .!= plcFoldingRangeOn def
79+
<*> o .:? "semanticTokensOn" .!= plcSemanticTokensOn def
7980
<*> o .:? "config" .!= plcConfig def
8081

8182
-- ---------------------------------------------------------------------

hls-plugin-api/src/Ide/Plugin/ConfigUtils.hs

+2
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ pluginsToDefaultConfig IdePlugins {..} =
8888
handlersToGenericDefaultConfig PluginConfig{..} (IdeMethod m DSum.:=> _) = case m of
8989
SMethod_TextDocumentCodeAction -> ["codeActionsOn" A..= plcCodeActionsOn]
9090
SMethod_TextDocumentCodeLens -> ["codeLensOn" A..= plcCodeLensOn]
91+
SMethod_TextDocumentInlayHint -> ["inlayHintsOn" A..= plcInlayHintsOn]
9192
SMethod_TextDocumentRename -> ["renameOn" A..= plcRenameOn]
9293
SMethod_TextDocumentHover -> ["hoverOn" A..= plcHoverOn]
9394
SMethod_TextDocumentDocumentSymbol -> ["symbolsOn" A..= plcSymbolsOn]
@@ -120,6 +121,7 @@ pluginsToVSCodeExtensionSchema IdePlugins {..} = A.object $ mconcat $ singlePlug
120121
handlersToGenericSchema PluginConfig{..} (IdeMethod m DSum.:=> _) = case m of
121122
SMethod_TextDocumentCodeAction -> [toKey' "codeActionsOn" A..= schemaEntry "code actions" plcCodeActionsOn]
122123
SMethod_TextDocumentCodeLens -> [toKey' "codeLensOn" A..= schemaEntry "code lenses" plcCodeLensOn]
124+
SMethod_TextDocumentInlayHint -> [toKey' "inlayHintsOn" A..= schemaEntry "inlay hints" plcInlayHintsOn]
123125
SMethod_TextDocumentRename -> [toKey' "renameOn" A..= schemaEntry "rename" plcRenameOn]
124126
SMethod_TextDocumentHover -> [toKey' "hoverOn" A..= schemaEntry "hover" plcHoverOn]
125127
SMethod_TextDocumentDocumentSymbol -> [toKey' "symbolsOn" A..= schemaEntry "symbols" plcSymbolsOn]

hls-plugin-api/src/Ide/Types.hs

+13-1
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,7 @@ data PluginConfig =
260260
, plcCallHierarchyOn :: !Bool
261261
, plcCodeActionsOn :: !Bool
262262
, plcCodeLensOn :: !Bool
263+
, plcInlayHintsOn :: !Bool
263264
, plcDiagnosticsOn :: !Bool
264265
, plcHoverOn :: !Bool
265266
, plcSymbolsOn :: !Bool
@@ -277,6 +278,7 @@ instance Default PluginConfig where
277278
, plcCallHierarchyOn = True
278279
, plcCodeActionsOn = True
279280
, plcCodeLensOn = True
281+
, plcInlayHintsOn = True
280282
, plcDiagnosticsOn = True
281283
, plcHoverOn = True
282284
, plcSymbolsOn = True
@@ -289,12 +291,13 @@ instance Default PluginConfig where
289291
}
290292

291293
instance ToJSON PluginConfig where
292-
toJSON (PluginConfig g ch ca cl d h s c rn sr fr st cfg) = r
294+
toJSON (PluginConfig g ch ca ih cl d h s c rn sr fr st cfg) = r
293295
where
294296
r = object [ "globalOn" .= g
295297
, "callHierarchyOn" .= ch
296298
, "codeActionsOn" .= ca
297299
, "codeLensOn" .= cl
300+
, "inlayHintsOn" .= ih
298301
, "diagnosticsOn" .= d
299302
, "hoverOn" .= h
300303
, "symbolsOn" .= s
@@ -511,6 +514,12 @@ instance PluginMethod Request Method_WorkspaceSymbol where
511514
-- Unconditionally enabled, but should it really be?
512515
handlesRequest _ _ _ _ = HandlesRequest
513516

517+
instance PluginMethod Request Method_TextDocumentInlayHint where
518+
handlesRequest = pluginEnabledWithFeature plcInlayHintsOn
519+
520+
instance PluginMethod Request Method_InlayHintResolve where
521+
handlesRequest = pluginEnabledResolve plcInlayHintsOn
522+
514523
instance PluginMethod Request Method_TextDocumentCodeLens where
515524
handlesRequest = pluginEnabledWithFeature plcCodeLensOn
516525

@@ -810,6 +819,9 @@ instance PluginRequestMethod Method_TextDocumentSemanticTokensFull where
810819
instance PluginRequestMethod Method_TextDocumentSemanticTokensFullDelta where
811820
combineResponses _ _ _ _ (x :| _) = x
812821

822+
instance PluginRequestMethod Method_TextDocumentInlayHint where
823+
combineResponses _ _ _ _ x = sconcat x
824+
813825
takeLefts :: [a |? b] -> [a]
814826
takeLefts = mapMaybe (\x -> [res | (InL res) <- Just x])
815827

hls-test-utils/src/Test/Hls/Util.hs

+7
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ module Test.Hls.Util
77
( -- * Test Capabilities
88
codeActionResolveCaps
99
, codeActionNoResolveCaps
10+
, codeActionNoInlayHintsCaps
1011
, codeActionSupportCaps
1112
, expectCodeAction
1213
-- * Environment specifications
@@ -107,6 +108,12 @@ codeActionNoResolveCaps :: ClientCapabilities
107108
codeActionNoResolveCaps = Test.fullLatestClientCaps
108109
& (L.textDocument . _Just . L.codeAction . _Just . L.resolveSupport) .~ Nothing
109110
& (L.textDocument . _Just . L.codeAction . _Just . L.dataSupport . _Just) .~ False
111+
112+
codeActionNoInlayHintsCaps :: ClientCapabilities
113+
codeActionNoInlayHintsCaps = Test.fullLatestClientCaps
114+
& (L.textDocument . _Just . L.codeAction . _Just . L.resolveSupport) .~ Nothing
115+
& (L.textDocument . _Just . L.codeAction . _Just . L.dataSupport . _Just) .~ False
116+
& (L.textDocument . _Just . L.inlayHint) .~ Nothing
110117
-- ---------------------------------------------------------------------
111118
-- Environment specification for ignoring tests
112119
-- ---------------------------------------------------------------------

0 commit comments

Comments
 (0)