Skip to content

Extract last 2 plugins and clean up others #1836

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

Merged
merged 20 commits into from
May 17, 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: 2 additions & 0 deletions cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ packages:
./plugins/hls-splice-plugin
./plugins/hls-floskell-plugin
./plugins/hls-pragmas-plugin
./plugins/hls-module-name-plugin
./plugins/hls-ormolu-plugin
tests: true

package *
Expand Down
9 changes: 2 additions & 7 deletions haskell-language-server.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ extra-source-files:
test/testdata/hlint/ignore/.hlint.yaml
test/testdata/**/*.h
test/testdata/**/*.hs
test/testdata/**/*.expected

flag pedantic
description: Enable -Werror
Expand Down Expand Up @@ -231,8 +230,7 @@ common hlint

common moduleName
if flag(moduleName) || flag(all-plugins)
hs-source-dirs: plugins/default/src
other-modules: Ide.Plugin.ModuleName
build-depends: hls-module-name-plugin ^>= 1.0.0.0
cpp-options: -DmoduleName

common pragmas
Expand All @@ -259,9 +257,7 @@ common fourmolu

common ormolu
if flag(ormolu) || flag(all-formatters)
hs-source-dirs: plugins/default/src
other-modules: Ide.Plugin.Ormolu
build-depends: ormolu ^>=0.1.2
build-depends: hls-ormolu-plugin ^>= 1.0.0.0
cpp-options: -Dormolu

common stylishHaskell
Expand Down Expand Up @@ -414,7 +410,6 @@ test-suite func-test
FunctionalLiquid
HieBios
Highlight
ModuleName
Progress
Reference
Rename
Expand Down
47 changes: 45 additions & 2 deletions hls-test-utils/src/Test/Hls.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{-# LANGUAGE GADTs #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE OverloadedStrings #-}
module Test.Hls
( module Test.Tasty.HUnit,
module Test.Tasty,
Expand All @@ -11,6 +12,8 @@ module Test.Hls
module Control.Applicative.Combinators,
defaultTestRunner,
goldenGitDiff,
goldenWithHaskellDoc,
goldenWithHaskellDocFormatter,
def,
runSessionWithServer,
runSessionWithServerFormatter,
Expand All @@ -30,6 +33,8 @@ import Control.Monad.IO.Class
import Data.ByteString.Lazy (ByteString)
import Data.Default (def)
import qualified Data.Text as T
import qualified Data.Text.Lazy as TL
import qualified Data.Text.Lazy.Encoding as TL
import Development.IDE (IdeState, hDuplicateTo',
noLogging)
import Development.IDE.Graph (ShakeOptions (shakeThreads))
Expand All @@ -46,6 +51,7 @@ import Language.LSP.Types
import Language.LSP.Types.Capabilities (ClientCapabilities)
import System.Directory (getCurrentDirectory,
setCurrentDirectory)
import System.FilePath
import System.IO.Extra
import System.IO.Unsafe (unsafePerformIO)
import System.Process.Extra (createPipe)
Expand All @@ -67,6 +73,43 @@ gitDiff fRef fNew = ["git", "-c", "core.fileMode=false", "diff", "--no-index", "
goldenGitDiff :: TestName -> FilePath -> IO ByteString -> TestTree
goldenGitDiff name = goldenVsStringDiff name gitDiff

goldenWithHaskellDoc
:: PluginDescriptor IdeState
-> TestName
-> FilePath
-> FilePath
-> FilePath
-> FilePath
-> (TextDocumentIdentifier -> Session ())
-> TestTree
goldenWithHaskellDoc plugin title testDataDir path desc ext act =
goldenGitDiff title (testDataDir </> path <.> desc <.> ext)
$ runSessionWithServer plugin testDataDir
$ TL.encodeUtf8 . TL.fromStrict
<$> do
doc <- openDoc (path <.> ext) "haskell"
act doc
documentContents doc

goldenWithHaskellDocFormatter
:: PluginDescriptor IdeState
-> String
-> TestName
-> FilePath
-> FilePath
-> FilePath
-> FilePath
-> (TextDocumentIdentifier -> Session ())
-> TestTree
goldenWithHaskellDocFormatter plugin formatter title testDataDir path desc ext act =
goldenGitDiff title (testDataDir </> path <.> desc <.> ext)
$ runSessionWithServerFormatter plugin formatter testDataDir
$ TL.encodeUtf8 . TL.fromStrict
<$> do
doc <- openDoc (path <.> ext) "haskell"
act doc
documentContents doc

runSessionWithServer :: PluginDescriptor IdeState -> FilePath -> Session a -> IO a
runSessionWithServer plugin = runSessionWithServer' [plugin] def def fullCaps

Expand Down
2 changes: 2 additions & 0 deletions nix/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ let
hls-brittany-plugin = gitignoreSource ../plugins/hls-brittany-plugin;
hls-stylish-haskell-plugin = gitignoreSource ../plugins/hls-stylish-haskell-plugin;
hls-fourmolu-plugin = gitignoreSource ../plugins/hls-fourmolu-plugin;
hls-ormolu-plugin = gitignoreSource ../plugins/hls-ormolu-plugin;
hls-class-plugin = gitignoreSource ../plugins/hls-class-plugin;
hls-haddock-comments-plugin = gitignoreSource ../plugins/hls-haddock-comments-plugin;
hls-eval-plugin = gitignoreSource ../plugins/hls-eval-plugin;
Expand All @@ -44,6 +45,7 @@ let
hls-tactics-plugin = gitignoreSource ../plugins/hls-tactics-plugin;
hls-floskell-plugin = gitignoreSource ../plugins/hls-floskell-plugin;
hls-pragmas-plugin = gitignoreSource ../plugins/hls-pragmas-plugin;
hls-module-name-plugin = gitignoreSource ../plugins/hls-module-name-plugin;
};
gitignoreSource = (import sources.gitignore { inherit (pkgs) lib; }).gitignoreSource;
extended = haskellPackages:
Expand Down
157 changes: 0 additions & 157 deletions plugins/default/src/Ide/Plugin/ModuleName.hs

This file was deleted.

3 changes: 1 addition & 2 deletions plugins/hls-brittany-plugin/hls-brittany-plugin.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ test-suite tests
ghc-options: -threaded -rtsopts -with-rtsopts=-N
build-depends:
, base
, bytestring
, filepath
, hls-brittany-plugin
, hls-test-utils ^>=1.0
, text
3 changes: 1 addition & 2 deletions plugins/hls-brittany-plugin/src/Ide/Plugin/Brittany.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import Control.Exception (bracket_)
import Control.Lens
import Control.Monad.IO.Class
import Control.Monad.Trans.Maybe (MaybeT, runMaybeT)
import Data.Coerce
import Data.Maybe (mapMaybe, maybeToList)
import Data.Semigroup
import Data.Text (Text)
Expand Down Expand Up @@ -81,7 +80,7 @@ runBrittany :: Int -- ^ tab size
runBrittany tabSize df confPath text = do
let cfg = mempty
{ _conf_layout =
mempty { _lconfig_indentAmount = opt (coerce tabSize)
mempty { _lconfig_indentAmount = opt (Last tabSize)
}
, _conf_forward =
(mempty :: CForwardOptions Option)
Expand Down
58 changes: 28 additions & 30 deletions plugins/hls-brittany-plugin/test/Main.hs
Original file line number Diff line number Diff line change
@@ -1,39 +1,37 @@
{-# LANGUAGE OverloadedStrings #-}
module Main(main) where
module Main
( main
) where

import qualified Data.ByteString.Lazy as BS
import qualified Data.Text.Encoding as T
import qualified Data.Text.IO as T
import qualified Ide.Plugin.Brittany as Brittany
import qualified Ide.Plugin.Brittany as Brittany
import System.FilePath
import Test.Hls

main :: IO ()
main = defaultTestRunner tests

plugin :: PluginDescriptor IdeState
plugin = Brittany.descriptor "brittany"
brittanyPlugin :: PluginDescriptor IdeState
brittanyPlugin = Brittany.descriptor "brittany"

tests :: TestTree
tests = testGroup "brittany" [
goldenGitDiff "formats a document with LF endings" "test/testdata/BrittanyLF.formatted_document.hs" $ runSessionWithServerFormatter plugin "brittany" "test/testdata" $ do
doc <- openDoc "BrittanyLF.hs" "haskell"
formatDoc doc (FormattingOptions 4 True Nothing Nothing Nothing)
BS.fromStrict . T.encodeUtf8 <$> documentContents doc

, goldenGitDiff "formats a document with CRLF endings" "test/testdata/BrittanyCRLF.formatted_document.hs" $ runSessionWithServerFormatter plugin "brittany" "test/testdata" $ do
doc <- openDoc "BrittanyCRLF.hs" "haskell"
formatDoc doc (FormattingOptions 4 True Nothing Nothing Nothing)
BS.fromStrict . T.encodeUtf8 <$> documentContents doc

, goldenGitDiff "formats a range with LF endings" "test/testdata/BrittanyLF.formatted_range.hs" $ runSessionWithServerFormatter plugin "brittany" "test/testdata" $ do
doc <- openDoc "BrittanyLF.hs" "haskell"
let range = Range (Position 1 0) (Position 2 22)
formatRange doc (FormattingOptions 4 True Nothing Nothing Nothing) range
BS.fromStrict . T.encodeUtf8 <$> documentContents doc

, goldenGitDiff "formats a range with CRLF endings" "test/testdata/BrittanyCRLF.formatted_range.hs" $ runSessionWithServerFormatter plugin "brittany" "test/testdata" $ do
doc <- openDoc "BrittanyCRLF.hs" "haskell"
let range = Range (Position 1 0) (Position 2 22)
formatRange doc (FormattingOptions 4 True Nothing Nothing Nothing) range
BS.fromStrict . T.encodeUtf8 <$> documentContents doc
]
tests = testGroup "brittany"
[ brittanyGolden "formats a document with LF endings" "BrittanyLF" "formatted_document" $ \doc -> do
formatDoc doc (FormattingOptions 4 True Nothing Nothing Nothing)

, brittanyGolden "formats a document with CRLF endings" "BrittanyCRLF" "formatted_document" $ \doc -> do
formatDoc doc (FormattingOptions 4 True Nothing Nothing Nothing)

, brittanyGolden "formats a range with LF endings" "BrittanyLF" "formatted_range" $ \doc -> do
let range = Range (Position 1 0) (Position 2 22)
formatRange doc (FormattingOptions 4 True Nothing Nothing Nothing) range

, brittanyGolden "formats a range with CRLF endings" "BrittanyCRLF" "formatted_range" $ \doc -> do
let range = Range (Position 1 0) (Position 2 22)
formatRange doc (FormattingOptions 4 True Nothing Nothing Nothing) range
]

brittanyGolden :: TestName -> FilePath -> FilePath -> (TextDocumentIdentifier -> Session ()) -> TestTree
brittanyGolden title path desc = goldenWithHaskellDocFormatter brittanyPlugin "brittany" title testDataDir path desc "hs"

testDataDir :: FilePath
testDataDir = "test" </> "testdata"
3 changes: 3 additions & 0 deletions plugins/hls-brittany-plugin/test/testdata/hie.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
cradle:
direct:
arguments: []
Loading