Skip to content

Commit 816017e

Browse files
committed
add inlayhint logic
only show code lenses when inlay hints are not supported
1 parent 83f55eb commit 816017e

File tree

1 file changed

+28
-20
lines changed
  • plugins/hls-cabal-plugin/src/Ide/Plugin

1 file changed

+28
-20
lines changed

plugins/hls-cabal-plugin/src/Ide/Plugin/Cabal.hs

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -436,21 +436,25 @@ hover ide _ msgParam = do
436436

437437
lens :: PluginMethodHandler IdeState LSP.Method_TextDocumentCodeLens
438438
lens state _plId clp = do
439-
let uri = clp ^. JL.textDocument . JL.uri
439+
if not $ isInlayHintsSupported state
440+
then do
441+
let uri = clp ^. JL.textDocument . JL.uri
440442

441-
nfp <- getNormalizedFilePathE uri
442-
cabalFields <- runActionE "cabal.cabal-lens" state $ useE ParseCabalFields nfp
443-
let positionedDeps = concatMap parseDeps cabalFields
443+
nfp <- getNormalizedFilePathE uri
444+
cabalFields <- runActionE "cabal.cabal-lens" state $ useE ParseCabalFields nfp
445+
let positionedDeps = concatMap parseDeps cabalFields
444446

445-
let rfp = rootDir state
446-
let planJson = toNormalizedFilePath $ rfp </> planJsonPath
447-
planDeps <- runActionE "cabal.cabal-lens" state $ useE BuildDependencyVersionMapping planJson
447+
let rfp = rootDir state
448+
let planJson = toNormalizedFilePath $ rfp </> planJsonPath
449+
planDeps <- runActionE "cabal.cabal-lens" state $ useE BuildDependencyVersionMapping planJson
448450

449-
let lenses = Maybe.mapMaybe
450-
(\p@(PositionedDependency _ name) -> getCodeLens . Versioned p <$> Map.lookup name planDeps)
451-
positionedDeps
451+
let lenses = Maybe.mapMaybe
452+
(\p@(PositionedDependency _ name) -> getCodeLens . Versioned p <$> Map.lookup name planDeps)
453+
positionedDeps
452454

453-
pure $ InL lenses
455+
pure $ InL lenses
456+
else
457+
pure $ InL []
454458
where
455459
getCodeLens :: Versioned PositionedDependency -> CodeLens
456460
getCodeLens (Versioned (PositionedDependency pos _) v) =
@@ -477,23 +481,27 @@ hint state _plId clp =
477481
if isInlayHintsSupported state
478482
then do
479483
let uri = clp ^. JL.textDocument . JL.uri
480-
let rfp = toNormalizedFilePath $ rootDir state
481484

482485
nfp <- getNormalizedFilePathE uri
483-
cabalFields <- runActionE "cabal.cabal-inlayhint" state $ useE ParseCabalFields nfp
486+
cabalFields <- runActionE "cabal.cabal-lens" state $ useE ParseCabalFields nfp
484487
let positionedDeps = concatMap parseDeps cabalFields
485-
let hints = map getInlayHint positionedDeps
486-
487-
let testDep = PositionedDependency (Syntax.Position 1 1) "test"
488488

489-
pure $ InL (getInlayHint testDep : hints)
489+
let rfp = rootDir state
490+
let planJson = toNormalizedFilePath $ rfp </> planJsonPath
491+
planDeps <- runActionE "cabal.cabal-lens" state $ useE BuildDependencyVersionMapping planJson
492+
493+
let hints = Maybe.mapMaybe
494+
(\p@(PositionedDependency _ name) -> getInlayHint . Versioned p <$> Map.lookup name planDeps)
495+
positionedDeps
496+
497+
pure $ InL hints
490498
else
491499
pure $ InL []
492500
where
493-
getInlayHint :: PositionedDependency -> InlayHint
494-
getInlayHint (PositionedDependency pos dep) = InlayHint
501+
getInlayHint :: Versioned PositionedDependency -> InlayHint
502+
getInlayHint (Versioned (PositionedDependency pos _) v) = InlayHint
495503
{ _position = Types.cabalPositionToLSPPosition pos
496-
, _label = InL dep
504+
, _label = InL v
497505
, _kind = Nothing
498506
, _textEdits = Nothing
499507
, _tooltip = Nothing

0 commit comments

Comments
 (0)