Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Class plugin bump up #2475

Merged
merged 5 commits into from
Dec 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ jobs:
name: Test hls-brittany-plugin
run: cabal test hls-brittany-plugin --test-options="$TEST_OPTS" || cabal test hls-brittany-plugin --test-options="$TEST_OPTS" || LSP_TEST_LOG_COLOR=0 LSP_TEST_LOG_MESSAGES=true LSP_TEST_LOG_STDERR=true cabal test hls-brittany-plugin --test-options="$TEST_OPTS"

- if: matrix.test && matrix.ghc != '9.0.1'
- if: matrix.test
name: Test hls-class-plugin
run: cabal test hls-class-plugin --test-options="$TEST_OPTS" || cabal test hls-class-plugin --test-options="$TEST_OPTS" || LSP_TEST_LOG_COLOR=0 LSP_TEST_LOG_MESSAGES=true LSP_TEST_LOG_STDERR=true cabal test hls-class-plugin --test-options="$TEST_OPTS"

Expand Down
2 changes: 1 addition & 1 deletion cabal-ghc901.project
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ index-state: 2021-11-29T12:30:07Z

constraints:
-- These plugins don't work on GHC9 yet
haskell-language-server +ignore-plugins-ghc-bounds -brittany -class -stylishhaskell -tactic,
haskell-language-server +ignore-plugins-ghc-bounds -brittany -stylishhaskell -tactic,
ghc-lib-parser ^>= 9.0

-- although we are not building all plugins cabal solver phase is run for all packages
Expand Down
2 changes: 0 additions & 2 deletions configuration-ghc-901.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ let
"hls-brittany-plugin"
"hls-stylish-haskell-plugin"
"hls-fourmolu-plugin"
"hls-class-plugin"
];

hpkgsOverride = hself: hsuper:
Expand All @@ -27,7 +26,6 @@ let
hself.callCabal2nixWithOptions "haskell-language-server" ./.
(pkgs.lib.concatStringsSep " " [
"-f-brittany"
"-f-class"
"-f-fourmolu"
"-f-stylishhaskell"
"-f-tactic"
Expand Down
2 changes: 1 addition & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
with haskell.lib; {
# Patches don't apply
github = overrideCabal hsuper.github (drv: { patches = []; });
# We need an older version
# We need an older version
hiedb = hself.hiedb_0_4_1_0;

implicit-hie-cradle = hself.callCabal2nix "implicit-hie-cradle"
Expand Down
2 changes: 1 addition & 1 deletion haskell-language-server.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ common example-plugins
Ide.Plugin.Example2

common class
if flag(class) && (impl(ghc < 9.0.1) || flag(ignore-plugins-ghc-bounds))
if flag(class) && (impl(ghc < 9.2.1) || flag(ignore-plugins-ghc-bounds))
build-depends: hls-class-plugin ^>=1.0.0.1
cpp-options: -Dclass

Expand Down
13 changes: 10 additions & 3 deletions plugins/hls-class-plugin/src/Ide/Plugin/Class.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{-# LANGUAGE CPP #-}
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE OverloadedStrings #-}
Expand Down Expand Up @@ -32,6 +33,7 @@ import Ide.Types
import Language.Haskell.GHC.ExactPrint
import Language.Haskell.GHC.ExactPrint.Parsers (parseDecl)
import Language.Haskell.GHC.ExactPrint.Types hiding (GhcPs, Parens)
import Language.Haskell.GHC.ExactPrint.Utils (rs)
import Language.LSP.Server
import Language.LSP.Types
import qualified Language.LSP.Types.Lens as J
Expand Down Expand Up @@ -85,20 +87,19 @@ addMethodPlaceholders state AddMinimalMethodsParams{..} = do
Right (ann, d) -> Just (setPrecedingLines d 1 indent ann, d)
Left _ -> Nothing

addMethodDecls :: ParsedSource -> [LHsDecl GhcPs] -> Transform (Located (HsModule GhcPs))
addMethodDecls ps mDecls = do
d <- findInstDecl ps
newSpan <- uniqueSrcSpanT
let
annKey = mkAnnKey d
newAnnKey = AnnKey newSpan (CN "HsValBinds")
newAnnKey = AnnKey (rs newSpan) (CN "HsValBinds")
addWhere mkds@(Map.lookup annKey -> Just ann)
= Map.insert newAnnKey ann2 mkds2
where
ann1 = ann
{ annsDP = annsDP ann ++ [(G AnnWhere, DP (0, 1))]
, annCapturedSpan = Just newAnnKey
, annSortKey = Just (fmap getLoc mDecls)
, annSortKey = Just (fmap (rs . getLoc) mDecls)
}
mkds2 = Map.insert annKey ann1 mkds
ann2 = annNone
Expand Down Expand Up @@ -168,9 +169,15 @@ codeAction state plId (CodeActionParams _ _ docId _ context) = liftIO $ fmap (fr
pure
$ head . head
$ pointCommand hf (fromJust (fromCurrentRange pmap range) ^. J.start & J.character -~ 1)
#if !MIN_VERSION_ghc(9,0,0)
( (Map.keys . Map.filter isClassNodeIdentifier . nodeIdentifiers . nodeInfo)
<=< nodeChildren
)
#else
( (Map.keys . Map.filter isClassNodeIdentifier . sourcedNodeIdents . sourcedNodeInfo)
<=< nodeChildren
)
#endif

findClassFromIdentifier docPath (Right name) = do
(hscEnv -> hscenv, _) <- MaybeT . runAction "classplugin" state $ useWithStale GhcSessionDeps docPath
Expand Down
2 changes: 1 addition & 1 deletion stack-9.0.1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ packages:
- ./hls-test-utils
- ./shake-bench
- ./plugins/hls-call-hierarchy-plugin
# - ./plugins/hls-class-plugin
- ./plugins/hls-class-plugin
- ./plugins/hls-haddock-comments-plugin
- ./plugins/hls-eval-plugin
- ./plugins/hls-explicit-imports-plugin
Expand Down