From 0439024cce84763a1f193d7e62154074f932936c Mon Sep 17 00:00:00 2001 From: Junyoung/Clare Jang Date: Sat, 15 May 2021 22:58:41 -0400 Subject: [PATCH 01/20] Add goldenWithHaskellDoc test util --- hls-test-utils/src/Test/Hls.hs | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/hls-test-utils/src/Test/Hls.hs b/hls-test-utils/src/Test/Hls.hs index 7e6d05e191..4c081f6ebe 100644 --- a/hls-test-utils/src/Test/Hls.hs +++ b/hls-test-utils/src/Test/Hls.hs @@ -1,5 +1,6 @@ -{-# LANGUAGE GADTs #-} -{-# LANGUAGE LambdaCase #-} +{-# LANGUAGE GADTs #-} +{-# LANGUAGE LambdaCase #-} +{-# LANGUAGE OverloadedStrings #-} module Test.Hls ( module Test.Tasty.HUnit, module Test.Tasty, @@ -11,6 +12,7 @@ module Test.Hls module Control.Applicative.Combinators, defaultTestRunner, goldenGitDiff, + goldenWithHaskellDoc, def, runSessionWithServer, runSessionWithServerFormatter, @@ -30,6 +32,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)) @@ -46,6 +50,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) @@ -67,6 +72,24 @@ 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 + runSessionWithServer :: PluginDescriptor IdeState -> FilePath -> Session a -> IO a runSessionWithServer plugin = runSessionWithServer' [plugin] def def fullCaps From 34dde123c0786764c37d1f9c6a064a91f91738e7 Mon Sep 17 00:00:00 2001 From: Junyoung/Clare Jang Date: Sat, 15 May 2021 16:17:06 -0400 Subject: [PATCH 02/20] Extract module name plugin --- cabal.project | 1 + haskell-language-server.cabal | 9 +- nix/default.nix | 1 + plugins/default/src/Ide/Plugin/ModuleName.hs | 157 -------------- plugins/hls-module-name-plugin/LICENSE | 201 ++++++++++++++++++ .../hls-module-name-plugin.cabal | 47 ++++ .../src/Ide/Plugin/ModuleName.hs | 142 +++++++++++++ plugins/hls-module-name-plugin/test/Main.hs | 41 ++++ .../test/testdata/TEmptyModule.expected.hs | 0 .../test/testdata}/TEmptyModule.hs | 0 .../testdata/TWrongModuleName.expected.hs | 0 .../test/testdata}/TWrongModuleName.hs | 0 .../test/testdata/hie.yaml | 6 + .../test/testdata/mainlike.expected.hs | 0 .../test/testdata}/mainlike.hs | 0 stack-8.10.2.yaml | 1 + stack-8.10.3.yaml | 1 + stack-8.10.4.yaml | 1 + stack-8.6.4.yaml | 1 + stack-8.6.5.yaml | 1 + stack-8.8.2.yaml | 1 + stack-8.8.3.yaml | 1 + stack-8.8.4.yaml | 1 + stack.yaml | 1 + test/functional/Main.hs | 2 - test/functional/ModuleName.hs | 36 ---- test/testdata/moduleName/hie.yaml | 1 - 27 files changed, 450 insertions(+), 203 deletions(-) delete mode 100644 plugins/default/src/Ide/Plugin/ModuleName.hs create mode 100644 plugins/hls-module-name-plugin/LICENSE create mode 100644 plugins/hls-module-name-plugin/hls-module-name-plugin.cabal create mode 100644 plugins/hls-module-name-plugin/src/Ide/Plugin/ModuleName.hs create mode 100644 plugins/hls-module-name-plugin/test/Main.hs rename test/testdata/moduleName/TEmptyModule.hs.expected => plugins/hls-module-name-plugin/test/testdata/TEmptyModule.expected.hs (100%) rename {test/testdata/moduleName => plugins/hls-module-name-plugin/test/testdata}/TEmptyModule.hs (100%) rename test/testdata/moduleName/TWrongModuleName.hs.expected => plugins/hls-module-name-plugin/test/testdata/TWrongModuleName.expected.hs (100%) rename {test/testdata/moduleName => plugins/hls-module-name-plugin/test/testdata}/TWrongModuleName.hs (100%) create mode 100644 plugins/hls-module-name-plugin/test/testdata/hie.yaml rename test/testdata/moduleName/mainlike.hs.expected => plugins/hls-module-name-plugin/test/testdata/mainlike.expected.hs (100%) rename {test/testdata/moduleName => plugins/hls-module-name-plugin/test/testdata}/mainlike.hs (100%) delete mode 100644 test/functional/ModuleName.hs delete mode 100644 test/testdata/moduleName/hie.yaml diff --git a/cabal.project b/cabal.project index 9859c33873..b06c6d4a8a 100644 --- a/cabal.project +++ b/cabal.project @@ -20,6 +20,7 @@ packages: ./plugins/hls-splice-plugin ./plugins/hls-floskell-plugin ./plugins/hls-pragmas-plugin + ./plugins/hls-module-name-plugin tests: true package * diff --git a/haskell-language-server.cabal b/haskell-language-server.cabal index 744c7ab43b..f360eaf32f 100644 --- a/haskell-language-server.cabal +++ b/haskell-language-server.cabal @@ -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 @@ -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 @@ -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 @@ -414,7 +410,6 @@ test-suite func-test FunctionalLiquid HieBios Highlight - ModuleName Progress Reference Rename diff --git a/nix/default.nix b/nix/default.nix index 28bb55598c..8d4ea6eb13 100644 --- a/nix/default.nix +++ b/nix/default.nix @@ -44,6 +44,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: diff --git a/plugins/default/src/Ide/Plugin/ModuleName.hs b/plugins/default/src/Ide/Plugin/ModuleName.hs deleted file mode 100644 index 58ee66ccc8..0000000000 --- a/plugins/default/src/Ide/Plugin/ModuleName.hs +++ /dev/null @@ -1,157 +0,0 @@ -{-# LANGUAGE NoMonomorphismRestriction #-} -{-# LANGUAGE OverloadedStrings #-} -{-# LANGUAGE RecordWildCards #-} -{-# LANGUAGE ScopedTypeVariables #-} -{-# OPTIONS_GHC -Wall -Wwarn -fno-warn-type-defaults -fno-warn-unused-binds -fno-warn-unused-imports -Wno-unticked-promoted-constructors #-} - -{- | Keep the module name in sync with its file path. - -Provide CodeLenses to: -* Add a module header ("module /moduleName/ where") to empty Haskell files -* Fix the module name if incorrect --} -module Ide.Plugin.ModuleName ( - descriptor, -) where - -import Control.Monad -import Control.Monad.IO.Class (MonadIO (liftIO)) -import Data.Aeson (ToJSON (toJSON), Value (Null)) -import Data.Char (isLower) -import qualified Data.HashMap.Strict as Map -import Data.List (find, intercalate, isPrefixOf) -import Data.Maybe (maybeToList) -import Data.String (IsString) -import Data.Text (Text, pack) -import qualified Data.Text as T --- import Debug.Trace (trace) -import Development.IDE (GetParsedModule (GetParsedModule), - GhcSession (GhcSession), HscEnvEq, - IdeState, List (..), - NormalizedFilePath, - Position (Position), Range (Range), - evalGhcEnv, hscEnvWithImportPaths, - realSrcSpanToRange, runAction, - toNormalizedUri, uriToFilePath', use, - use_) -import GHC (DynFlags (importPaths), GenLocated (L), - HsModule (hsmodName), - ParsedModule (pm_parsed_source), - SrcSpan (RealSrcSpan), - getSessionDynFlags, unLoc) -import Ide.PluginUtils (getProcessID, mkLspCmdId) -import Ide.Types -import Language.LSP.Server -import Language.LSP.Types -import Language.LSP.VFS (virtualFileText) -import System.Directory (canonicalizePath) -import System.FilePath (dropExtension, splitDirectories, - takeFileName) - --- |Plugin descriptor -descriptor :: PluginId -> PluginDescriptor IdeState -descriptor plId = - (defaultPluginDescriptor plId) - { pluginHandlers = mkPluginHandler STextDocumentCodeLens codeLens - , pluginCommands = [PluginCommand editCommandName editCommandName command] - } - -editCommandName :: IsString p => p -editCommandName = "edit" - -asCodeLens :: Text -> Action -> CodeLens -asCodeLens cid Replace{..} = - CodeLens - aRange - (Just $ Command aTitle cid (Just (List [toJSON aUri]))) - Nothing - --- | Generate code lenses -codeLens :: PluginMethodHandler IdeState TextDocumentCodeLens -codeLens state pluginId CodeLensParams{_textDocument=TextDocumentIdentifier uri} = do - do - pid <- liftIO $ pack . show <$> getProcessID - Right . List . maybeToList . (asCodeLens (mkLspCmdId pid pluginId editCommandName) <$>) <$> action state uri - --- | (Quasi) Idempotent command execution: recalculate action to execute on command request -command :: CommandFunction IdeState Uri -command state uri = do - actMaybe <- action state uri - case actMaybe of - Nothing -> pure () - Just act -> void $ sendRequest SWorkspaceApplyEdit (ApplyWorkspaceEditParams Nothing (asEdit act)) (\_ -> pure ()) - return (Right Null) - --- | A source code change -data Action = Replace {aUri :: Uri, aRange :: Range, aTitle :: Text, aCode :: Text} deriving (Show) - --- | Convert an Action to the corresponding edit operation -asEdit :: Action -> WorkspaceEdit -asEdit act@Replace{..} = - WorkspaceEdit (Just $ Map.singleton aUri $ List (asTextEdits act)) Nothing Nothing - -asTextEdits :: Action -> [TextEdit] -asTextEdits Replace{..} = [TextEdit aRange aCode] - --- | Required action (that can be converted to either CodeLenses or CodeActions) -action :: IdeState -> Uri -> LspM c (Maybe Action) -action state uri = - traceAs "action" <$> do - let Just nfp = uriToNormalizedFilePath $ toNormalizedUri uri - let Just fp = uriToFilePath' uri - - contents <- getVirtualFile $ toNormalizedUri uri - let emptyModule = maybe True (T.null . T.strip . virtualFileText) contents - - correctNameMaybe <- liftIO $ traceAs "correctName" <$> pathModuleName state nfp fp - statedNameMaybe <- liftIO $ traceAs "statedName" <$> codeModuleName state nfp - - let act = Replace uri - let todo = case (correctNameMaybe, statedNameMaybe) of - (Just correctName, Just (nameRange, statedName)) - | correctName /= statedName -> - Just $ - act - nameRange - ("Set module name to " <> correctName) - correctName - (Just correctName, _) - | emptyModule -> - let code = T.unwords ["module", correctName, "where\n"] - in Just $ act (Range (Position 0 0) (Position 0 0)) code code - _ -> Nothing - return todo - --- | The module name, as derived by the position of the module in its source directory -pathModuleName :: IdeState -> NormalizedFilePath -> String -> IO (Maybe Text) -pathModuleName state normFilePath filePath - | isLower (head $ takeFileName filePath) = return $ Just "Main" - | otherwise = do - session :: HscEnvEq <- runAction "ModuleName.ghcSession" state $ use_ GhcSession normFilePath - srcPaths <- evalGhcEnv (hscEnvWithImportPaths session) $ importPaths <$> getSessionDynFlags - paths <- mapM canonicalizePath srcPaths - mdlPath <- canonicalizePath filePath - let maybePrefix = find (`isPrefixOf` mdlPath) paths - - let maybeMdlName = - ( \prefix -> - intercalate "." - . splitDirectories - . drop (length prefix + 1) - $ dropExtension mdlPath - ) - <$> maybePrefix - return $ T.pack <$> maybeMdlName - --- | The module name, as stated in the module -codeModuleName :: IdeState -> NormalizedFilePath -> IO (Maybe (Range, Text)) -codeModuleName state nfp = - ((\(L (RealSrcSpan l) m) -> (realSrcSpanToRange l, T.pack . show $ m)) <$>) - . ((hsmodName . unLoc . pm_parsed_source) =<<) - <$> runAction "ModuleName.GetParsedModule" state (use GetParsedModule nfp) - --- traceAs :: Show a => String -> a -> a --- traceAs lbl a = trace (lbl ++ " = " ++ show a) a - -traceAs :: b -> a -> a -traceAs _ a = a diff --git a/plugins/hls-module-name-plugin/LICENSE b/plugins/hls-module-name-plugin/LICENSE new file mode 100644 index 0000000000..261eeb9e9f --- /dev/null +++ b/plugins/hls-module-name-plugin/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/plugins/hls-module-name-plugin/hls-module-name-plugin.cabal b/plugins/hls-module-name-plugin/hls-module-name-plugin.cabal new file mode 100644 index 0000000000..6923dc8d19 --- /dev/null +++ b/plugins/hls-module-name-plugin/hls-module-name-plugin.cabal @@ -0,0 +1,47 @@ +cabal-version: 2.4 +name: hls-module-name-plugin +version: 1.0.0.0 +synopsis: Module name plugin for Haskell Language Server +description: + Please see the README on GitHub at + +license: Apache-2.0 +license-file: LICENSE +author: The Haskell IDE Team +copyright: The Haskell IDE Team +maintainer: alan.zimm@gmail.com +category: Development +build-type: Simple +extra-source-files: + LICENSE + test/testdata/*.hs + test/testdata/*.yaml + +library + exposed-modules: Ide.Plugin.ModuleName + hs-source-dirs: src + build-depends: + , aeson + , base >=4.12 && <5 + , directory + , filepath + , ghcide >=1.2 && <1.4 + , hls-plugin-api ^>=1.1 + , lsp + , text + , transformers + , unordered-containers + + default-language: Haskell2010 + +test-suite tests + type: exitcode-stdio-1.0 + default-language: Haskell2010 + hs-source-dirs: test + main-is: Main.hs + ghc-options: -threaded -rtsopts -with-rtsopts=-N + build-depends: + , base + , filepath + , hls-module-name-plugin + , hls-test-utils ^>=1.0 diff --git a/plugins/hls-module-name-plugin/src/Ide/Plugin/ModuleName.hs b/plugins/hls-module-name-plugin/src/Ide/Plugin/ModuleName.hs new file mode 100644 index 0000000000..637fa3f02e --- /dev/null +++ b/plugins/hls-module-name-plugin/src/Ide/Plugin/ModuleName.hs @@ -0,0 +1,142 @@ +{-# LANGUAGE DataKinds #-} +{-# LANGUAGE OverloadedStrings #-} +{-# LANGUAGE RecordWildCards #-} +{-# OPTIONS_GHC -Wall -Wwarn -fno-warn-type-defaults #-} + +{- | Keep the module name in sync with its file path. + +Provide CodeLenses to: +* Add a module header ("module /moduleName/ where") to empty Haskell files +* Fix the module name if incorrect +-} +module Ide.Plugin.ModuleName ( + descriptor, +) where + +import Control.Monad (forM_, void) +import Control.Monad.IO.Class (liftIO) +import Control.Monad.Trans.Class (lift) +import Control.Monad.Trans.Maybe +import Data.Aeson (Value (Null), toJSON) +import Data.Char (isLower) +import qualified Data.HashMap.Strict as HashMap +import Data.List (find, intercalate, isPrefixOf) +import Data.Maybe (maybeToList) +import Data.String (IsString) +import qualified Data.Text as T +import Development.IDE (GetParsedModule (GetParsedModule), + GhcSession (GhcSession), IdeState, + List (..), NormalizedFilePath, + Position (Position), Range (Range), + evalGhcEnv, hscEnvWithImportPaths, + realSrcSpanToRange, runAction, + toNormalizedUri, uriToFilePath', + use, use_) +import Development.IDE.GHC.Compat (GenLocated (L), + SrcSpan (RealSrcSpan), + getSessionDynFlags, hsmodName, + importPaths, pm_parsed_source, + unLoc) +import Ide.Types +import Language.LSP.Server +import Language.LSP.Types +import Language.LSP.VFS (virtualFileText) +import System.Directory (canonicalizePath) +import System.FilePath (dropExtension, splitDirectories, + takeFileName) + +-- |Plugin descriptor +descriptor :: PluginId -> PluginDescriptor IdeState +descriptor plId = + (defaultPluginDescriptor plId) + { pluginHandlers = mkPluginHandler STextDocumentCodeLens codeLens + , pluginCommands = [PluginCommand updateModuleNameCommand "set name of module to match with file path" command] + } + +updateModuleNameCommand :: IsString p => p +updateModuleNameCommand = "updateModuleName" + +-- | Generate code lenses +codeLens :: PluginMethodHandler IdeState 'TextDocumentCodeLens +codeLens state pluginId CodeLensParams{_textDocument=TextDocumentIdentifier uri} = + Right . List . maybeToList . (asCodeLens <$>) <$> action state uri + where + asCodeLens :: Action -> CodeLens + asCodeLens Replace{..} = CodeLens aRange (Just cmd) Nothing + where + cmd = mkLspCommand pluginId updateModuleNameCommand aTitle (Just [toJSON aUri]) + +-- | (Quasi) Idempotent command execution: recalculate action to execute on command request +command :: CommandFunction IdeState Uri +command state uri = do + actMaybe <- action state uri + forM_ actMaybe $ \Replace{..} -> + let + -- | Convert an Action to the corresponding edit operation + edit = WorkspaceEdit (Just . HashMap.singleton aUri $ List [TextEdit aRange aCode]) Nothing Nothing + in + void $ sendRequest SWorkspaceApplyEdit (ApplyWorkspaceEditParams Nothing edit) (const (pure ())) + pure $ Right Null + +-- | A source code change +data Action = Replace + { aUri :: Uri + , aRange :: Range + , aTitle :: T.Text + , aCode :: T.Text + } + deriving (Show) + +-- | Required action (that can be converted to either CodeLenses or CodeActions) +action :: IdeState -> Uri -> LspM c (Maybe Action) +action state uri = + traceAs "action" <$> runMaybeT $ do + nfp <- MaybeT . pure . uriToNormalizedFilePath $ toNormalizedUri uri + fp <- MaybeT . pure $ uriToFilePath' uri + + contents <- lift . getVirtualFile $ toNormalizedUri uri + let emptyModule = maybe True (T.null . T.strip . virtualFileText) contents + + correctName <- MaybeT . liftIO $ traceAs "correctName" <$> pathModuleName state nfp fp + + statedNameMaybe <- liftIO $ traceAs "statedName" <$> codeModuleName state nfp + case statedNameMaybe of + Just (nameRange, statedName) + | correctName /= statedName -> + pure $ Replace uri nameRange ("Set module name to " <> correctName) correctName + Nothing + | emptyModule -> + let code = "module " <> correctName <> " where\n" + in pure $ Replace uri (Range (Position 0 0) (Position 0 0)) code code + _ -> MaybeT $ pure Nothing + +-- | The module name, as derived by the position of the module in its source directory +pathModuleName :: IdeState -> NormalizedFilePath -> String -> IO (Maybe T.Text) +pathModuleName state normFilePath filePath + | isLower . head $ takeFileName filePath = return $ Just "Main" + | otherwise = do + session <- runAction "ModuleName.ghcSession" state $ use_ GhcSession normFilePath + srcPaths <- evalGhcEnv (hscEnvWithImportPaths session) $ importPaths <$> getSessionDynFlags + paths <- mapM canonicalizePath srcPaths + mdlPath <- canonicalizePath filePath + pure $ do + prefix <- find (`isPrefixOf` mdlPath) paths + pure + . T.pack + . intercalate "." + . splitDirectories + . drop (length prefix + 1) + $ dropExtension mdlPath + +-- | The module name, as stated in the module +codeModuleName :: IdeState -> NormalizedFilePath -> IO (Maybe (Range, T.Text)) +codeModuleName state nfp = runMaybeT $ do + pm <- MaybeT . runAction "ModuleName.GetParsedModule" state $ use GetParsedModule nfp + L (RealSrcSpan l) m <- MaybeT . pure . hsmodName . unLoc $ pm_parsed_source pm + pure (realSrcSpanToRange l, T.pack $ show m) + +-- traceAs :: Show a => String -> a -> a +-- traceAs lbl a = trace (lbl ++ " = " ++ show a) a + +traceAs :: b -> a -> a +traceAs _ a = a diff --git a/plugins/hls-module-name-plugin/test/Main.hs b/plugins/hls-module-name-plugin/test/Main.hs new file mode 100644 index 0000000000..2ee496818f --- /dev/null +++ b/plugins/hls-module-name-plugin/test/Main.hs @@ -0,0 +1,41 @@ +{-# LANGUAGE DuplicateRecordFields #-} +{-# LANGUAGE OverloadedStrings #-} +module Main + ( main + ) where + +import Control.Monad (void) +import qualified Ide.Plugin.ModuleName as ModuleName +import System.FilePath +import Test.Hls + +main :: IO () +main = defaultTestRunner tests + +moduleNamePlugin :: PluginDescriptor IdeState +moduleNamePlugin = ModuleName.descriptor "moduleName" + +tests :: TestTree +tests = + testGroup "moduleName" + [ goldenWithModuleName "Add module header to empty module" "TEmptyModule" $ \doc -> do + [CodeLens { _command = Just c }] <- getCodeLenses doc + executeCommand c + void $ skipManyTill anyMessage (message SWorkspaceApplyEdit) + + , goldenWithModuleName "Fix wrong module name" "TWrongModuleName" $ \doc -> do + [CodeLens { _command = Just c }] <- getCodeLenses doc + executeCommand c + void $ skipManyTill anyMessage (message SWorkspaceApplyEdit) + + , goldenWithModuleName "Must infer module name as Main, if the file name starts with a lowercase" "mainlike" $ \doc -> do + [CodeLens { _command = Just c }] <- getCodeLenses doc + executeCommand c + void $ skipManyTill anyMessage (message SWorkspaceApplyEdit) + ] + +goldenWithModuleName :: TestName -> FilePath -> (TextDocumentIdentifier -> Session ()) -> TestTree +goldenWithModuleName title path = goldenWithHaskellDoc moduleNamePlugin title testDataDir path "expected" "hs" + +testDataDir :: FilePath +testDataDir = "test" "testdata" diff --git a/test/testdata/moduleName/TEmptyModule.hs.expected b/plugins/hls-module-name-plugin/test/testdata/TEmptyModule.expected.hs similarity index 100% rename from test/testdata/moduleName/TEmptyModule.hs.expected rename to plugins/hls-module-name-plugin/test/testdata/TEmptyModule.expected.hs diff --git a/test/testdata/moduleName/TEmptyModule.hs b/plugins/hls-module-name-plugin/test/testdata/TEmptyModule.hs similarity index 100% rename from test/testdata/moduleName/TEmptyModule.hs rename to plugins/hls-module-name-plugin/test/testdata/TEmptyModule.hs diff --git a/test/testdata/moduleName/TWrongModuleName.hs.expected b/plugins/hls-module-name-plugin/test/testdata/TWrongModuleName.expected.hs similarity index 100% rename from test/testdata/moduleName/TWrongModuleName.hs.expected rename to plugins/hls-module-name-plugin/test/testdata/TWrongModuleName.expected.hs diff --git a/test/testdata/moduleName/TWrongModuleName.hs b/plugins/hls-module-name-plugin/test/testdata/TWrongModuleName.hs similarity index 100% rename from test/testdata/moduleName/TWrongModuleName.hs rename to plugins/hls-module-name-plugin/test/testdata/TWrongModuleName.hs diff --git a/plugins/hls-module-name-plugin/test/testdata/hie.yaml b/plugins/hls-module-name-plugin/test/testdata/hie.yaml new file mode 100644 index 0000000000..221ee3dd72 --- /dev/null +++ b/plugins/hls-module-name-plugin/test/testdata/hie.yaml @@ -0,0 +1,6 @@ +cradle: + direct: + arguments: + - "TEmptyModule" + - "TWrongModuleName" + - "mainlike" diff --git a/test/testdata/moduleName/mainlike.hs.expected b/plugins/hls-module-name-plugin/test/testdata/mainlike.expected.hs similarity index 100% rename from test/testdata/moduleName/mainlike.hs.expected rename to plugins/hls-module-name-plugin/test/testdata/mainlike.expected.hs diff --git a/test/testdata/moduleName/mainlike.hs b/plugins/hls-module-name-plugin/test/testdata/mainlike.hs similarity index 100% rename from test/testdata/moduleName/mainlike.hs rename to plugins/hls-module-name-plugin/test/testdata/mainlike.hs diff --git a/stack-8.10.2.yaml b/stack-8.10.2.yaml index ef1eb8a5e7..c1bcb4d3d6 100644 --- a/stack-8.10.2.yaml +++ b/stack-8.10.2.yaml @@ -22,6 +22,7 @@ packages: - ./plugins/hls-floskell-plugin - ./plugins/hls-fourmolu-plugin - ./plugins/hls-pragmas-plugin + - ./plugins/hls-module-name-plugin ghc-options: "$everything": -haddock diff --git a/stack-8.10.3.yaml b/stack-8.10.3.yaml index cfc7c4699b..85f4cc1db6 100644 --- a/stack-8.10.3.yaml +++ b/stack-8.10.3.yaml @@ -22,6 +22,7 @@ packages: - ./plugins/hls-floskell-plugin - ./plugins/hls-fourmolu-plugin - ./plugins/hls-pragmas-plugin + - ./plugins/hls-module-name-plugin ghc-options: "$everything": -haddock diff --git a/stack-8.10.4.yaml b/stack-8.10.4.yaml index f70dda59fc..ee9e751dab 100644 --- a/stack-8.10.4.yaml +++ b/stack-8.10.4.yaml @@ -22,6 +22,7 @@ packages: - ./plugins/hls-floskell-plugin - ./plugins/hls-fourmolu-plugin - ./plugins/hls-pragmas-plugin + - ./plugins/hls-module-name-plugin ghc-options: "$everything": -haddock diff --git a/stack-8.6.4.yaml b/stack-8.6.4.yaml index b8a8ce9eb5..7692d36aa8 100644 --- a/stack-8.6.4.yaml +++ b/stack-8.6.4.yaml @@ -23,6 +23,7 @@ packages: - ./plugins/hls-floskell-plugin - ./plugins/hls-fourmolu-plugin - ./plugins/hls-pragmas-plugin + - ./plugins/hls-module-name-plugin ghc-options: "$everything": -haddock diff --git a/stack-8.6.5.yaml b/stack-8.6.5.yaml index 110e2ca671..9d5459ff15 100644 --- a/stack-8.6.5.yaml +++ b/stack-8.6.5.yaml @@ -22,6 +22,7 @@ packages: - ./plugins/hls-floskell-plugin - ./plugins/hls-fourmolu-plugin - ./plugins/hls-pragmas-plugin + - ./plugins/hls-module-name-plugin ghc-options: "$everything": -haddock diff --git a/stack-8.8.2.yaml b/stack-8.8.2.yaml index e0ea2be6fc..325fb78c7d 100644 --- a/stack-8.8.2.yaml +++ b/stack-8.8.2.yaml @@ -22,6 +22,7 @@ packages: - ./plugins/hls-floskell-plugin - ./plugins/hls-fourmolu-plugin - ./plugins/hls-pragmas-plugin + - ./plugins/hls-module-name-plugin ghc-options: "$everything": -haddock diff --git a/stack-8.8.3.yaml b/stack-8.8.3.yaml index baf1d28b34..906df8fb8d 100644 --- a/stack-8.8.3.yaml +++ b/stack-8.8.3.yaml @@ -22,6 +22,7 @@ packages: - ./plugins/hls-floskell-plugin - ./plugins/hls-fourmolu-plugin - ./plugins/hls-pragmas-plugin + - ./plugins/hls-module-name-plugin ghc-options: "$everything": -haddock diff --git a/stack-8.8.4.yaml b/stack-8.8.4.yaml index 6b403b628b..33b8ff6da6 100644 --- a/stack-8.8.4.yaml +++ b/stack-8.8.4.yaml @@ -22,6 +22,7 @@ packages: - ./plugins/hls-floskell-plugin - ./plugins/hls-fourmolu-plugin - ./plugins/hls-pragmas-plugin + - ./plugins/hls-module-name-plugin ghc-options: "$everything": -haddock diff --git a/stack.yaml b/stack.yaml index 6958060f18..24f4b22f1f 100644 --- a/stack.yaml +++ b/stack.yaml @@ -22,6 +22,7 @@ packages: - ./plugins/hls-floskell-plugin - ./plugins/hls-fourmolu-plugin - ./plugins/hls-pragmas-plugin + - ./plugins/hls-module-name-plugin ghc-options: "$everything": -haddock diff --git a/test/functional/Main.hs b/test/functional/Main.hs index 660eee674d..8da258b708 100644 --- a/test/functional/Main.hs +++ b/test/functional/Main.hs @@ -12,7 +12,6 @@ import FunctionalCodeAction import FunctionalLiquid import HieBios import Highlight -import ModuleName import Progress import Reference import Rename @@ -36,7 +35,6 @@ main = defaultTestRunner , FunctionalLiquid.tests , HieBios.tests , Highlight.tests - , ModuleName.tests , Progress.tests , Reference.tests , Rename.tests diff --git a/test/functional/ModuleName.hs b/test/functional/ModuleName.hs deleted file mode 100644 index 7c5b6130ba..0000000000 --- a/test/functional/ModuleName.hs +++ /dev/null @@ -1,36 +0,0 @@ -{-# LANGUAGE DuplicateRecordFields #-} -{-# LANGUAGE OverloadedStrings #-} -{-# LANGUAGE ScopedTypeVariables #-} - -module ModuleName - ( tests - ) -where - -import qualified Data.Text.IO as T -import System.FilePath ((<.>), ()) -import Test.Hls -import Test.Hls.Command - -tests :: TestTree -tests = testGroup - "moduleName" - [ testCase "Add module header to empty module" $ goldenTest "TEmptyModule.hs" - , testCase "Fix wrong module name" $ goldenTest "TWrongModuleName.hs" - , testCase "Must infer module name as Main, if the file name starts with a lowercase" $ goldenTest "mainlike.hs" - ] - -goldenTest :: FilePath -> IO () -goldenTest input = runSession hlsCommand fullCaps testdataPath $ do - doc <- openDoc input "haskell" - -- getCodeLenses doc >>= liftIO . print . length - [CodeLens { _command = Just c }] <- getCodeLenses doc - executeCommand c - _resp <- skipManyTill anyMessage (message SWorkspaceApplyEdit) - edited <- documentContents doc - -- liftIO $ T.writeFile (testdataPath input <.> "expected") edited - expected <- liftIO $ T.readFile $ testdataPath input <.> "expected" - liftIO $ edited @?= expected - -testdataPath :: FilePath -testdataPath = "test/testdata/moduleName" diff --git a/test/testdata/moduleName/hie.yaml b/test/testdata/moduleName/hie.yaml deleted file mode 100644 index bf9d384c32..0000000000 --- a/test/testdata/moduleName/hie.yaml +++ /dev/null @@ -1 +0,0 @@ -cradle: { direct: { arguments: ["TEmptyModule", "TWrongModuleName", "mainlike"] } } From 0a9b876943b08c45312200526b6e88e7296494e5 Mon Sep 17 00:00:00 2001 From: Junyoung/Clare Jang Date: Sat, 15 May 2021 22:26:18 -0400 Subject: [PATCH 03/20] Extract ormolu plugin --- cabal.project | 1 + nix/default.nix | 1 + plugins/hls-ormolu-plugin/LICENSE | 201 ++++++++++++++++++ .../hls-ormolu-plugin/hls-ormolu-plugin.cabal | 47 ++++ .../src/Ide/Plugin/Ormolu.hs | 58 +++-- plugins/hls-ormolu-plugin/test/Main.hs | 29 +++ .../test/testdata/Ormolu.expected.hs | 16 ++ .../test/testdata/Ormolu.formatted.hs | 16 ++ .../hls-ormolu-plugin/test/testdata/Ormolu.hs | 15 ++ .../test/testdata/Ormolu2.expected.hs | 0 .../test/testdata/Ormolu2.formatted.hs | 5 + .../test/testdata/Ormolu2.hs | 0 .../hls-ormolu-plugin/test/testdata/hie.yaml | 2 + stack-8.10.2.yaml | 1 + stack-8.10.3.yaml | 1 + stack-8.10.4.yaml | 1 + stack-8.6.4.yaml | 1 + stack-8.6.5.yaml | 1 + stack-8.8.2.yaml | 1 + stack-8.8.3.yaml | 1 + stack-8.8.4.yaml | 1 + stack.yaml | 1 + test/functional/Format.hs | 17 -- 23 files changed, 369 insertions(+), 48 deletions(-) create mode 100644 plugins/hls-ormolu-plugin/LICENSE create mode 100644 plugins/hls-ormolu-plugin/hls-ormolu-plugin.cabal rename plugins/{default => hls-ormolu-plugin}/src/Ide/Plugin/Ormolu.hs (59%) create mode 100644 plugins/hls-ormolu-plugin/test/Main.hs create mode 100644 plugins/hls-ormolu-plugin/test/testdata/Ormolu.expected.hs create mode 100644 plugins/hls-ormolu-plugin/test/testdata/Ormolu.formatted.hs create mode 100644 plugins/hls-ormolu-plugin/test/testdata/Ormolu.hs rename test/testdata/format/Format2.ormolu.formatted.hs => plugins/hls-ormolu-plugin/test/testdata/Ormolu2.expected.hs (100%) create mode 100644 plugins/hls-ormolu-plugin/test/testdata/Ormolu2.formatted.hs rename test/testdata/format/Format2.hs => plugins/hls-ormolu-plugin/test/testdata/Ormolu2.hs (100%) create mode 100644 plugins/hls-ormolu-plugin/test/testdata/hie.yaml diff --git a/cabal.project b/cabal.project index b06c6d4a8a..d85f35b23d 100644 --- a/cabal.project +++ b/cabal.project @@ -21,6 +21,7 @@ packages: ./plugins/hls-floskell-plugin ./plugins/hls-pragmas-plugin ./plugins/hls-module-name-plugin + ./plugins/hls-ormolu-plugin tests: true package * diff --git a/nix/default.nix b/nix/default.nix index 8d4ea6eb13..24a1b3c1ac 100644 --- a/nix/default.nix +++ b/nix/default.nix @@ -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; diff --git a/plugins/hls-ormolu-plugin/LICENSE b/plugins/hls-ormolu-plugin/LICENSE new file mode 100644 index 0000000000..16502c47e2 --- /dev/null +++ b/plugins/hls-ormolu-plugin/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright 2021 The Haskell IDE team + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/plugins/hls-ormolu-plugin/hls-ormolu-plugin.cabal b/plugins/hls-ormolu-plugin/hls-ormolu-plugin.cabal new file mode 100644 index 0000000000..35c9e67b9d --- /dev/null +++ b/plugins/hls-ormolu-plugin/hls-ormolu-plugin.cabal @@ -0,0 +1,47 @@ +cabal-version: 2.4 +name: hls-ormolu-plugin +version: 1.0.0.0 +synopsis: Integration with the Ormolu code formatter +description: + Please see the README on GitHub at + +license: Apache-2.0 +license-file: LICENSE +author: The Haskell IDE Team +copyright: The Haskell IDE Team +maintainer: alan.zimm@gmail.com +category: Development +build-type: Simple +extra-source-files: + LICENSE + test/testdata/**/*.hs + +library + exposed-modules: Ide.Plugin.Ormolu + hs-source-dirs: src + build-depends: + , base >=4.12 && <5 + , filepath + , ghc + , ghc-boot-th + , ghcide >=1.2 && <1.4 + , hls-plugin-api ^>=1.1 + , lens + , lsp + , ormolu ^>=0.1.2 + , text + + default-language: Haskell2010 + +test-suite tests + type: exitcode-stdio-1.0 + default-language: Haskell2010 + hs-source-dirs: test + main-is: Main.hs + ghc-options: -threaded -rtsopts -with-rtsopts=-N + build-depends: + , base + , filepath + , hls-ormolu-plugin + , hls-test-utils ^>=1.0 + , lsp-types diff --git a/plugins/default/src/Ide/Plugin/Ormolu.hs b/plugins/hls-ormolu-plugin/src/Ide/Plugin/Ormolu.hs similarity index 59% rename from plugins/default/src/Ide/Plugin/Ormolu.hs rename to plugins/hls-ormolu-plugin/src/Ide/Plugin/Ormolu.hs index d58503c2d2..6e4ae91c7c 100644 --- a/plugins/default/src/Ide/Plugin/Ormolu.hs +++ b/plugins/hls-ormolu-plugin/src/Ide/Plugin/Ormolu.hs @@ -1,22 +1,20 @@ -{-# LANGUAGE OverloadedStrings #-} -{-# LANGUAGE PackageImports #-} -{-# LANGUAGE ScopedTypeVariables #-} -{-# LANGUAGE TypeApplications #-} +{-# LANGUAGE OverloadedStrings #-} +{-# LANGUAGE PackageImports #-} +{-# LANGUAGE TypeApplications #-} module Ide.Plugin.Ormolu - ( - descriptor + ( descriptor , provider ) where -import Control.Exception -import Control.Monad.IO.Class +import Control.Exception (try) +import Control.Monad.IO.Class (liftIO) import qualified Data.Text as T import Development.IDE hiding (pluginHandlers) +import Development.IDE.GHC.Compat (moduleNameString) import qualified DynFlags as D import qualified EnumSet as S -import GHC import GHC.LanguageExtensions.Type import GhcPlugins (HscEnv (hsc_dflags)) import Ide.PluginUtils @@ -25,7 +23,6 @@ import Language.LSP.Server hiding (defaultConfig) import Language.LSP.Types import "ormolu" Ormolu import System.FilePath (takeFileName) -import Text.Regex.TDFA.Text () -- --------------------------------------------------------------------- @@ -38,42 +35,41 @@ descriptor plId = (defaultPluginDescriptor plId) provider :: FormattingHandler IdeState provider ideState typ contents fp _ = withIndefiniteProgress title Cancellable $ liftIO $ do - let - fromDyn :: DynFlags -> IO [DynOption] - fromDyn df = - let - pp = - let p = D.sPgm_F $ D.settings df - in ["-pgmF=" <> p | not (null p)] - pm = map (("-fplugin=" <>) . moduleNameString) $ D.pluginModNames df - ex = map showExtension $ S.toList $ D.extensionFlags df - in - return $ map DynOption $ pp <> pm <> ex - ghc <- runAction "Ormolu" ideState $ use GhcSession fp let df = hsc_dflags . hscEnv <$> ghc fileOpts <- case df of - Nothing -> return [] - Just df -> fromDyn df + Nothing -> pure [] + Just df -> pure $ fromDyn df let fullRegion = RegionIndices Nothing Nothing rangeRegion s e = RegionIndices (Just $ s + 1) (Just $ e + 1) - mkConf o region = defaultConfig { cfgDynOptions = o, cfgRegion = region } + mkConf o region = defaultConfig { cfgDynOptions = o, cfgRegion = region } fmt :: T.Text -> Config RegionIndices -> IO (Either OrmoluException T.Text) fmt cont conf = - try @OrmoluException (ormolu conf (fromNormalizedFilePath fp) $ T.unpack cont) + try @OrmoluException $ ormolu conf (fromNormalizedFilePath fp) $ T.unpack cont case typ of FormatText -> ret <$> fmt contents (mkConf fileOpts fullRegion) FormatRange (Range (Position sl _) (Position el _)) -> ret <$> fmt contents (mkConf fileOpts (rangeRegion sl el)) where - title = T.pack $ "Formatting " <> takeFileName (fromNormalizedFilePath fp) - ret :: Either OrmoluException T.Text -> Either ResponseError (List TextEdit) - ret (Left err) = Left - (responseError (T.pack $ "ormoluCmd: " ++ show err) ) - ret (Right new) = Right (makeDiffTextEdit contents new) + title = T.pack $ "Formatting " <> takeFileName (fromNormalizedFilePath fp) + + ret :: Either OrmoluException T.Text -> Either ResponseError (List TextEdit) + ret (Left err) = Left . responseError . T.pack $ "ormoluCmd: " ++ show err + ret (Right new) = Right $ makeDiffTextEdit contents new + + fromDyn :: D.DynFlags -> [DynOption] + fromDyn df = + let + pp = + let p = D.sPgm_F $ D.settings df + in ["-pgmF=" <> p | not (null p)] + pm = ("-fplugin=" <>) . moduleNameString <$> D.pluginModNames df + ex = showExtension <$> S.toList (D.extensionFlags df) + in + DynOption <$> pp <> pm <> ex showExtension :: Extension -> String showExtension Cpp = "-XCPP" diff --git a/plugins/hls-ormolu-plugin/test/Main.hs b/plugins/hls-ormolu-plugin/test/Main.hs new file mode 100644 index 0000000000..ffb34f3f63 --- /dev/null +++ b/plugins/hls-ormolu-plugin/test/Main.hs @@ -0,0 +1,29 @@ +{-# LANGUAGE OverloadedStrings #-} +module Main + ( main + ) where + +import qualified Ide.Plugin.Ormolu as Ormolu +import Language.LSP.Types +import System.FilePath +import Test.Hls + +main :: IO () +main = defaultTestRunner tests + +ormoluPlugin :: PluginDescriptor IdeState +ormoluPlugin = Ormolu.descriptor "ormolu" + +tests :: TestTree +tests = testGroup "ormolu" + [ goldenWithOrmolu "formats correctly" "Ormolu" "formatted" $ \doc -> do + formatDoc doc (FormattingOptions 4 True Nothing Nothing Nothing) + , goldenWithOrmolu "formats imports correctly" "Ormolu2" "formatted" $ \doc -> do + formatDoc doc (FormattingOptions 4 True Nothing Nothing Nothing) + ] + +goldenWithOrmolu :: TestName -> FilePath -> FilePath -> (TextDocumentIdentifier -> Session ()) -> TestTree +goldenWithOrmolu title path desc = goldenWithHaskellDoc ormoluPlugin title testDataDir path desc "hs" + +testDataDir :: FilePath +testDataDir = "test" "testdata" diff --git a/plugins/hls-ormolu-plugin/test/testdata/Ormolu.expected.hs b/plugins/hls-ormolu-plugin/test/testdata/Ormolu.expected.hs new file mode 100644 index 0000000000..c986937b74 --- /dev/null +++ b/plugins/hls-ormolu-plugin/test/testdata/Ormolu.expected.hs @@ -0,0 +1,16 @@ +module Ormolu where + +import Data.Int +import Data.List +import Prelude + +foo :: Int -> Int +foo 3 = 2 +foo x = x + +bar :: String -> IO String +bar s = do + x <- return "hello" + return "asdf" + +data Baz = Baz {a :: Int, b :: String} diff --git a/plugins/hls-ormolu-plugin/test/testdata/Ormolu.formatted.hs b/plugins/hls-ormolu-plugin/test/testdata/Ormolu.formatted.hs new file mode 100644 index 0000000000..c986937b74 --- /dev/null +++ b/plugins/hls-ormolu-plugin/test/testdata/Ormolu.formatted.hs @@ -0,0 +1,16 @@ +module Ormolu where + +import Data.Int +import Data.List +import Prelude + +foo :: Int -> Int +foo 3 = 2 +foo x = x + +bar :: String -> IO String +bar s = do + x <- return "hello" + return "asdf" + +data Baz = Baz {a :: Int, b :: String} diff --git a/plugins/hls-ormolu-plugin/test/testdata/Ormolu.hs b/plugins/hls-ormolu-plugin/test/testdata/Ormolu.hs new file mode 100644 index 0000000000..7a181537b8 --- /dev/null +++ b/plugins/hls-ormolu-plugin/test/testdata/Ormolu.hs @@ -0,0 +1,15 @@ +module Ormolu where +import Data.List + +import Prelude +import Data.Int +foo :: Int -> Int +foo 3 = 2 +foo x = x +bar :: String -> IO String +bar s = do + x <- return "hello" + return "asdf" + +data Baz = Baz { a :: Int, b :: String } + diff --git a/test/testdata/format/Format2.ormolu.formatted.hs b/plugins/hls-ormolu-plugin/test/testdata/Ormolu2.expected.hs similarity index 100% rename from test/testdata/format/Format2.ormolu.formatted.hs rename to plugins/hls-ormolu-plugin/test/testdata/Ormolu2.expected.hs diff --git a/plugins/hls-ormolu-plugin/test/testdata/Ormolu2.formatted.hs b/plugins/hls-ormolu-plugin/test/testdata/Ormolu2.formatted.hs new file mode 100644 index 0000000000..b3d867e700 --- /dev/null +++ b/plugins/hls-ormolu-plugin/test/testdata/Ormolu2.formatted.hs @@ -0,0 +1,5 @@ +import Data.Bool +import Data.Char +import Data.Data +import Data.Either +import Data.Int diff --git a/test/testdata/format/Format2.hs b/plugins/hls-ormolu-plugin/test/testdata/Ormolu2.hs similarity index 100% rename from test/testdata/format/Format2.hs rename to plugins/hls-ormolu-plugin/test/testdata/Ormolu2.hs diff --git a/plugins/hls-ormolu-plugin/test/testdata/hie.yaml b/plugins/hls-ormolu-plugin/test/testdata/hie.yaml new file mode 100644 index 0000000000..47db6b9bc8 --- /dev/null +++ b/plugins/hls-ormolu-plugin/test/testdata/hie.yaml @@ -0,0 +1,2 @@ +cradle: + direct: diff --git a/stack-8.10.2.yaml b/stack-8.10.2.yaml index c1bcb4d3d6..11ecef541c 100644 --- a/stack-8.10.2.yaml +++ b/stack-8.10.2.yaml @@ -23,6 +23,7 @@ packages: - ./plugins/hls-fourmolu-plugin - ./plugins/hls-pragmas-plugin - ./plugins/hls-module-name-plugin + - ./plugins/hls-ormolu-plugin ghc-options: "$everything": -haddock diff --git a/stack-8.10.3.yaml b/stack-8.10.3.yaml index 85f4cc1db6..0d4aa1062a 100644 --- a/stack-8.10.3.yaml +++ b/stack-8.10.3.yaml @@ -23,6 +23,7 @@ packages: - ./plugins/hls-fourmolu-plugin - ./plugins/hls-pragmas-plugin - ./plugins/hls-module-name-plugin + - ./plugins/hls-ormolu-plugin ghc-options: "$everything": -haddock diff --git a/stack-8.10.4.yaml b/stack-8.10.4.yaml index ee9e751dab..c67e9fdd5c 100644 --- a/stack-8.10.4.yaml +++ b/stack-8.10.4.yaml @@ -23,6 +23,7 @@ packages: - ./plugins/hls-fourmolu-plugin - ./plugins/hls-pragmas-plugin - ./plugins/hls-module-name-plugin + - ./plugins/hls-ormolu-plugin ghc-options: "$everything": -haddock diff --git a/stack-8.6.4.yaml b/stack-8.6.4.yaml index 7692d36aa8..edcc949a22 100644 --- a/stack-8.6.4.yaml +++ b/stack-8.6.4.yaml @@ -24,6 +24,7 @@ packages: - ./plugins/hls-fourmolu-plugin - ./plugins/hls-pragmas-plugin - ./plugins/hls-module-name-plugin + - ./plugins/hls-ormolu-plugin ghc-options: "$everything": -haddock diff --git a/stack-8.6.5.yaml b/stack-8.6.5.yaml index 9d5459ff15..76ddf9f51d 100644 --- a/stack-8.6.5.yaml +++ b/stack-8.6.5.yaml @@ -23,6 +23,7 @@ packages: - ./plugins/hls-fourmolu-plugin - ./plugins/hls-pragmas-plugin - ./plugins/hls-module-name-plugin + - ./plugins/hls-ormolu-plugin ghc-options: "$everything": -haddock diff --git a/stack-8.8.2.yaml b/stack-8.8.2.yaml index 325fb78c7d..1375078dff 100644 --- a/stack-8.8.2.yaml +++ b/stack-8.8.2.yaml @@ -23,6 +23,7 @@ packages: - ./plugins/hls-fourmolu-plugin - ./plugins/hls-pragmas-plugin - ./plugins/hls-module-name-plugin + - ./plugins/hls-ormolu-plugin ghc-options: "$everything": -haddock diff --git a/stack-8.8.3.yaml b/stack-8.8.3.yaml index 906df8fb8d..1bfeb571bb 100644 --- a/stack-8.8.3.yaml +++ b/stack-8.8.3.yaml @@ -23,6 +23,7 @@ packages: - ./plugins/hls-fourmolu-plugin - ./plugins/hls-pragmas-plugin - ./plugins/hls-module-name-plugin + - ./plugins/hls-ormolu-plugin ghc-options: "$everything": -haddock diff --git a/stack-8.8.4.yaml b/stack-8.8.4.yaml index 33b8ff6da6..3a65dd34fa 100644 --- a/stack-8.8.4.yaml +++ b/stack-8.8.4.yaml @@ -23,6 +23,7 @@ packages: - ./plugins/hls-fourmolu-plugin - ./plugins/hls-pragmas-plugin - ./plugins/hls-module-name-plugin + - ./plugins/hls-ormolu-plugin ghc-options: "$everything": -haddock diff --git a/stack.yaml b/stack.yaml index 24f4b22f1f..ef3871c091 100644 --- a/stack.yaml +++ b/stack.yaml @@ -23,6 +23,7 @@ packages: - ./plugins/hls-fourmolu-plugin - ./plugins/hls-pragmas-plugin - ./plugins/hls-module-name-plugin + - ./plugins/hls-ormolu-plugin ghc-options: "$everything": -haddock diff --git a/test/functional/Format.hs b/test/functional/Format.hs index 39a6f0c093..a579ed9a17 100644 --- a/test/functional/Format.hs +++ b/test/functional/Format.hs @@ -26,7 +26,6 @@ tests = testGroup "format document" [ BS.fromStrict . T.encodeUtf8 <$> documentContents doc , rangeTests , providerTests - , ormoluTests ] rangeTests :: TestTree @@ -81,22 +80,6 @@ providerTests = testGroup "formatting provider" [ documentContents doc >>= liftIO . (@?= formattedFloskell) ] - -ormoluTests :: TestTree -ormoluTests = testGroup "ormolu" - [ goldenGitDiff "formats correctly" "test/testdata/format/Format.ormolu.formatted.hs" $ runSession hlsCommand fullCaps "test/testdata/format" $ do - sendNotification SWorkspaceDidChangeConfiguration (DidChangeConfigurationParams (formatLspConfig "ormolu")) - doc <- openDoc "Format.hs" "haskell" - formatDoc doc (FormattingOptions 2 True Nothing Nothing Nothing) - BS.fromStrict . T.encodeUtf8 <$> documentContents doc - , goldenGitDiff "formats imports correctly" "test/testdata/format/Format2.ormolu.formatted.hs" $ runSession hlsCommand fullCaps "test/testdata/format" $ do - sendNotification SWorkspaceDidChangeConfiguration (DidChangeConfigurationParams (formatLspConfig "ormolu")) - doc <- openDoc "Format2.hs" "haskell" - formatDoc doc (FormattingOptions 2 True Nothing Nothing Nothing) - BS.fromStrict . T.encodeUtf8 <$> documentContents doc - ] - - formatLspConfig :: Value -> Value formatLspConfig provider = object [ "haskell" .= object ["formattingProvider" .= (provider :: Value)] ] From 9f014e286d01944678e8f1dbd3571a0da2c6725e Mon Sep 17 00:00:00 2001 From: Junyoung/Clare Jang Date: Sat, 15 May 2021 23:10:30 -0400 Subject: [PATCH 04/20] Clean up brittany plugin --- .../hls-brittany-plugin.cabal | 3 +- .../src/Ide/Plugin/Brittany.hs | 3 +- plugins/hls-brittany-plugin/test/Main.hs | 58 +++++++++---------- .../test/testdata/hie.yaml | 2 + 4 files changed, 32 insertions(+), 34 deletions(-) create mode 100644 plugins/hls-brittany-plugin/test/testdata/hie.yaml diff --git a/plugins/hls-brittany-plugin/hls-brittany-plugin.cabal b/plugins/hls-brittany-plugin/hls-brittany-plugin.cabal index 4a0bbd0c29..a2523a7b24 100644 --- a/plugins/hls-brittany-plugin/hls-brittany-plugin.cabal +++ b/plugins/hls-brittany-plugin/hls-brittany-plugin.cabal @@ -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 diff --git a/plugins/hls-brittany-plugin/src/Ide/Plugin/Brittany.hs b/plugins/hls-brittany-plugin/src/Ide/Plugin/Brittany.hs index ff90bfecda..8f6e4e193f 100644 --- a/plugins/hls-brittany-plugin/src/Ide/Plugin/Brittany.hs +++ b/plugins/hls-brittany-plugin/src/Ide/Plugin/Brittany.hs @@ -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) @@ -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) diff --git a/plugins/hls-brittany-plugin/test/Main.hs b/plugins/hls-brittany-plugin/test/Main.hs index 4f8f185328..258532442d 100644 --- a/plugins/hls-brittany-plugin/test/Main.hs +++ b/plugins/hls-brittany-plugin/test/Main.hs @@ -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 = goldenWithHaskellDoc brittanyPlugin title testDataDir path desc "hs" + +testDataDir :: FilePath +testDataDir = "test" "testdata" diff --git a/plugins/hls-brittany-plugin/test/testdata/hie.yaml b/plugins/hls-brittany-plugin/test/testdata/hie.yaml new file mode 100644 index 0000000000..47db6b9bc8 --- /dev/null +++ b/plugins/hls-brittany-plugin/test/testdata/hie.yaml @@ -0,0 +1,2 @@ +cradle: + direct: From 13ed087054d1e12abeba0875c687c05e151300ae Mon Sep 17 00:00:00 2001 From: Junyoung/Clare Jang Date: Sat, 15 May 2021 23:28:59 -0400 Subject: [PATCH 05/20] Clean up class plugin --- .../hls-class-plugin/hls-class-plugin.cabal | 12 ++-- .../hls-class-plugin/src/Ide/Plugin/Class.hs | 3 +- plugins/hls-class-plugin/test/Main.hs | 66 ++++++++----------- .../hls-class-plugin/test/testdata/hie.yaml | 2 + 4 files changed, 33 insertions(+), 50 deletions(-) create mode 100644 plugins/hls-class-plugin/test/testdata/hie.yaml diff --git a/plugins/hls-class-plugin/hls-class-plugin.cabal b/plugins/hls-class-plugin/hls-class-plugin.cabal index 2ddc47c513..96b4146dcb 100644 --- a/plugins/hls-class-plugin/hls-class-plugin.cabal +++ b/plugins/hls-class-plugin/hls-class-plugin.cabal @@ -25,17 +25,16 @@ library hs-source-dirs: src build-depends: , aeson - , base >=4.12 && <5 + , base >=4.12 && <5 , containers , ghc , ghc-exactprint - , ghcide >=1.2 && <1.4 - , hls-plugin-api ^>=1.1 + , ghcide >=1.2 && <1.4 + , hls-plugin-api ^>=1.1 , lens , lsp , text , transformers - , unordered-containers default-language: Haskell2010 default-extensions: @@ -52,11 +51,8 @@ test-suite tests ghc-options: -threaded -rtsopts -with-rtsopts=-N build-depends: , base - , bytestring , filepath , hls-class-plugin - , hls-test-utils ^>= 1.0 + , hls-test-utils ^>=1.0 , lens - , lsp-test , lsp-types - , text diff --git a/plugins/hls-class-plugin/src/Ide/Plugin/Class.hs b/plugins/hls-class-plugin/src/Ide/Plugin/Class.hs index 90f45851fe..6ec932e4a5 100644 --- a/plugins/hls-class-plugin/src/Ide/Plugin/Class.hs +++ b/plugins/hls-class-plugin/src/Ide/Plugin/Class.hs @@ -25,7 +25,7 @@ import qualified Data.Text as T import Development.IDE hiding (pluginHandlers) import Development.IDE.Core.PositionMapping (fromCurrentRange, toCurrentRange) -import Development.IDE.GHC.Compat hiding (getLoc) +import Development.IDE.GHC.Compat import Development.IDE.Spans.AtPoint import qualified GHC.Generics as Generics import GhcPlugins hiding (Var, getLoc, @@ -38,7 +38,6 @@ import Language.Haskell.GHC.ExactPrint.Types hiding (GhcPs, Parens) import Language.LSP.Server import Language.LSP.Types import qualified Language.LSP.Types.Lens as J -import SrcLoc import TcEnv import TcRnMonad diff --git a/plugins/hls-class-plugin/test/Main.hs b/plugins/hls-class-plugin/test/Main.hs index 140a540045..9a69255030 100644 --- a/plugins/hls-class-plugin/test/Main.hs +++ b/plugins/hls-class-plugin/test/Main.hs @@ -1,15 +1,14 @@ -{-# LANGUAGE LambdaCase #-} -{-# LANGUAGE OverloadedStrings #-} -{-# LANGUAGE ScopedTypeVariables #-} -{-# LANGUAGE TypeOperators #-} +{-# LANGUAGE LambdaCase #-} +{-# LANGUAGE OverloadedStrings #-} +{-# LANGUAGE TypeOperators #-} + +{-# OPTIONS_GHC -Wall #-} module Main ( main - ) -where + ) where -import Control.Lens hiding ((<.>)) -import qualified Data.ByteString.Lazy as BS -import qualified Data.Text.Encoding as T +import Control.Lens (Prism', prism', (^..), (^?)) +import Control.Monad (void) import qualified Ide.Plugin.Class as Class import qualified Language.LSP.Types.Lens as J import System.FilePath @@ -18,14 +17,14 @@ import Test.Hls main :: IO () main = defaultTestRunner tests -plugin :: PluginDescriptor IdeState -plugin = Class.descriptor "class" +classPlugin :: PluginDescriptor IdeState +classPlugin = Class.descriptor "class" tests :: TestTree tests = testGroup "class" [ testCase "Produces addMinimalMethodPlaceholders code actions for one instance" $ do - runSessionWithServer plugin classPath $ do + runSessionWithServer classPlugin testDataDir $ do doc <- openDoc "T1.hs" "haskell" _ <- waitForDiagnosticsFromSource doc "typecheck" caResults <- getAllCodeActions doc @@ -34,23 +33,17 @@ tests = testGroup [ Just "Add placeholders for '=='" , Just "Add placeholders for '/='" ] - , glodenTest "Creates a placeholder for '=='" "T1" "eq" - $ \(eqAction:_) -> do + , goldenWithClass "Creates a placeholder for '=='" "T1" "eq" $ \(eqAction:_) -> do executeCodeAction eqAction - , glodenTest "Creates a placeholder for '/='" "T1" "ne" - $ \(_:neAction:_) -> do + , goldenWithClass "Creates a placeholder for '/='" "T1" "ne" $ \(_:neAction:_) -> do executeCodeAction neAction - , glodenTest "Creates a placeholder for 'fmap'" "T2" "fmap" - $ \(_:_:fmapAction:_) -> do + , goldenWithClass "Creates a placeholder for 'fmap'" "T2" "fmap" $ \(_:_:fmapAction:_) -> do executeCodeAction fmapAction - , glodenTest "Creates a placeholder for multiple methods 1" "T3" "1" - $ \(mmAction:_) -> do + , goldenWithClass "Creates a placeholder for multiple methods 1" "T3" "1" $ \(mmAction:_) -> do executeCodeAction mmAction - , glodenTest "Creates a placeholder for multiple methods 2" "T3" "2" - $ \(_:mmAction:_) -> do + , goldenWithClass "Creates a placeholder for multiple methods 2" "T3" "2" $ \(_:mmAction:_) -> do executeCodeAction mmAction - , glodenTest "Creates a placeholder for a method starting with '_'" "T4" "" - $ \(_fAction:_) -> do + , goldenWithClass "Creates a placeholder for a method starting with '_'" "T4" "" $ \(_fAction:_) -> do executeCodeAction _fAction ] @@ -59,20 +52,13 @@ _CACodeAction = prism' InR $ \case InR action -> Just action _ -> Nothing -classPath :: FilePath -classPath = "test" "testdata" +goldenWithClass :: TestName -> FilePath -> FilePath -> ([CodeAction] -> Session ()) -> TestTree +goldenWithClass title path desc act = + goldenWithHaskellDoc classPlugin title testDataDir path (desc <.> "expected") "hs" $ \doc -> do + _ <- waitForDiagnosticsFromSource doc "typecheck" + actions <- concatMap (^.. _CACodeAction) <$> getAllCodeActions doc + act actions + void $ skipManyTill anyMessage (getDocumentEdit doc) -glodenTest :: String -> FilePath -> FilePath -> ([CodeAction] -> Session ()) -> TestTree -glodenTest name fp deco execute - = goldenGitDiff name (classPath fpWithDeco <.> "expected" <.> "hs") - $ runSessionWithServer plugin classPath - $ do - doc <- openDoc (fp <.> "hs") "haskell" - _ <- waitForDiagnosticsFromSource doc "typecheck" - actions <- concatMap (^.. _CACodeAction) <$> getAllCodeActions doc - execute actions - BS.fromStrict . T.encodeUtf8 <$> skipManyTill anyMessage (getDocumentEdit doc) - where - fpWithDeco - | deco == "" = fp - | otherwise = fp <.> deco +testDataDir :: FilePath +testDataDir = "test" "testdata" diff --git a/plugins/hls-class-plugin/test/testdata/hie.yaml b/plugins/hls-class-plugin/test/testdata/hie.yaml new file mode 100644 index 0000000000..47db6b9bc8 --- /dev/null +++ b/plugins/hls-class-plugin/test/testdata/hie.yaml @@ -0,0 +1,2 @@ +cradle: + direct: From 8025095cb712f5e60745647d19e4f02974c1ad75 Mon Sep 17 00:00:00 2001 From: Junyoung/Clare Jang Date: Sat, 15 May 2021 23:54:27 -0400 Subject: [PATCH 06/20] Clean up eval plugin --- plugins/hls-eval-plugin/hls-eval-plugin.cabal | 8 +- plugins/hls-eval-plugin/test/Main.hs | 294 +++++++----------- .../{T1.hs.expected => T1.expected.hs} | 0 .../{T10.hs.expected => T10.expected.hs} | 0 .../{T11.hs.expected => T11.expected.hs} | 0 .../{T12.hs.expected => T12.expected.hs} | 0 .../{T13.hs.expected => T13.expected.hs} | 0 .../{T14.hs.expected => T14.expected.hs} | 0 .../{T15.hs.expected => T15.expected.hs} | 0 .../{T16.hs.expected => T16.expected.hs} | 0 .../{T17.hs.expected => T17.expected.hs} | 0 .../{T18.hs.expected => T18.expected.hs} | 0 .../{T19.hs.expected => T19.expected.hs} | 0 .../{T2.hs.expected => T2.expected.hs} | 0 .../{T20.hs.expected => T20.expected.hs} | 0 .../{T21.hs.expected => T21.expected.hs} | 0 .../{T22.hs.expected => T22.expected.hs} | 0 .../{T23.hs.expected => T23.expected.hs} | 0 .../{T24.hs.expected => T24.expected.hs} | 0 .../{T25.hs.expected => T25.expected.hs} | 0 .../{T26.hs.expected => T26.expected.hs} | 0 .../{T27.hs.expected => T27.expected.hs} | 0 .../{T3.hs.expected => T3.expected.hs} | 0 .../{T4.hs.expected => T4.expected.hs} | 0 .../{T5.hs.expected => T5.expected.hs} | 0 .../{T6.hs.expected => T6.expected.hs} | 0 .../{T7.hs.expected => T7.expected.hs} | 0 .../{T8.hs.expected => T8.expected.hs} | 0 .../{T9.hs.expected => T9.expected.hs} | 0 .../{TCPP.hs.expected => TCPP.expected.hs} | 0 ...mpare.hs.expected => TCompare.expected.hs} | 0 ...i.hs.expected => TEndingMulti.expected.hs} | 0 ...{TFlags.hs.expected => TFlags.expected.hs} | 0 ...ddock.hs.expected => THaddock.expected.hs} | 0 .../{TIO.hs.expected => TIO.expected.hs} | 0 .../{TIt.hs.expected => TIt.expected.hs} | 0 .../{TLHS.lhs.expected => TLHS.expected.lhs} | 0 ...eX.lhs.expected => TLHSLateX.expected.lhs} | 0 ...TLanguageOptionsTupleSections.expected.hs} | 0 ...Line.hs.expected => TLastLine.expected.hs} | 0 ...t.hs.expected => TLocalImport.expected.hs} | 0 ...xpected => TLocalImportInTest.expected.hs} | 0 ...{TMulti.hs.expected => TMulti.expected.hs} | 0 ...Nested.hs.expected => TNested.expected.hs} | 0 ...xpected => TNoImplicitPrelude.expected.hs} | 0 ....hs.expected => TPlainComment.expected.hs} | 0 ...elude.hs.expected => TPrelude.expected.hs} | 0 ...erty.hs.expected => TProperty.expected.hs} | 0 ...l.hs.expected => TSectionEval.expected.hs} | 0 ...{TSetup.hs.expected => TSetup.expected.hs} | 0 ...UNPACK.hs.expected => TUNPACK.expected.hs} | 0 51 files changed, 110 insertions(+), 192 deletions(-) rename plugins/hls-eval-plugin/test/testdata/{T1.hs.expected => T1.expected.hs} (100%) rename plugins/hls-eval-plugin/test/testdata/{T10.hs.expected => T10.expected.hs} (100%) rename plugins/hls-eval-plugin/test/testdata/{T11.hs.expected => T11.expected.hs} (100%) rename plugins/hls-eval-plugin/test/testdata/{T12.hs.expected => T12.expected.hs} (100%) rename plugins/hls-eval-plugin/test/testdata/{T13.hs.expected => T13.expected.hs} (100%) rename plugins/hls-eval-plugin/test/testdata/{T14.hs.expected => T14.expected.hs} (100%) rename plugins/hls-eval-plugin/test/testdata/{T15.hs.expected => T15.expected.hs} (100%) rename plugins/hls-eval-plugin/test/testdata/{T16.hs.expected => T16.expected.hs} (100%) rename plugins/hls-eval-plugin/test/testdata/{T17.hs.expected => T17.expected.hs} (100%) rename plugins/hls-eval-plugin/test/testdata/{T18.hs.expected => T18.expected.hs} (100%) rename plugins/hls-eval-plugin/test/testdata/{T19.hs.expected => T19.expected.hs} (100%) rename plugins/hls-eval-plugin/test/testdata/{T2.hs.expected => T2.expected.hs} (100%) rename plugins/hls-eval-plugin/test/testdata/{T20.hs.expected => T20.expected.hs} (100%) rename plugins/hls-eval-plugin/test/testdata/{T21.hs.expected => T21.expected.hs} (100%) rename plugins/hls-eval-plugin/test/testdata/{T22.hs.expected => T22.expected.hs} (100%) rename plugins/hls-eval-plugin/test/testdata/{T23.hs.expected => T23.expected.hs} (100%) rename plugins/hls-eval-plugin/test/testdata/{T24.hs.expected => T24.expected.hs} (100%) rename plugins/hls-eval-plugin/test/testdata/{T25.hs.expected => T25.expected.hs} (100%) rename plugins/hls-eval-plugin/test/testdata/{T26.hs.expected => T26.expected.hs} (100%) rename plugins/hls-eval-plugin/test/testdata/{T27.hs.expected => T27.expected.hs} (100%) rename plugins/hls-eval-plugin/test/testdata/{T3.hs.expected => T3.expected.hs} (100%) rename plugins/hls-eval-plugin/test/testdata/{T4.hs.expected => T4.expected.hs} (100%) rename plugins/hls-eval-plugin/test/testdata/{T5.hs.expected => T5.expected.hs} (100%) rename plugins/hls-eval-plugin/test/testdata/{T6.hs.expected => T6.expected.hs} (100%) rename plugins/hls-eval-plugin/test/testdata/{T7.hs.expected => T7.expected.hs} (100%) rename plugins/hls-eval-plugin/test/testdata/{T8.hs.expected => T8.expected.hs} (100%) rename plugins/hls-eval-plugin/test/testdata/{T9.hs.expected => T9.expected.hs} (100%) rename plugins/hls-eval-plugin/test/testdata/{TCPP.hs.expected => TCPP.expected.hs} (100%) rename plugins/hls-eval-plugin/test/testdata/{TCompare.hs.expected => TCompare.expected.hs} (100%) rename plugins/hls-eval-plugin/test/testdata/{TEndingMulti.hs.expected => TEndingMulti.expected.hs} (100%) rename plugins/hls-eval-plugin/test/testdata/{TFlags.hs.expected => TFlags.expected.hs} (100%) rename plugins/hls-eval-plugin/test/testdata/{THaddock.hs.expected => THaddock.expected.hs} (100%) rename plugins/hls-eval-plugin/test/testdata/{TIO.hs.expected => TIO.expected.hs} (100%) rename plugins/hls-eval-plugin/test/testdata/{TIt.hs.expected => TIt.expected.hs} (100%) rename plugins/hls-eval-plugin/test/testdata/{TLHS.lhs.expected => TLHS.expected.lhs} (100%) rename plugins/hls-eval-plugin/test/testdata/{TLHSLateX.lhs.expected => TLHSLateX.expected.lhs} (100%) rename plugins/hls-eval-plugin/test/testdata/{TLanguageOptionsTupleSections.hs.expected => TLanguageOptionsTupleSections.expected.hs} (100%) rename plugins/hls-eval-plugin/test/testdata/{TLastLine.hs.expected => TLastLine.expected.hs} (100%) rename plugins/hls-eval-plugin/test/testdata/{TLocalImport.hs.expected => TLocalImport.expected.hs} (100%) rename plugins/hls-eval-plugin/test/testdata/{TLocalImportInTest.hs.expected => TLocalImportInTest.expected.hs} (100%) rename plugins/hls-eval-plugin/test/testdata/{TMulti.hs.expected => TMulti.expected.hs} (100%) rename plugins/hls-eval-plugin/test/testdata/{TNested.hs.expected => TNested.expected.hs} (100%) rename plugins/hls-eval-plugin/test/testdata/{TNoImplicitPrelude.hs.expected => TNoImplicitPrelude.expected.hs} (100%) rename plugins/hls-eval-plugin/test/testdata/{TPlainComment.hs.expected => TPlainComment.expected.hs} (100%) rename plugins/hls-eval-plugin/test/testdata/{TPrelude.hs.expected => TPrelude.expected.hs} (100%) rename plugins/hls-eval-plugin/test/testdata/{TProperty.hs.expected => TProperty.expected.hs} (100%) rename plugins/hls-eval-plugin/test/testdata/{TSectionEval.hs.expected => TSectionEval.expected.hs} (100%) rename plugins/hls-eval-plugin/test/testdata/{TSetup.hs.expected => TSetup.expected.hs} (100%) rename plugins/hls-eval-plugin/test/testdata/{TUNPACK.hs.expected => TUNPACK.expected.hs} (100%) diff --git a/plugins/hls-eval-plugin/hls-eval-plugin.cabal b/plugins/hls-eval-plugin/hls-eval-plugin.cabal index 7520d264d7..d8064b0390 100644 --- a/plugins/hls-eval-plugin/hls-eval-plugin.cabal +++ b/plugins/hls-eval-plugin/hls-eval-plugin.cabal @@ -20,10 +20,10 @@ extra-source-files: LICENSE README.md test/testdata/*.cabal - test/testdata/*.expected test/testdata/*.hs test/testdata/*.lhs test/testdata/*.yaml + test/testdata/cabal.project flag pedantic description: Enable -Werror @@ -50,7 +50,7 @@ library build-depends: , aeson - , base >=4.12 && <5 + , base >=4.12 && <5 , containers , deepseq , Diff ^>=0.4.0 @@ -61,7 +61,7 @@ library , ghc , ghc-boot-th , ghc-paths - , ghcide >=1.2 && <1.4 + , ghcide >=1.2 && <1.4 , hashable , hls-plugin-api ^>=1.1 , lens @@ -106,6 +106,4 @@ test-suite tests , hls-eval-plugin , hls-test-utils ^>=1.0 , lens - , lsp-test , lsp-types - , text diff --git a/plugins/hls-eval-plugin/test/Main.hs b/plugins/hls-eval-plugin/test/Main.hs index ae14832741..d5de5477b6 100644 --- a/plugins/hls-eval-plugin/test/Main.hs +++ b/plugins/hls-eval-plugin/test/Main.hs @@ -1,20 +1,16 @@ -{-# LANGUAGE DuplicateRecordFields #-} -{-# LANGUAGE OverloadedStrings #-} -{-# LANGUAGE RecordWildCards #-} -{-# LANGUAGE ScopedTypeVariables #-} -{-# LANGUAGE ViewPatterns #-} +{-# LANGUAGE OverloadedStrings #-} +{-# LANGUAGE RecordWildCards #-} +{-# LANGUAGE ViewPatterns #-} -module Main ( - main, -) where +module Main + ( main + ) where import Control.Lens (_Just, preview, view) import Control.Monad (when) import Data.Aeson (fromJSON) import Data.Aeson.Types (Result (Success)) import Data.List.Extra (nubOrdOn) -import qualified Data.Text as T -import qualified Data.Text.IO as T import qualified Ide.Plugin.Eval as Eval import Ide.Plugin.Eval.Types (EvalParams (..)) import Language.LSP.Types.Lens (command, range, title) @@ -30,189 +26,113 @@ evalPlugin = Eval.descriptor "eval" tests :: TestTree tests = - testGroup - "eval" - [ testCase "Produces Evaluate code lenses" $ - runSessionWithServer evalPlugin evalPath $ do - doc <- openDoc "T1.hs" "haskell" - lenses <- getEvalCodeLenses doc - liftIO $ map (preview $ command . _Just . title) lenses @?= [Just "Evaluate..."] - , testCase "Produces Refresh code lenses" $ - runSessionWithServer evalPlugin evalPath $ do - doc <- openDoc "T2.hs" "haskell" - lenses <- getEvalCodeLenses doc - liftIO $ map (preview $ command . _Just . title) lenses @?= [Just "Refresh..."] - , testCase "Code lenses have ranges" $ - runSessionWithServer evalPlugin evalPath $ do - doc <- openDoc "T1.hs" "haskell" - lenses <- getEvalCodeLenses doc - liftIO $ map (view range) lenses @?= [Range (Position 4 0) (Position 5 0)] - , testCase "Multi-line expressions have a multi-line range" $ do - runSessionWithServer evalPlugin evalPath $ do - doc <- openDoc "T3.hs" "haskell" - lenses <- getEvalCodeLenses doc - liftIO $ map (view range) lenses @?= [Range (Position 3 0) (Position 5 0)] - , testCase "Executed expressions range covers only the expression" $ do - runSessionWithServer evalPlugin evalPath $ do - doc <- openDoc "T2.hs" "haskell" - lenses <- getEvalCodeLenses doc - liftIO $ map (view range) lenses @?= [Range (Position 4 0) (Position 5 0)] - , testCase "Evaluation of expressions" $ goldenTest "T1.hs" - , testCase "Reevaluation of expressions" $ goldenTest "T2.hs" - , testCase "Evaluation of expressions w/ imports" $ goldenTest "T3.hs" - , testCase "Evaluation of expressions w/ lets" $ goldenTest "T4.hs" - , testCase "Refresh an evaluation" $ goldenTest "T5.hs" - , testCase "Refresh an evaluation w/ lets" $ goldenTest "T6.hs" - , testCase "Refresh a multiline evaluation" $ goldenTest "T7.hs" - , testCase "Semantic and Lexical errors are reported" $ goldenTest "T8.hs" - , testCase "Applies file LANGUAGE extensions" $ goldenTest "T9.hs" - , testCase "Evaluate a type with :kind!" $ goldenTest "T10.hs" - , testCase "Reports an error for an incorrect type with :kind!" $ - goldenTest "T11.hs" - , testCase "Shows a kind with :kind" $ goldenTest "T12.hs" - , testCase "Reports an error for an incorrect type with :kind" $ - goldenTest "T13.hs" - , testCase "Returns a fully-instantiated type for :type" $ - goldenTest "T14.hs" - , testCase "Returns an uninstantiated type for :type +v, admitting multiple whitespaces around arguments" $ - goldenTest "T15.hs" - , testCase "Returns defaulted type for :type +d, admitting multiple whitespaces around arguments" $ - goldenTest "T16.hs" - , testCase ":type reports an error when given with unknown +x option" $ - goldenTest "T17.hs" - , testCase "Reports an error when given with unknown command" $ - goldenTest "T18.hs" - , testCase "Returns defaulted type for :type +d reflecting the default declaration specified in the >>> prompt" $ - goldenTest "T19.hs" - , expectFailBecause "known issue - see a note in P.R. #361" $ - testCase ":type +d reflects the `default' declaration of the module" $ - goldenTest "T20.hs" - , testCase ":type handles a multilined result properly" $ - goldenTest "T21.hs" - , testCase ":t behaves exactly the same as :type" $ - goldenTest "T22.hs" - , testCase ":type does \"dovetails\" for short identifiers" $ - goldenTest "T23.hs" - , testCase ":kind! treats a multilined result properly" $ - goldenTest "T24.hs" - , testCase ":kind treats a multilined result properly" $ - goldenTest "T25.hs" - , testCase "local imports" $ - goldenTest "T26.hs" - , testCase "Preserves one empty comment line after prompt" $ - goldenTest "T27.hs" - , testCase - "Multi line comments" - $ goldenTest "TMulti.hs" - , testCase - "Multi line comments, with the last test line ends without newline" - $ goldenTest "TEndingMulti.hs" - , testCase - "Evaluate expressions in Plain comments in both single line and multi line format" - $ goldenTest "TPlainComment.hs" - , testCase - "Evaluate expressions in Haddock comments in both single line and multi line format" - $ goldenTest "THaddock.hs" - , testCase "Compare results (for Haddock tests only)" $ - goldenTest "TCompare.hs" - , testCase "Local Modules imports are accessible in a test" $ - goldenTest "TLocalImport.hs" - , -- , testCase "Local Modules can be imported in a test" $ goldenTest "TLocalImportInTest.hs" - expectFailBecause "Unexplained but minor issue" $ - testCase "Setting language option TupleSections" $ - goldenTest "TLanguageOptionsTupleSections.hs" - , testCase ":set accepts ghci flags" $ - goldenTest "TFlags.hs" - , testCase "IO expressions are supported, stdout/stderr output is ignored" $ - goldenTest "TIO.hs" - , testCase "Property checking" $ goldenTest "TProperty.hs" - , testCase - "Prelude has no special treatment, it is imported as stated in the module" - $ goldenTest "TPrelude.hs" - , testCase - "Don't panic on {-# UNPACK #-} pragma" - $ goldenTest "TUNPACK.hs" - , testCase - "Can handle eval inside nested comment properly" - $ goldenTest "TNested.hs" - , testCase "Test on last line insert results correctly" $ do - let mdl = "TLastLine.hs" - -- Write the test file, to make sure that it has no final line return - writeFile (evalPath mdl) "module TLastLine where\n\n-- >>> take 3 [1..]" - goldenTest mdl - , testGroup "with preprocessors" - [ knownBrokenInEnv [HostOS Windows, GhcVer GHC84, GhcVer GHC86] - "CPP eval on Windows and/or GHC <= 8.6 fails for some reasons" $ - testCase "CPP support" $ goldenTest "TCPP.hs" - , knownBrokenForGhcVersions [GHC84, GHC86] - "Preprocessor known to fail on GHC <= 8.6" - $ testCase "Literate Haskell Bird Style" $ goldenTest "TLHS.lhs" - -- , testCase "Literate Haskell LaTeX Style" $ goldenTest "TLHSLateX.lhs" - ] - , testCase "Works with NoImplicitPrelude" - $ goldenTest "TNoImplicitPrelude.hs" - , testCase "Variable 'it' works" - $ goldenTest "TIt.hs" - ] - -goldenTest :: FilePath -> IO () -goldenTest = goldenTestBy isEvalTest - -{- |Execute all CodeLens accepted by 'filter' - Compare results with the contents of corresponding '.expected' file (and creates it, if missing) --} -goldenTestBy :: (CodeLens -> Bool) -> FilePath -> IO () -goldenTestBy fltr input = runSessionWithServer evalPlugin evalPath $ do - doc <- openDoc input "haskell" - - -- Execute lenses backwards, to avoid affecting their position in the source file - codeLenses <- reverse <$> getCodeLensesBy fltr doc - -- liftIO $ print codeLenses - - -- Execute sequentially, nubbing elements to avoid - -- evaluating the same section with multiple tests - -- more than twice - mapM_ executeCmd - $ nubOrdOn actSectionId [c | CodeLens{_command = Just c} <- codeLenses] - - edited <- replaceUnicodeQuotes <$> documentContents doc - -- liftIO $ T.putStrLn edited - - let expectedFile = input <.> "expected" - - liftIO $ do - -- Write expected file if missing - missingExpected <- not <$> doesFileExist expectedFile - when missingExpected $ T.writeFile expectedFile edited - expected <- T.readFile expectedFile - edited @?= expected + testGroup "eval" + [ testCase "Produces Evaluate code lenses" $ + runSessionWithServer evalPlugin testDataDir $ do + doc <- openDoc "T1.hs" "haskell" + lenses <- getCodeLenses doc + liftIO $ map (preview $ command . _Just . title) lenses @?= [Just "Evaluate..."] + , testCase "Produces Refresh code lenses" $ + runSessionWithServer evalPlugin testDataDir $ do + doc <- openDoc "T2.hs" "haskell" + lenses <- getCodeLenses doc + liftIO $ map (preview $ command . _Just . title) lenses @?= [Just "Refresh..."] + , testCase "Code lenses have ranges" $ + runSessionWithServer evalPlugin testDataDir $ do + doc <- openDoc "T1.hs" "haskell" + lenses <- getCodeLenses doc + liftIO $ map (view range) lenses @?= [Range (Position 4 0) (Position 5 0)] + , testCase "Multi-line expressions have a multi-line range" $ do + runSessionWithServer evalPlugin testDataDir $ do + doc <- openDoc "T3.hs" "haskell" + lenses <- getCodeLenses doc + liftIO $ map (view range) lenses @?= [Range (Position 3 0) (Position 5 0)] + , testCase "Executed expressions range covers only the expression" $ do + runSessionWithServer evalPlugin testDataDir $ do + doc <- openDoc "T2.hs" "haskell" + lenses <- getCodeLenses doc + liftIO $ map (view range) lenses @?= [Range (Position 4 0) (Position 5 0)] + + , goldenWithEval "Evaluation of expressions" "T1" "hs" + , goldenWithEval "Reevaluation of expressions" "T2" "hs" + , goldenWithEval "Evaluation of expressions w/ imports" "T3" "hs" + , goldenWithEval "Evaluation of expressions w/ lets" "T4" "hs" + , goldenWithEval "Refresh an evaluation" "T5" "hs" + , goldenWithEval "Refresh an evaluation w/ lets" "T6" "hs" + , goldenWithEval "Refresh a multiline evaluation" "T7" "hs" + , goldenWithEval "Semantic and Lexical errors are reported" "T8" "hs" + , goldenWithEval "Applies file LANGUAGE extensions" "T9" "hs" + , goldenWithEval "Evaluate a type with :kind!" "T10" "hs" + , goldenWithEval "Reports an error for an incorrect type with :kind!" "T11" "hs" + , goldenWithEval "Shows a kind with :kind" "T12" "hs" + , goldenWithEval "Reports an error for an incorrect type with :kind" "T13" "hs" + , goldenWithEval "Returns a fully-instantiated type for :type" "T14" "hs" + , goldenWithEval "Returns an uninstantiated type for :type +v, admitting multiple whitespaces around arguments" "T15" "hs" + , goldenWithEval "Returns defaulted type for :type +d, admitting multiple whitespaces around arguments" "T16" "hs" + , goldenWithEval ":type reports an error when given with unknown +x option" "T17" "hs" + , goldenWithEval "Reports an error when given with unknown command" "T18" "hs" + , goldenWithEval "Returns defaulted type for :type +d reflecting the default declaration specified in the >>> prompt" "T19" "hs" + , expectFailBecause "known issue - see a note in P.R. #361" $ + goldenWithEval ":type +d reflects the `default' declaration of the module" "T20" "hs" + , goldenWithEval ":type handles a multilined result properly" "T21" "hs" + , goldenWithEval ":t behaves exactly the same as :type" "T22" "hs" + , goldenWithEval ":type does \"dovetails\" for short identifiers" "T23" "hs" + , goldenWithEval ":kind! treats a multilined result properly" "T24" "hs" + , goldenWithEval ":kind treats a multilined result properly" "T25" "hs" + , goldenWithEval "local imports" "T26" "hs" + , goldenWithEval "Preserves one empty comment line after prompt" "T27" "hs" + , goldenWithEval "Multi line comments" "TMulti" "hs" + , goldenWithEval "Multi line comments, with the last test line ends without newline" "TEndingMulti" "hs" + , goldenWithEval "Evaluate expressions in Plain comments in both single line and multi line format" "TPlainComment" "hs" + , goldenWithEval "Evaluate expressions in Haddock comments in both single line and multi line format" "THaddock" "hs" + , goldenWithEval "Compare results (for Haddock tests only)" "TCompare" "hs" + , goldenWithEval "Local Modules imports are accessible in a test" "TLocalImport" "hs" + , -- , goldenWithEval "Local Modules can be imported in a test" "TLocalImportInTest" "hs" + expectFailBecause "Unexplained but minor issue" $ + goldenWithEval "Setting language option TupleSections" "TLanguageOptionsTupleSections" "hs" + , goldenWithEval ":set accepts ghci flags" "TFlags" "hs" + , goldenWithEval "IO expressions are supported, stdout/stderr output is ignored" "TIO" "hs" + , goldenWithEval "Property checking" "TProperty" "hs" + , goldenWithEval "Prelude has no special treatment, it is imported as stated in the module" "TPrelude" "hs" + , goldenWithEval "Don't panic on {-# UNPACK #-} pragma" "TUNPACK" "hs" + , goldenWithEval "Can handle eval inside nested comment properly" "TNested" "hs" + , goldenWithEval "Test on last line insert results correctly" "TLastLine" "hs" + , testGroup "with preprocessors" + [ knownBrokenInEnv [HostOS Windows, GhcVer GHC84, GhcVer GHC86] + "CPP eval on Windows and/or GHC <= 8.6 fails for some reasons" $ + goldenWithEval "CPP support" "TCPP" "hs" + , knownBrokenForGhcVersions [GHC84, GHC86] + "Preprocessor known to fail on GHC <= 8.6" $ + goldenWithEval "Literate Haskell Bird Style" "TLHS" "lhs" + -- , goldenWithEval "Literate Haskell LaTeX Style" "TLHSLateX" "lhs" + ] + , goldenWithEval "Works with NoImplicitPrelude" "TNoImplicitPrelude" "hs" + , goldenWithEval "Variable 'it' works" "TIt" "hs" + ] + +goldenWithEval :: TestName -> FilePath -> FilePath -> TestTree +goldenWithEval title path ext = goldenWithHaskellDoc evalPlugin title testDataDir path "expected" ext $ \doc -> do + -- Execute lenses backwards, to avoid affecting their position in the source file + codeLenses <- reverse <$> getCodeLenses doc + -- liftIO $ print codeLenses + + -- Execute sequentially, nubbing elements to avoid + -- evaluating the same section with multiple tests + -- more than twice + mapM_ executeCmd $ + nubOrdOn actSectionId [c | CodeLens{_command = Just c} <- codeLenses] actSectionId :: Command -> Int actSectionId Command{_arguments = Just (List [fromJSON -> Success EvalParams{..}])} = evalId actSectionId _ = error "Invalid CodeLens" -getEvalCodeLenses :: TextDocumentIdentifier -> Session [CodeLens] -getEvalCodeLenses = getCodeLensesBy isEvalTest - -getCodeLensesBy :: (CodeLens -> Bool) -> TextDocumentIdentifier -> Session [CodeLens] -getCodeLensesBy f doc = filter f <$> getCodeLenses doc - -- Execute command and wait for result executeCmd :: Command -> Session () executeCmd cmd = do - executeCommand cmd - _resp <- skipManyTill anyMessage (message SWorkspaceApplyEdit) - -- liftIO $ print _resp - return () - --- Execute only Eval tests to avoid interference from other plugins (e.g ghcide:typesignature.add) -isEvalTest :: CodeLens -> Bool -isEvalTest (CodeLens _ (Just (Command _ cmd _)) _) - | ":eval:" `T.isInfixOf` cmd = True -isEvalTest _ = False - -replaceUnicodeQuotes :: T.Text -> T.Text -replaceUnicodeQuotes = T.replace "‘" "'" . T.replace "’" "'" + executeCommand cmd + _ <- skipManyTill anyMessage (message SWorkspaceApplyEdit) + -- liftIO $ print _resp + pure () -evalPath :: FilePath -evalPath = "test" "testdata" +testDataDir :: FilePath +testDataDir = "test" "testdata" diff --git a/plugins/hls-eval-plugin/test/testdata/T1.hs.expected b/plugins/hls-eval-plugin/test/testdata/T1.expected.hs similarity index 100% rename from plugins/hls-eval-plugin/test/testdata/T1.hs.expected rename to plugins/hls-eval-plugin/test/testdata/T1.expected.hs diff --git a/plugins/hls-eval-plugin/test/testdata/T10.hs.expected b/plugins/hls-eval-plugin/test/testdata/T10.expected.hs similarity index 100% rename from plugins/hls-eval-plugin/test/testdata/T10.hs.expected rename to plugins/hls-eval-plugin/test/testdata/T10.expected.hs diff --git a/plugins/hls-eval-plugin/test/testdata/T11.hs.expected b/plugins/hls-eval-plugin/test/testdata/T11.expected.hs similarity index 100% rename from plugins/hls-eval-plugin/test/testdata/T11.hs.expected rename to plugins/hls-eval-plugin/test/testdata/T11.expected.hs diff --git a/plugins/hls-eval-plugin/test/testdata/T12.hs.expected b/plugins/hls-eval-plugin/test/testdata/T12.expected.hs similarity index 100% rename from plugins/hls-eval-plugin/test/testdata/T12.hs.expected rename to plugins/hls-eval-plugin/test/testdata/T12.expected.hs diff --git a/plugins/hls-eval-plugin/test/testdata/T13.hs.expected b/plugins/hls-eval-plugin/test/testdata/T13.expected.hs similarity index 100% rename from plugins/hls-eval-plugin/test/testdata/T13.hs.expected rename to plugins/hls-eval-plugin/test/testdata/T13.expected.hs diff --git a/plugins/hls-eval-plugin/test/testdata/T14.hs.expected b/plugins/hls-eval-plugin/test/testdata/T14.expected.hs similarity index 100% rename from plugins/hls-eval-plugin/test/testdata/T14.hs.expected rename to plugins/hls-eval-plugin/test/testdata/T14.expected.hs diff --git a/plugins/hls-eval-plugin/test/testdata/T15.hs.expected b/plugins/hls-eval-plugin/test/testdata/T15.expected.hs similarity index 100% rename from plugins/hls-eval-plugin/test/testdata/T15.hs.expected rename to plugins/hls-eval-plugin/test/testdata/T15.expected.hs diff --git a/plugins/hls-eval-plugin/test/testdata/T16.hs.expected b/plugins/hls-eval-plugin/test/testdata/T16.expected.hs similarity index 100% rename from plugins/hls-eval-plugin/test/testdata/T16.hs.expected rename to plugins/hls-eval-plugin/test/testdata/T16.expected.hs diff --git a/plugins/hls-eval-plugin/test/testdata/T17.hs.expected b/plugins/hls-eval-plugin/test/testdata/T17.expected.hs similarity index 100% rename from plugins/hls-eval-plugin/test/testdata/T17.hs.expected rename to plugins/hls-eval-plugin/test/testdata/T17.expected.hs diff --git a/plugins/hls-eval-plugin/test/testdata/T18.hs.expected b/plugins/hls-eval-plugin/test/testdata/T18.expected.hs similarity index 100% rename from plugins/hls-eval-plugin/test/testdata/T18.hs.expected rename to plugins/hls-eval-plugin/test/testdata/T18.expected.hs diff --git a/plugins/hls-eval-plugin/test/testdata/T19.hs.expected b/plugins/hls-eval-plugin/test/testdata/T19.expected.hs similarity index 100% rename from plugins/hls-eval-plugin/test/testdata/T19.hs.expected rename to plugins/hls-eval-plugin/test/testdata/T19.expected.hs diff --git a/plugins/hls-eval-plugin/test/testdata/T2.hs.expected b/plugins/hls-eval-plugin/test/testdata/T2.expected.hs similarity index 100% rename from plugins/hls-eval-plugin/test/testdata/T2.hs.expected rename to plugins/hls-eval-plugin/test/testdata/T2.expected.hs diff --git a/plugins/hls-eval-plugin/test/testdata/T20.hs.expected b/plugins/hls-eval-plugin/test/testdata/T20.expected.hs similarity index 100% rename from plugins/hls-eval-plugin/test/testdata/T20.hs.expected rename to plugins/hls-eval-plugin/test/testdata/T20.expected.hs diff --git a/plugins/hls-eval-plugin/test/testdata/T21.hs.expected b/plugins/hls-eval-plugin/test/testdata/T21.expected.hs similarity index 100% rename from plugins/hls-eval-plugin/test/testdata/T21.hs.expected rename to plugins/hls-eval-plugin/test/testdata/T21.expected.hs diff --git a/plugins/hls-eval-plugin/test/testdata/T22.hs.expected b/plugins/hls-eval-plugin/test/testdata/T22.expected.hs similarity index 100% rename from plugins/hls-eval-plugin/test/testdata/T22.hs.expected rename to plugins/hls-eval-plugin/test/testdata/T22.expected.hs diff --git a/plugins/hls-eval-plugin/test/testdata/T23.hs.expected b/plugins/hls-eval-plugin/test/testdata/T23.expected.hs similarity index 100% rename from plugins/hls-eval-plugin/test/testdata/T23.hs.expected rename to plugins/hls-eval-plugin/test/testdata/T23.expected.hs diff --git a/plugins/hls-eval-plugin/test/testdata/T24.hs.expected b/plugins/hls-eval-plugin/test/testdata/T24.expected.hs similarity index 100% rename from plugins/hls-eval-plugin/test/testdata/T24.hs.expected rename to plugins/hls-eval-plugin/test/testdata/T24.expected.hs diff --git a/plugins/hls-eval-plugin/test/testdata/T25.hs.expected b/plugins/hls-eval-plugin/test/testdata/T25.expected.hs similarity index 100% rename from plugins/hls-eval-plugin/test/testdata/T25.hs.expected rename to plugins/hls-eval-plugin/test/testdata/T25.expected.hs diff --git a/plugins/hls-eval-plugin/test/testdata/T26.hs.expected b/plugins/hls-eval-plugin/test/testdata/T26.expected.hs similarity index 100% rename from plugins/hls-eval-plugin/test/testdata/T26.hs.expected rename to plugins/hls-eval-plugin/test/testdata/T26.expected.hs diff --git a/plugins/hls-eval-plugin/test/testdata/T27.hs.expected b/plugins/hls-eval-plugin/test/testdata/T27.expected.hs similarity index 100% rename from plugins/hls-eval-plugin/test/testdata/T27.hs.expected rename to plugins/hls-eval-plugin/test/testdata/T27.expected.hs diff --git a/plugins/hls-eval-plugin/test/testdata/T3.hs.expected b/plugins/hls-eval-plugin/test/testdata/T3.expected.hs similarity index 100% rename from plugins/hls-eval-plugin/test/testdata/T3.hs.expected rename to plugins/hls-eval-plugin/test/testdata/T3.expected.hs diff --git a/plugins/hls-eval-plugin/test/testdata/T4.hs.expected b/plugins/hls-eval-plugin/test/testdata/T4.expected.hs similarity index 100% rename from plugins/hls-eval-plugin/test/testdata/T4.hs.expected rename to plugins/hls-eval-plugin/test/testdata/T4.expected.hs diff --git a/plugins/hls-eval-plugin/test/testdata/T5.hs.expected b/plugins/hls-eval-plugin/test/testdata/T5.expected.hs similarity index 100% rename from plugins/hls-eval-plugin/test/testdata/T5.hs.expected rename to plugins/hls-eval-plugin/test/testdata/T5.expected.hs diff --git a/plugins/hls-eval-plugin/test/testdata/T6.hs.expected b/plugins/hls-eval-plugin/test/testdata/T6.expected.hs similarity index 100% rename from plugins/hls-eval-plugin/test/testdata/T6.hs.expected rename to plugins/hls-eval-plugin/test/testdata/T6.expected.hs diff --git a/plugins/hls-eval-plugin/test/testdata/T7.hs.expected b/plugins/hls-eval-plugin/test/testdata/T7.expected.hs similarity index 100% rename from plugins/hls-eval-plugin/test/testdata/T7.hs.expected rename to plugins/hls-eval-plugin/test/testdata/T7.expected.hs diff --git a/plugins/hls-eval-plugin/test/testdata/T8.hs.expected b/plugins/hls-eval-plugin/test/testdata/T8.expected.hs similarity index 100% rename from plugins/hls-eval-plugin/test/testdata/T8.hs.expected rename to plugins/hls-eval-plugin/test/testdata/T8.expected.hs diff --git a/plugins/hls-eval-plugin/test/testdata/T9.hs.expected b/plugins/hls-eval-plugin/test/testdata/T9.expected.hs similarity index 100% rename from plugins/hls-eval-plugin/test/testdata/T9.hs.expected rename to plugins/hls-eval-plugin/test/testdata/T9.expected.hs diff --git a/plugins/hls-eval-plugin/test/testdata/TCPP.hs.expected b/plugins/hls-eval-plugin/test/testdata/TCPP.expected.hs similarity index 100% rename from plugins/hls-eval-plugin/test/testdata/TCPP.hs.expected rename to plugins/hls-eval-plugin/test/testdata/TCPP.expected.hs diff --git a/plugins/hls-eval-plugin/test/testdata/TCompare.hs.expected b/plugins/hls-eval-plugin/test/testdata/TCompare.expected.hs similarity index 100% rename from plugins/hls-eval-plugin/test/testdata/TCompare.hs.expected rename to plugins/hls-eval-plugin/test/testdata/TCompare.expected.hs diff --git a/plugins/hls-eval-plugin/test/testdata/TEndingMulti.hs.expected b/plugins/hls-eval-plugin/test/testdata/TEndingMulti.expected.hs similarity index 100% rename from plugins/hls-eval-plugin/test/testdata/TEndingMulti.hs.expected rename to plugins/hls-eval-plugin/test/testdata/TEndingMulti.expected.hs diff --git a/plugins/hls-eval-plugin/test/testdata/TFlags.hs.expected b/plugins/hls-eval-plugin/test/testdata/TFlags.expected.hs similarity index 100% rename from plugins/hls-eval-plugin/test/testdata/TFlags.hs.expected rename to plugins/hls-eval-plugin/test/testdata/TFlags.expected.hs diff --git a/plugins/hls-eval-plugin/test/testdata/THaddock.hs.expected b/plugins/hls-eval-plugin/test/testdata/THaddock.expected.hs similarity index 100% rename from plugins/hls-eval-plugin/test/testdata/THaddock.hs.expected rename to plugins/hls-eval-plugin/test/testdata/THaddock.expected.hs diff --git a/plugins/hls-eval-plugin/test/testdata/TIO.hs.expected b/plugins/hls-eval-plugin/test/testdata/TIO.expected.hs similarity index 100% rename from plugins/hls-eval-plugin/test/testdata/TIO.hs.expected rename to plugins/hls-eval-plugin/test/testdata/TIO.expected.hs diff --git a/plugins/hls-eval-plugin/test/testdata/TIt.hs.expected b/plugins/hls-eval-plugin/test/testdata/TIt.expected.hs similarity index 100% rename from plugins/hls-eval-plugin/test/testdata/TIt.hs.expected rename to plugins/hls-eval-plugin/test/testdata/TIt.expected.hs diff --git a/plugins/hls-eval-plugin/test/testdata/TLHS.lhs.expected b/plugins/hls-eval-plugin/test/testdata/TLHS.expected.lhs similarity index 100% rename from plugins/hls-eval-plugin/test/testdata/TLHS.lhs.expected rename to plugins/hls-eval-plugin/test/testdata/TLHS.expected.lhs diff --git a/plugins/hls-eval-plugin/test/testdata/TLHSLateX.lhs.expected b/plugins/hls-eval-plugin/test/testdata/TLHSLateX.expected.lhs similarity index 100% rename from plugins/hls-eval-plugin/test/testdata/TLHSLateX.lhs.expected rename to plugins/hls-eval-plugin/test/testdata/TLHSLateX.expected.lhs diff --git a/plugins/hls-eval-plugin/test/testdata/TLanguageOptionsTupleSections.hs.expected b/plugins/hls-eval-plugin/test/testdata/TLanguageOptionsTupleSections.expected.hs similarity index 100% rename from plugins/hls-eval-plugin/test/testdata/TLanguageOptionsTupleSections.hs.expected rename to plugins/hls-eval-plugin/test/testdata/TLanguageOptionsTupleSections.expected.hs diff --git a/plugins/hls-eval-plugin/test/testdata/TLastLine.hs.expected b/plugins/hls-eval-plugin/test/testdata/TLastLine.expected.hs similarity index 100% rename from plugins/hls-eval-plugin/test/testdata/TLastLine.hs.expected rename to plugins/hls-eval-plugin/test/testdata/TLastLine.expected.hs diff --git a/plugins/hls-eval-plugin/test/testdata/TLocalImport.hs.expected b/plugins/hls-eval-plugin/test/testdata/TLocalImport.expected.hs similarity index 100% rename from plugins/hls-eval-plugin/test/testdata/TLocalImport.hs.expected rename to plugins/hls-eval-plugin/test/testdata/TLocalImport.expected.hs diff --git a/plugins/hls-eval-plugin/test/testdata/TLocalImportInTest.hs.expected b/plugins/hls-eval-plugin/test/testdata/TLocalImportInTest.expected.hs similarity index 100% rename from plugins/hls-eval-plugin/test/testdata/TLocalImportInTest.hs.expected rename to plugins/hls-eval-plugin/test/testdata/TLocalImportInTest.expected.hs diff --git a/plugins/hls-eval-plugin/test/testdata/TMulti.hs.expected b/plugins/hls-eval-plugin/test/testdata/TMulti.expected.hs similarity index 100% rename from plugins/hls-eval-plugin/test/testdata/TMulti.hs.expected rename to plugins/hls-eval-plugin/test/testdata/TMulti.expected.hs diff --git a/plugins/hls-eval-plugin/test/testdata/TNested.hs.expected b/plugins/hls-eval-plugin/test/testdata/TNested.expected.hs similarity index 100% rename from plugins/hls-eval-plugin/test/testdata/TNested.hs.expected rename to plugins/hls-eval-plugin/test/testdata/TNested.expected.hs diff --git a/plugins/hls-eval-plugin/test/testdata/TNoImplicitPrelude.hs.expected b/plugins/hls-eval-plugin/test/testdata/TNoImplicitPrelude.expected.hs similarity index 100% rename from plugins/hls-eval-plugin/test/testdata/TNoImplicitPrelude.hs.expected rename to plugins/hls-eval-plugin/test/testdata/TNoImplicitPrelude.expected.hs diff --git a/plugins/hls-eval-plugin/test/testdata/TPlainComment.hs.expected b/plugins/hls-eval-plugin/test/testdata/TPlainComment.expected.hs similarity index 100% rename from plugins/hls-eval-plugin/test/testdata/TPlainComment.hs.expected rename to plugins/hls-eval-plugin/test/testdata/TPlainComment.expected.hs diff --git a/plugins/hls-eval-plugin/test/testdata/TPrelude.hs.expected b/plugins/hls-eval-plugin/test/testdata/TPrelude.expected.hs similarity index 100% rename from plugins/hls-eval-plugin/test/testdata/TPrelude.hs.expected rename to plugins/hls-eval-plugin/test/testdata/TPrelude.expected.hs diff --git a/plugins/hls-eval-plugin/test/testdata/TProperty.hs.expected b/plugins/hls-eval-plugin/test/testdata/TProperty.expected.hs similarity index 100% rename from plugins/hls-eval-plugin/test/testdata/TProperty.hs.expected rename to plugins/hls-eval-plugin/test/testdata/TProperty.expected.hs diff --git a/plugins/hls-eval-plugin/test/testdata/TSectionEval.hs.expected b/plugins/hls-eval-plugin/test/testdata/TSectionEval.expected.hs similarity index 100% rename from plugins/hls-eval-plugin/test/testdata/TSectionEval.hs.expected rename to plugins/hls-eval-plugin/test/testdata/TSectionEval.expected.hs diff --git a/plugins/hls-eval-plugin/test/testdata/TSetup.hs.expected b/plugins/hls-eval-plugin/test/testdata/TSetup.expected.hs similarity index 100% rename from plugins/hls-eval-plugin/test/testdata/TSetup.hs.expected rename to plugins/hls-eval-plugin/test/testdata/TSetup.expected.hs diff --git a/plugins/hls-eval-plugin/test/testdata/TUNPACK.hs.expected b/plugins/hls-eval-plugin/test/testdata/TUNPACK.expected.hs similarity index 100% rename from plugins/hls-eval-plugin/test/testdata/TUNPACK.hs.expected rename to plugins/hls-eval-plugin/test/testdata/TUNPACK.expected.hs From 717b1ff806349082a96faba33141b1e3b6349faa Mon Sep 17 00:00:00 2001 From: Junyoung/Clare Jang Date: Sun, 16 May 2021 00:04:44 -0400 Subject: [PATCH 07/20] Clean up explicit imports plugin --- .../hls-explicit-imports-plugin.cabal | 8 +++---- .../src/Ide/Plugin/ExplicitImports.hs | 21 +++++++++---------- 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/plugins/hls-explicit-imports-plugin/hls-explicit-imports-plugin.cabal b/plugins/hls-explicit-imports-plugin/hls-explicit-imports-plugin.cabal index d7fb907c61..88e01fffa5 100644 --- a/plugins/hls-explicit-imports-plugin/hls-explicit-imports-plugin.cabal +++ b/plugins/hls-explicit-imports-plugin/hls-explicit-imports-plugin.cabal @@ -8,23 +8,21 @@ author: Pepe Iborra maintainer: pepeiborra@gmail.com category: Development build-type: Simple -extra-source-files: - LICENSE +extra-source-files: LICENSE library exposed-modules: Ide.Plugin.ExplicitImports hs-source-dirs: src build-depends: , aeson - , base >=4.12 && <5 + , base >=4.12 && <5 , containers , deepseq , ghc , ghcide ^>=1.3 + , hls-graph , hls-plugin-api ^>=1.1 , lsp - , lsp-types - , hls-graph , text , unordered-containers diff --git a/plugins/hls-explicit-imports-plugin/src/Ide/Plugin/ExplicitImports.hs b/plugins/hls-explicit-imports-plugin/src/Ide/Plugin/ExplicitImports.hs index 4714fe49ee..669c93b866 100644 --- a/plugins/hls-explicit-imports-plugin/src/Ide/Plugin/ExplicitImports.hs +++ b/plugins/hls-explicit-imports-plugin/src/Ide/Plugin/ExplicitImports.hs @@ -1,13 +1,11 @@ -{-# LANGUAGE CPP #-} -{-# LANGUAGE DeriveAnyClass #-} -{-# LANGUAGE DeriveGeneric #-} -{-# LANGUAGE DerivingStrategies #-} -{-# LANGUAGE DuplicateRecordFields #-} -{-# LANGUAGE NamedFieldPuns #-} -{-# LANGUAGE OverloadedStrings #-} -{-# LANGUAGE RecordWildCards #-} -{-# LANGUAGE ScopedTypeVariables #-} -{-# LANGUAGE TypeFamilies #-} +{-# LANGUAGE CPP #-} +{-# LANGUAGE DeriveAnyClass #-} +{-# LANGUAGE DeriveGeneric #-} +{-# LANGUAGE DerivingStrategies #-} +{-# LANGUAGE NamedFieldPuns #-} +{-# LANGUAGE OverloadedStrings #-} +{-# LANGUAGE RecordWildCards #-} +{-# LANGUAGE TypeFamilies #-} module Ide.Plugin.ExplicitImports @@ -26,7 +24,8 @@ import Data.IORef (readIORef) import qualified Data.Map.Strict as Map import Data.Maybe (catMaybes, fromMaybe) import qualified Data.Text as T -import Development.IDE +import Development.IDE hiding (pluginHandlers, + pluginRules) import Development.IDE.Core.PositionMapping import Development.IDE.GHC.Compat import Development.IDE.Graph.Classes From 00c51b0058835ad89d1010dde40e59b06f35a63f Mon Sep 17 00:00:00 2001 From: Junyoung/Clare Jang Date: Sun, 16 May 2021 00:11:31 -0400 Subject: [PATCH 08/20] Clean up floskell plugin --- .../hls-floskell-plugin.cabal | 8 ++--- .../src/Ide/Plugin/Floskell.hs | 19 +++++------- plugins/hls-floskell-plugin/test/Main.hs | 29 ++++++++++--------- .../test/testdata/hie.yaml | 2 ++ 4 files changed, 30 insertions(+), 28 deletions(-) create mode 100644 plugins/hls-floskell-plugin/test/testdata/hie.yaml diff --git a/plugins/hls-floskell-plugin/hls-floskell-plugin.cabal b/plugins/hls-floskell-plugin/hls-floskell-plugin.cabal index 6c8429d2a3..10423ef433 100644 --- a/plugins/hls-floskell-plugin/hls-floskell-plugin.cabal +++ b/plugins/hls-floskell-plugin/hls-floskell-plugin.cabal @@ -20,9 +20,9 @@ library exposed-modules: Ide.Plugin.Floskell hs-source-dirs: src build-depends: - , base >=4.12 && <5 - , floskell ^>=0.10 - , ghcide >=1.2 && <1.4 + , base >=4.12 && <5 + , floskell ^>=0.10 + , ghcide >=1.2 && <1.4 , hls-plugin-api ^>=1.1 , lsp-types , text @@ -38,6 +38,6 @@ test-suite tests ghc-options: -threaded -rtsopts -with-rtsopts=-N build-depends: , base + , filepath , hls-floskell-plugin , hls-test-utils ^>=1.0 - , text diff --git a/plugins/hls-floskell-plugin/src/Ide/Plugin/Floskell.hs b/plugins/hls-floskell-plugin/src/Ide/Plugin/Floskell.hs index 78f284ef32..70fe309b66 100644 --- a/plugins/hls-floskell-plugin/src/Ide/Plugin/Floskell.hs +++ b/plugins/hls-floskell-plugin/src/Ide/Plugin/Floskell.hs @@ -1,18 +1,15 @@ -{-# LANGUAGE OverloadedStrings #-} -{-# LANGUAGE ScopedTypeVariables #-} +{-# LANGUAGE OverloadedStrings #-} module Ide.Plugin.Floskell - ( - descriptor + ( descriptor , provider - ) -where + ) where import Control.Monad.IO.Class import qualified Data.Text as T import qualified Data.Text.Lazy as TL import qualified Data.Text.Lazy.Encoding as TL -import Development.IDE as D hiding (pluginHandlers) +import Development.IDE hiding (pluginHandlers) import Floskell import Ide.PluginUtils import Ide.Types @@ -37,10 +34,10 @@ provider _ideState typ contents fp _ = liftIO $ do let (range, selectedContents) = case typ of FormatText -> (fullRange contents, contents) FormatRange r -> (r, extractRange r contents) - result = reformat config (Just file) (TL.encodeUtf8 (TL.fromStrict selectedContents)) + result = reformat config (Just file) . TL.encodeUtf8 $ TL.fromStrict selectedContents case result of - Left err -> return $ Left $ responseError (T.pack $ "floskellCmd: " ++ err) - Right new -> return $ Right $ List [TextEdit range . TL.toStrict $ TL.decodeUtf8 new] + Left err -> pure $ Left $ responseError $ T.pack $ "floskellCmd: " ++ err + Right new -> pure $ Right $ List [TextEdit range . TL.toStrict $ TL.decodeUtf8 new] -- | Find Floskell Config, user and system wide or provides a default style. -- Every directory of the filepath will be searched to find a user configuration. @@ -53,6 +50,6 @@ findConfigOrDefault file = do Just confFile -> readAppConfig confFile Nothing -> let gibiansky = head (filter (\s -> styleName s == "gibiansky") styles) - in return $ defaultAppConfig { appStyle = gibiansky } + in pure $ defaultAppConfig { appStyle = gibiansky } -- --------------------------------------------------------------------- diff --git a/plugins/hls-floskell-plugin/test/Main.hs b/plugins/hls-floskell-plugin/test/Main.hs index 36b6d14ff0..162230b94d 100644 --- a/plugins/hls-floskell-plugin/test/Main.hs +++ b/plugins/hls-floskell-plugin/test/Main.hs @@ -1,27 +1,30 @@ {-# LANGUAGE OverloadedStrings #-} -module Main(main) where +module Main + ( main + ) where -import qualified Data.Text.Lazy as TL -import qualified Data.Text.Lazy.Encoding as TL -import qualified Ide.Plugin.Floskell as Floskell +import qualified Ide.Plugin.Floskell as Floskell +import System.FilePath import Test.Hls main :: IO () main = defaultTestRunner tests -plugin :: PluginDescriptor IdeState -plugin = Floskell.descriptor "floskell" +floskellPlugin :: PluginDescriptor IdeState +floskellPlugin = Floskell.descriptor "floskell" tests :: TestTree tests = testGroup "floskell" - [ goldenGitDiff "formats a document" "test/testdata/Floskell.formatted_document.hs" $ runSessionWithServerFormatter plugin "floskell" "test/testdata" $ do - doc <- openDoc "Floskell.hs" "haskell" - formatDoc doc (FormattingOptions 4 True Nothing Nothing Nothing) - TL.encodeUtf8 . TL.fromStrict <$> documentContents doc + [ goldenWithFloskell "formats a document" "Floskell" "formatted_document" $ \doc -> do + formatDoc doc (FormattingOptions 4 True Nothing Nothing Nothing) - , goldenGitDiff "formats a range" "test/testdata/Floskell.formatted_range.hs" $ runSessionWithServerFormatter plugin "floskell" "test/testdata" $ do - doc <- openDoc "Floskell.hs" "haskell" + , goldenWithFloskell "formats a range" "Floskell" "formatted_range" $ \doc -> do let range = Range (Position 1 0) (Position 4 22) formatRange doc (FormattingOptions 4 True Nothing Nothing Nothing) range - TL.encodeUtf8 . TL.fromStrict <$> documentContents doc ] + +goldenWithFloskell :: TestName -> FilePath -> FilePath -> (TextDocumentIdentifier -> Session ()) -> TestTree +goldenWithFloskell title path desc = goldenWithHaskellDoc floskellPlugin title testDataDir path desc "hs" + +testDataDir :: FilePath +testDataDir = "test" "testdata" diff --git a/plugins/hls-floskell-plugin/test/testdata/hie.yaml b/plugins/hls-floskell-plugin/test/testdata/hie.yaml new file mode 100644 index 0000000000..47db6b9bc8 --- /dev/null +++ b/plugins/hls-floskell-plugin/test/testdata/hie.yaml @@ -0,0 +1,2 @@ +cradle: + direct: From f6535554815a980d936ad2e1822c8bde4155d9a9 Mon Sep 17 00:00:00 2001 From: Junyoung/Clare Jang Date: Sun, 16 May 2021 00:22:01 -0400 Subject: [PATCH 09/20] Clean up fourmolu plugin --- .../hls-fourmolu-plugin.cabal | 23 +++-------- .../src/Ide/Plugin/Fourmolu.hs | 18 ++++----- plugins/hls-fourmolu-plugin/test/Main.hs | 40 ++++++++----------- ...olu.formatted.hs => Fourmolu.formatted.hs} | 0 .../test/testdata/{Format.hs => Fourmolu.hs} | 2 +- ...lu.formatted.hs => Fourmolu2.formatted.hs} | 0 .../testdata/{Format2.hs => Fourmolu2.hs} | 0 .../test/testdata/hie.yaml | 2 + 8 files changed, 33 insertions(+), 52 deletions(-) rename plugins/hls-fourmolu-plugin/test/testdata/{Format.fourmolu.formatted.hs => Fourmolu.formatted.hs} (100%) rename plugins/hls-fourmolu-plugin/test/testdata/{Format.hs => Fourmolu.hs} (90%) rename plugins/hls-fourmolu-plugin/test/testdata/{Format2.fourmolu.formatted.hs => Fourmolu2.formatted.hs} (100%) rename plugins/hls-fourmolu-plugin/test/testdata/{Format2.hs => Fourmolu2.hs} (100%) create mode 100644 plugins/hls-fourmolu-plugin/test/testdata/hie.yaml diff --git a/plugins/hls-fourmolu-plugin/hls-fourmolu-plugin.cabal b/plugins/hls-fourmolu-plugin/hls-fourmolu-plugin.cabal index b4cdf3d8ea..9aee0b6ccc 100644 --- a/plugins/hls-fourmolu-plugin/hls-fourmolu-plugin.cabal +++ b/plugins/hls-fourmolu-plugin/hls-fourmolu-plugin.cabal @@ -20,17 +20,15 @@ library exposed-modules: Ide.Plugin.Fourmolu hs-source-dirs: src build-depends: - , base >=4.12 && <5 - , extra - , fourmolu ^>=0.3 + , base >=4.12 && <5 , filepath + , fourmolu ^>=0.3 , ghc , ghc-boot-th - , ghcide >=1.2 && <1.4 + , ghcide >=1.2 && <1.4 , hls-plugin-api ^>=1.1 , lens , lsp - , lsp-types , text default-language: Haskell2010 @@ -43,18 +41,7 @@ test-suite tests ghc-options: -threaded -rtsopts -with-rtsopts=-N build-depends: , base - , bytestring - , hls-fourmolu-plugin - , text - , data-default - , hspec-expectations - , lens - , ghcide , filepath - , hls-test-utils ^>= 1.0 - , lsp-types - , aeson - , hls-plugin-api + , hls-fourmolu-plugin + , hls-test-utils ^>=1.0 , lsp-test - , containers - , unordered-containers diff --git a/plugins/hls-fourmolu-plugin/src/Ide/Plugin/Fourmolu.hs b/plugins/hls-fourmolu-plugin/src/Ide/Plugin/Fourmolu.hs index f382a72229..cb9d766d06 100644 --- a/plugins/hls-fourmolu-plugin/src/Ide/Plugin/Fourmolu.hs +++ b/plugins/hls-fourmolu-plugin/src/Ide/Plugin/Fourmolu.hs @@ -9,26 +9,24 @@ module Ide.Plugin.Fourmolu ( provider, ) where -import Control.Exception -import Data.Either.Extra -import System.FilePath - +import Control.Exception (try) import Control.Lens ((^.)) +import Control.Monad.IO.Class +import Data.Bifunctor (first) import qualified Data.Text as T -import Development.IDE as D hiding (pluginHandlers) +import Development.IDE hiding (pluginHandlers) +import Development.IDE.GHC.Compat (moduleNameString) import qualified DynFlags as D import qualified EnumSet as S -import GHC (DynFlags, moduleNameString) import GHC.LanguageExtensions.Type (Extension (Cpp)) import GhcPlugins (HscEnv (hsc_dflags)) import Ide.PluginUtils (makeDiffTextEdit) - -import Control.Monad.IO.Class import Ide.Types import Language.LSP.Server hiding (defaultConfig) import Language.LSP.Types import Language.LSP.Types.Lens import "fourmolu" Ormolu +import System.FilePath -- --------------------------------------------------------------------- @@ -48,7 +46,7 @@ provider ideState typ contents fp fo = withIndefiniteProgress title Cancellable Just df -> liftIO $ convertDynFlags df let format printerOpts = - mapLeft (responseError . ("Fourmolu: " <>) . T.pack . show) + first (responseError . ("Fourmolu: " <>) . T.pack . show) <$> try @OrmoluException (makeDiffTextEdit contents <$> ormolu config fp' (T.unpack contents)) where config = @@ -91,7 +89,7 @@ provider ideState typ contents fp fo = withIndefiniteProgress title Cancellable FormatRange (Range (Position sl _) (Position el _)) -> RegionIndices (Just $ sl + 1) (Just $ el + 1) -convertDynFlags :: DynFlags -> IO [DynOption] +convertDynFlags :: D.DynFlags -> IO [DynOption] convertDynFlags df = let pp = ["-pgmF=" <> p | not (null p)] p = D.sPgm_F $ D.settings df diff --git a/plugins/hls-fourmolu-plugin/test/Main.hs b/plugins/hls-fourmolu-plugin/test/Main.hs index 5ef9ac8c44..b10e900ae0 100644 --- a/plugins/hls-fourmolu-plugin/test/Main.hs +++ b/plugins/hls-fourmolu-plugin/test/Main.hs @@ -1,36 +1,30 @@ {-# LANGUAGE OverloadedStrings #-} -module Main(main) where +module Main + ( main + ) where -import Control.Monad.IO.Class -import Data.Aeson -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.Fourmolu as Fourmolu import Language.LSP.Test import Language.LSP.Types -import Test.Hls -import qualified Ide.Plugin.Fourmolu as Fourmolu import System.FilePath +import Test.Hls main :: IO () main = defaultTestRunner tests -plugin :: PluginDescriptor IdeState -plugin = Fourmolu.descriptor "fourmolu" - -testDataDir :: FilePath -testDataDir = "test/testdata/" +fourmoluPlugin :: PluginDescriptor IdeState +fourmoluPlugin = Fourmolu.descriptor "fourmolu" tests :: TestTree tests = testGroup "fourmolu" - [ goldenGitDiff "formats correctly" (testDataDir "Format.fourmolu.formatted.hs") $ - runSessionWithServerFormatter plugin "fourmolu" testDataDir $ do - doc <- openDoc "Format.hs" "haskell" - formatDoc doc (FormattingOptions 4 True Nothing Nothing Nothing) - BS.fromStrict . T.encodeUtf8 <$> documentContents doc - , goldenGitDiff "formats imports correctly" (testDataDir "Format2.fourmolu.formatted.hs") $ - runSessionWithServerFormatter plugin "fourmolu" testDataDir $ do - doc <- openDoc "Format2.hs" "haskell" - formatDoc doc (FormattingOptions 4 True Nothing Nothing Nothing) - BS.fromStrict . T.encodeUtf8 <$> documentContents doc + [ goldenWithFourmolu "formats correctly" "Fourmolu" "formatted" $ \doc -> do + formatDoc doc (FormattingOptions 4 True Nothing Nothing Nothing) + , goldenWithFourmolu "formats imports correctly" "Fourmolu" "formatted" $ \doc -> do + formatDoc doc (FormattingOptions 4 True Nothing Nothing Nothing) ] + +goldenWithFourmolu :: TestName -> FilePath -> FilePath -> (TextDocumentIdentifier -> Session ()) -> TestTree +goldenWithFourmolu title path desc = goldenWithHaskellDoc fourmoluPlugin title testDataDir path desc "hs" + +testDataDir :: FilePath +testDataDir = "test" "testdata" diff --git a/plugins/hls-fourmolu-plugin/test/testdata/Format.fourmolu.formatted.hs b/plugins/hls-fourmolu-plugin/test/testdata/Fourmolu.formatted.hs similarity index 100% rename from plugins/hls-fourmolu-plugin/test/testdata/Format.fourmolu.formatted.hs rename to plugins/hls-fourmolu-plugin/test/testdata/Fourmolu.formatted.hs diff --git a/plugins/hls-fourmolu-plugin/test/testdata/Format.hs b/plugins/hls-fourmolu-plugin/test/testdata/Fourmolu.hs similarity index 90% rename from plugins/hls-fourmolu-plugin/test/testdata/Format.hs rename to plugins/hls-fourmolu-plugin/test/testdata/Fourmolu.hs index b8bb374e2e..14eabbd69a 100644 --- a/plugins/hls-fourmolu-plugin/test/testdata/Format.hs +++ b/plugins/hls-fourmolu-plugin/test/testdata/Fourmolu.hs @@ -1,4 +1,4 @@ -module Format where +module Fourmolu where import Data.List import Prelude diff --git a/plugins/hls-fourmolu-plugin/test/testdata/Format2.fourmolu.formatted.hs b/plugins/hls-fourmolu-plugin/test/testdata/Fourmolu2.formatted.hs similarity index 100% rename from plugins/hls-fourmolu-plugin/test/testdata/Format2.fourmolu.formatted.hs rename to plugins/hls-fourmolu-plugin/test/testdata/Fourmolu2.formatted.hs diff --git a/plugins/hls-fourmolu-plugin/test/testdata/Format2.hs b/plugins/hls-fourmolu-plugin/test/testdata/Fourmolu2.hs similarity index 100% rename from plugins/hls-fourmolu-plugin/test/testdata/Format2.hs rename to plugins/hls-fourmolu-plugin/test/testdata/Fourmolu2.hs diff --git a/plugins/hls-fourmolu-plugin/test/testdata/hie.yaml b/plugins/hls-fourmolu-plugin/test/testdata/hie.yaml new file mode 100644 index 0000000000..47db6b9bc8 --- /dev/null +++ b/plugins/hls-fourmolu-plugin/test/testdata/hie.yaml @@ -0,0 +1,2 @@ +cradle: + direct: From f975f87b6564c6537267c3eb57c320f7c5915f94 Mon Sep 17 00:00:00 2001 From: Junyoung/Clare Jang Date: Sun, 16 May 2021 00:30:46 -0400 Subject: [PATCH 10/20] Clean up haddock comments plugin --- .../hls-haddock-comments-plugin.cabal | 7 ++- .../hls-haddock-comments-plugin/test/Main.hs | 45 +++++++------------ .../test/testdata/hie.yaml | 2 + 3 files changed, 22 insertions(+), 32 deletions(-) create mode 100644 plugins/hls-haddock-comments-plugin/test/testdata/hie.yaml diff --git a/plugins/hls-haddock-comments-plugin/hls-haddock-comments-plugin.cabal b/plugins/hls-haddock-comments-plugin/hls-haddock-comments-plugin.cabal index e490a7831e..d34ec57e2f 100644 --- a/plugins/hls-haddock-comments-plugin/hls-haddock-comments-plugin.cabal +++ b/plugins/hls-haddock-comments-plugin/hls-haddock-comments-plugin.cabal @@ -25,11 +25,11 @@ library -Wno-unticked-promoted-constructors build-depends: - , base >=4.12 && <5 + , base >=4.12 && <5 , containers , ghc , ghc-exactprint - , ghcide >=1.2 && <1.4 + , ghcide >=1.2 && <1.4 , hls-plugin-api ^>=1.1 , lsp-types , text @@ -48,8 +48,7 @@ test-suite tests ghc-options: -threaded -rtsopts -with-rtsopts=-N build-depends: , base - , bytestring , filepath , hls-haddock-comments-plugin - , hls-test-utils ^>= 1.0 + , hls-test-utils ^>=1.0 , text diff --git a/plugins/hls-haddock-comments-plugin/test/Main.hs b/plugins/hls-haddock-comments-plugin/test/Main.hs index 5bc2817e8e..2cfddadffc 100644 --- a/plugins/hls-haddock-comments-plugin/test/Main.hs +++ b/plugins/hls-haddock-comments-plugin/test/Main.hs @@ -1,21 +1,16 @@ -{-# LANGUAGE DataKinds #-} {-# LANGUAGE DisambiguateRecordFields #-} -{-# LANGUAGE GADTs #-} {-# LANGUAGE NamedFieldPuns #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE TypeOperators #-} {-# LANGUAGE ViewPatterns #-} module Main - ( main, - ) -where + ( main + ) where -import qualified Data.ByteString.Lazy as LBS import Data.Foldable (find) import Data.Maybe (mapMaybe) import Data.Text (Text) -import Data.Text.Encoding (encodeUtf8) import qualified Ide.Plugin.HaddockComments as HaddockComments import System.FilePath ((<.>), ()) import Test.Hls @@ -23,40 +18,34 @@ import Test.Hls main :: IO () main = defaultTestRunner tests -plugin :: PluginDescriptor IdeState -plugin = HaddockComments.descriptor "haddockComments" +haddockCommentsPlugin :: PluginDescriptor IdeState +haddockCommentsPlugin = HaddockComments.descriptor "haddockComments" tests :: TestTree tests = testGroup "haddock comments" - [ goldenTest "HigherRankFunction" Signature 4 6, - goldenTest "KindSigFunction" Signature 9 10, - goldenTest "MultivariateFunction" Signature 4 8, - goldenTest "QualFunction" Signature 2 10, - goldenTest "Record" Record 7 2, + [ goldenWithHaddockComments "HigherRankFunction" Signature 4 6, + goldenWithHaddockComments "KindSigFunction" Signature 9 10, + goldenWithHaddockComments "MultivariateFunction" Signature 4 8, + goldenWithHaddockComments "QualFunction" Signature 2 10, + goldenWithHaddockComments "Record" Record 7 2, expectedNothing "ConstFunction" Signature 2 2, expectedNothing "StaleFunction" Signature 3 3, expectedNothing "StaleRecord" Record 3 12 ] -goldenTest :: FilePath -> GenCommentsType -> Int -> Int -> TestTree -goldenTest fp (toTitle -> expectedTitle) l c = goldenGitDiff (fp <> " (golden)") goldenFilePath $ - runSessionWithServer plugin haddockCommentsPath $ do - doc <- openDoc hsFilePath "haskell" +goldenWithHaddockComments :: FilePath -> GenCommentsType -> Int -> Int -> TestTree +goldenWithHaddockComments fp (toTitle -> expectedTitle) l c = + goldenWithHaskellDoc haddockCommentsPlugin (fp <> " (golden)") testDataDir fp "expected" "hs" $ \doc -> do actions <- getCodeActions doc (Range (Position l c) (Position l $ succ c)) case find ((== Just expectedTitle) . caTitle) actions of - Just (InR x) -> do - executeCodeAction x - LBS.fromStrict . encodeUtf8 <$> documentContents doc - _ -> liftIO $ assertFailure "Unable to find CodeAction" - where - hsFilePath = fp <.> "hs" - goldenFilePath = haddockCommentsPath fp <.> "expected" <.> "hs" + Just (InR x) -> executeCodeAction x + _ -> liftIO $ assertFailure "Unable to find CodeAction" expectedNothing :: FilePath -> GenCommentsType -> Int -> Int -> TestTree expectedNothing fp (toTitle -> expectedTitle) l c = testCase fp $ - runSessionWithServer plugin haddockCommentsPath $ do + runSessionWithServer haddockCommentsPlugin testDataDir $ do doc <- openDoc (fp <.> "hs") "haskell" titles <- mapMaybe caTitle <$> getCodeActions doc (Range (Position l c) (Position l $ succ c)) liftIO $ expectedTitle `notElem` titles @? "Unexpected CodeAction" @@ -71,6 +60,6 @@ caTitle :: (Command |? CodeAction) -> Maybe Text caTitle (InR CodeAction {_title}) = Just _title caTitle _ = Nothing -haddockCommentsPath :: String -haddockCommentsPath = "test" "testdata" +testDataDir :: String +testDataDir = "test" "testdata" diff --git a/plugins/hls-haddock-comments-plugin/test/testdata/hie.yaml b/plugins/hls-haddock-comments-plugin/test/testdata/hie.yaml new file mode 100644 index 0000000000..47db6b9bc8 --- /dev/null +++ b/plugins/hls-haddock-comments-plugin/test/testdata/hie.yaml @@ -0,0 +1,2 @@ +cradle: + direct: From 1394eb87e6b5ed48ef68f2b0e6f2c1b75cfdf1c0 Mon Sep 17 00:00:00 2001 From: Junyoung/Clare Jang Date: Sun, 16 May 2021 00:33:53 -0400 Subject: [PATCH 11/20] Clean up hlint plugin --- plugins/hls-hlint-plugin/hls-hlint-plugin.cabal | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/hls-hlint-plugin/hls-hlint-plugin.cabal b/plugins/hls-hlint-plugin/hls-hlint-plugin.cabal index 166217a44b..39a3dc52be 100644 --- a/plugins/hls-hlint-plugin/hls-hlint-plugin.cabal +++ b/plugins/hls-hlint-plugin/hls-hlint-plugin.cabal @@ -41,7 +41,7 @@ library , extra , filepath , ghc-exactprint >=0.6.3.4 - , ghcide >=1.2 && <1.4 + , ghcide >=1.2 && <1.4 , hashable , hlint ^>=3.2 , hls-plugin-api ^>=1.1 From 282b3289ffa94748f87cd861fb28cb600dd28f28 Mon Sep 17 00:00:00 2001 From: Junyoung/Clare Jang Date: Sun, 16 May 2021 00:38:46 -0400 Subject: [PATCH 12/20] Clean up pragmas plugin --- .../hls-pragmas-plugin.cabal | 15 ++-- .../src/Ide/Plugin/Pragmas.hs | 4 +- plugins/hls-pragmas-plugin/test/Main.hs | 72 ++++++------------- 3 files changed, 33 insertions(+), 58 deletions(-) diff --git a/plugins/hls-pragmas-plugin/hls-pragmas-plugin.cabal b/plugins/hls-pragmas-plugin/hls-pragmas-plugin.cabal index 8d7688a9a8..b6d31dbc53 100644 --- a/plugins/hls-pragmas-plugin/hls-pragmas-plugin.cabal +++ b/plugins/hls-pragmas-plugin/hls-pragmas-plugin.cabal @@ -18,20 +18,21 @@ extra-source-files: test/testdata/*.yaml library - exposed-modules: Ide.Plugin.Pragmas - hs-source-dirs: src + exposed-modules: Ide.Plugin.Pragmas + hs-source-dirs: src build-depends: - base >=4.12 && <5 + , base >=4.12 && <5 , extra , fuzzy - , ghcide >=1.2 && <1.4 + , ghcide >=1.2 && <1.4 , hls-plugin-api ^>=1.1 , lens , lsp , text , transformers , unordered-containers - default-language: Haskell2010 + + default-language: Haskell2010 test-suite tests type: exitcode-stdio-1.0 @@ -43,8 +44,6 @@ test-suite tests , base , filepath , hls-pragmas-plugin - , hls-test-utils ^>=1.0 + , hls-test-utils ^>=1.0 , lens - , lsp-test , lsp-types - , text diff --git a/plugins/hls-pragmas-plugin/src/Ide/Plugin/Pragmas.hs b/plugins/hls-pragmas-plugin/src/Ide/Plugin/Pragmas.hs index 3d91297ddf..b6e73e3964 100644 --- a/plugins/hls-pragmas-plugin/src/Ide/Plugin/Pragmas.hs +++ b/plugins/hls-pragmas-plugin/src/Ide/Plugin/Pragmas.hs @@ -6,7 +6,9 @@ {-# LANGUAGE ViewPatterns #-} -- | Provides code actions to add missing pragmas (whenever GHC suggests to) -module Ide.Plugin.Pragmas (descriptor) where +module Ide.Plugin.Pragmas + ( descriptor + ) where import Control.Applicative ((<|>)) import Control.Lens hiding (List) diff --git a/plugins/hls-pragmas-plugin/test/Main.hs b/plugins/hls-pragmas-plugin/test/Main.hs index 5ed53aaba9..5423dfa330 100644 --- a/plugins/hls-pragmas-plugin/test/Main.hs +++ b/plugins/hls-pragmas-plugin/test/Main.hs @@ -1,15 +1,9 @@ -{-# LANGUAGE DuplicateRecordFields #-} -{-# LANGUAGE OverloadedStrings #-} -{-# LANGUAGE ScopedTypeVariables #-} -module Main ( - main, -) where +{-# LANGUAGE OverloadedStrings #-} +module Main + ( main + ) where import Control.Lens ((^.)) -import qualified Data.Text as T -import qualified Data.Text.IO as T -import qualified Data.Text.Lazy as TL -import qualified Data.Text.Lazy.Encoding as TL import qualified Ide.Plugin.Pragmas as Pragmas import qualified Language.LSP.Types.Lens as L import System.FilePath @@ -31,78 +25,62 @@ tests = codeActionTests :: TestTree codeActionTests = testGroup "code actions" - [ pragmasGolden "adds TypeSynonymInstances pragma" "NeedsPragmas" $ \path -> do - doc <- openDoc path "haskell" + [ goldenWithPragmas "adds TypeSynonymInstances pragma" "NeedsPragmas" $ \doc -> do _ <- waitForDiagnosticsFromSource doc "typecheck" cas <- map fromAction <$> getAllCodeActions doc liftIO $ "Add \"TypeSynonymInstances\"" `elem` map (^. L.title) cas @? "Contains TypeSynonymInstances code action" liftIO $ "Add \"FlexibleInstances\"" `elem` map (^. L.title) cas @? "Contains FlexibleInstances code action" executeCodeAction $ head cas - documentContents doc - , pragmasGolden "adds TypeApplications pragma" "TypeApplications" $ \path -> do - doc <- openDoc path "haskell" + , goldenWithPragmas "adds TypeApplications pragma" "TypeApplications" $ \doc -> do _ <- waitForDiagnosticsFrom doc cas <- map fromAction <$> getAllCodeActions doc liftIO $ "Add \"TypeApplications\"" `elem` map (^. L.title) cas @? "Contains TypeApplications code action" executeCodeAction $ head cas - documentContents doc - , pragmasGolden "no duplication" "NamedFieldPuns" $ \path -> do - doc <- openDoc path "haskell" + , goldenWithPragmas "no duplication" "NamedFieldPuns" $ \doc -> do _ <- waitForDiagnosticsFrom doc cas <- map fromAction <$> getCodeActions doc (Range (Position 8 9) (Position 8 9)) liftIO $ length cas == 1 @? "Expected one code action, but got: " <> show cas let ca = head cas liftIO $ (ca ^. L.title == "Add \"NamedFieldPuns\"") @? "NamedFieldPuns code action" executeCodeAction ca - documentContents doc - , pragmasGolden "after shebang" "AfterShebang" $ \path -> do - doc <- openDoc path "haskell" + , goldenWithPragmas "after shebang" "AfterShebang" $ \doc -> do _ <- waitForDiagnosticsFrom doc cas <- map fromAction <$> getAllCodeActions doc liftIO $ "Add \"NamedFieldPuns\"" `elem` map (^. L.title) cas @? "Contains NamedFieldPuns code action" executeCodeAction $ head cas - documentContents doc - , pragmasGolden "append to existing pragmas" "AppendToExisting" $ \path -> do - doc <- openDoc path "haskell" + , goldenWithPragmas "append to existing pragmas" "AppendToExisting" $ \doc -> do _ <- waitForDiagnosticsFrom doc cas <- map fromAction <$> getAllCodeActions doc liftIO $ "Add \"NamedFieldPuns\"" `elem` map (^. L.title) cas @? "Contains NamedFieldPuns code action" executeCodeAction $ head cas - documentContents doc - , pragmasGolden "before doc comments" "BeforeDocComment" $ \path -> do - doc <- openDoc path "haskell" + , goldenWithPragmas "before doc comments" "BeforeDocComment" $ \doc -> do _ <- waitForDiagnosticsFrom doc cas <- map fromAction <$> getAllCodeActions doc liftIO $ "Add \"NamedFieldPuns\"" `elem` map (^. L.title) cas @? "Contains NamedFieldPuns code action" executeCodeAction $ head cas - documentContents doc - , pragmasGolden "before doc comments" "MissingSignatures" $ \path -> do - doc <- openDoc path "haskell" + , goldenWithPragmas "before doc comments" "MissingSignatures" $ \doc -> do _ <- waitForDiagnosticsFrom doc cas <- map fromAction <$> getAllCodeActions doc liftIO $ "Disable \"missing-signatures\" warnings" `elem` map (^. L.title) cas @? "Contains missing-signatures code action" executeCodeAction $ head cas - documentContents doc - , pragmasGolden "before doc comments" "UnusedImports" $ \path -> do - doc <- openDoc path "haskell" + , goldenWithPragmas "before doc comments" "UnusedImports" $ \doc -> do _ <- waitForDiagnosticsFrom doc cas <- map fromAction <$> getAllCodeActions doc liftIO $ "Disable \"unused-imports\" warnings" `elem` map (^. L.title) cas @? "Contains unused-imports code action" executeCodeAction $ head cas - documentContents doc ] completionTests :: TestTree completionTests = testGroup "completions" - [ testCase "completes pragmas" $ runSessionWithServer pragmasPlugin testDirectory $ do + [ testCase "completes pragmas" $ runSessionWithServer pragmasPlugin testDataDir $ do doc <- openDoc "Completion.hs" "haskell" _ <- waitForDiagnostics let te = TextEdit (Range (Position 0 4) (Position 0 34)) "" @@ -115,7 +93,7 @@ completionTests = item ^. L.insertTextFormat @?= Just Snippet item ^. L.insertText @?= Just "LANGUAGE ${1:extension} #-}" - , testCase "completes pragmas no close" $ runSessionWithServer pragmasPlugin testDirectory $ do + , testCase "completes pragmas no close" $ runSessionWithServer pragmasPlugin testDataDir $ do doc <- openDoc "Completion.hs" "haskell" let te = TextEdit (Range (Position 0 4) (Position 0 24)) "" _ <- applyEdit doc te @@ -127,7 +105,7 @@ completionTests = item ^. L.insertTextFormat @?= Just Snippet item ^. L.insertText @?= Just "LANGUAGE ${1:extension}" - , testCase "completes options pragma" $ runSessionWithServer pragmasPlugin testDirectory $ do + , testCase "completes options pragma" $ runSessionWithServer pragmasPlugin testDataDir $ do doc <- openDoc "Completion.hs" "haskell" _ <- waitForDiagnostics let te = TextEdit (Range (Position 0 4) (Position 0 34)) "OPTIONS" @@ -140,7 +118,7 @@ completionTests = item ^. L.insertTextFormat @?= Just Snippet item ^. L.insertText @?= Just "OPTIONS_GHC -${1:option} #-}" - , testCase "completes ghc options pragma values" $ runSessionWithServer pragmasPlugin testDirectory $ do + , testCase "completes ghc options pragma values" $ runSessionWithServer pragmasPlugin testDataDir $ do doc <- openDoc "Completion.hs" "haskell" let te = TextEdit (Range (Position 0 0) (Position 0 0)) "{-# OPTIONS_GHC -Wno-red #-}\n" _ <- applyEdit doc te @@ -152,7 +130,7 @@ completionTests = item ^. L.insertTextFormat @?= Nothing item ^. L.insertText @?= Nothing - , testCase "completes language extensions" $ runSessionWithServer pragmasPlugin testDirectory $ do + , testCase "completes language extensions" $ runSessionWithServer pragmasPlugin testDataDir $ do doc <- openDoc "Completion.hs" "haskell" _ <- waitForDiagnostics let te = TextEdit (Range (Position 0 24) (Position 0 31)) "" @@ -163,7 +141,7 @@ completionTests = item ^. L.label @?= "OverloadedStrings" item ^. L.kind @?= Just CiKeyword - , testCase "completes the Strict language extension" $ runSessionWithServer pragmasPlugin testDirectory $ do + , testCase "completes the Strict language extension" $ runSessionWithServer pragmasPlugin testDataDir $ do doc <- openDoc "Completion.hs" "haskell" _ <- waitForDiagnostics let te = TextEdit (Range (Position 0 13) (Position 0 31)) "Str" @@ -174,7 +152,7 @@ completionTests = item ^. L.label @?= "Strict" item ^. L.kind @?= Just CiKeyword - , testCase "completes No- language extensions" $ runSessionWithServer pragmasPlugin testDirectory $ do + , testCase "completes No- language extensions" $ runSessionWithServer pragmasPlugin testDataDir $ do doc <- openDoc "Completion.hs" "haskell" _ <- waitForDiagnostics let te = TextEdit (Range (Position 0 13) (Position 0 31)) "NoOverload" @@ -186,12 +164,8 @@ completionTests = item ^. L.kind @?= Just CiKeyword ] -pragmasGolden :: TestName -> FilePath -> (FilePath -> Session T.Text) -> TestTree -pragmasGolden title path action = - goldenGitDiff title (testDirectory path <.> "expected.hs") - $ runSessionWithServer pragmasPlugin testDirectory - $ TL.encodeUtf8 . TL.fromStrict - <$> action (path <.> "hs") +goldenWithPragmas :: TestName -> FilePath -> (TextDocumentIdentifier -> Session ()) -> TestTree +goldenWithPragmas title path = goldenWithHaskellDoc pragmasPlugin title testDataDir path "expected" "hs" -testDirectory :: FilePath -testDirectory = "test" "testdata" +testDataDir :: FilePath +testDataDir = "test" "testdata" From d3eb980867b10c274eea58454095f5fe5fbaf965 Mon Sep 17 00:00:00 2001 From: Junyoung/Clare Jang Date: Sun, 16 May 2021 00:52:04 -0400 Subject: [PATCH 13/20] Clean up refine imports plugin --- .../hls-refine-imports-plugin.cabal | 45 +++++++++---------- .../hls-refine-imports-plugin/test/Main.hs | 44 +++++++----------- 2 files changed, 39 insertions(+), 50 deletions(-) diff --git a/plugins/hls-refine-imports-plugin/hls-refine-imports-plugin.cabal b/plugins/hls-refine-imports-plugin/hls-refine-imports-plugin.cabal index e2ada35b0f..acb749b2ce 100644 --- a/plugins/hls-refine-imports-plugin/hls-refine-imports-plugin.cabal +++ b/plugins/hls-refine-imports-plugin/hls-refine-imports-plugin.cabal @@ -1,36 +1,36 @@ -cabal-version: 2.2 -name: hls-refine-imports-plugin -version: 1.0.0.0 -synopsis: Refine imports plugin for Haskell Language Server -license: Apache-2.0 -license-file: LICENSE -author: rayshih -maintainer: mnf.shih@gmail.com -category: Development -build-type: Simple -extra-source-files: - LICENSE +cabal-version: 2.2 +name: hls-refine-imports-plugin +version: 1.0.0.0 +synopsis: Refine imports plugin for Haskell Language Server +license: Apache-2.0 +license-file: LICENSE +author: rayshih +maintainer: mnf.shih@gmail.com +category: Development +build-type: Simple +extra-source-files: LICENSE library - exposed-modules: Ide.Plugin.RefineImports - hs-source-dirs: src + exposed-modules: Ide.Plugin.RefineImports + hs-source-dirs: src build-depends: , aeson - , base >=4.12 && <5 + , base >=4.12 && <5 , containers , deepseq , ghc - , ghcide ^>=1.3 - , hls-plugin-api ^>=1.1 - , lsp - , lsp-types + , ghcide ^>=1.3 + , hls-explicit-imports-plugin ^>=1.0.0.1 , hls-graph + , hls-plugin-api ^>=1.1 + , lsp , text , unordered-containers - , hls-explicit-imports-plugin ^>= 1.0.0.1 - default-language: Haskell2010 - default-extensions: DataKinds, TypeOperators + default-language: Haskell2010 + default-extensions: + DataKinds + TypeOperators test-suite tests type: exitcode-stdio-1.0 @@ -40,7 +40,6 @@ test-suite tests ghc-options: -threaded -rtsopts -with-rtsopts=-N build-depends: , base - , bytestring , filepath , hls-refine-imports-plugin , hls-test-utils diff --git a/plugins/hls-refine-imports-plugin/test/Main.hs b/plugins/hls-refine-imports-plugin/test/Main.hs index a63f63354a..90c294cc24 100644 --- a/plugins/hls-refine-imports-plugin/test/Main.hs +++ b/plugins/hls-refine-imports-plugin/test/Main.hs @@ -4,13 +4,13 @@ {-# LANGUAGE TypeOperators #-} {-# LANGUAGE ViewPatterns #-} -module Main (main) where +module Main + ( main + ) where -import qualified Data.ByteString.Lazy as LBS import Data.Foldable (find, forM_) import Data.Text (Text) import qualified Data.Text as T -import Data.Text.Encoding (encodeUtf8) import qualified Ide.Plugin.RefineImports as RefineImports import System.FilePath ((<.>), ()) import Test.Hls @@ -23,24 +23,17 @@ main = defaultTestRunner $ , codeLensGoldenTest "UsualCase" 1 ] -plugin :: PluginDescriptor IdeState -plugin = RefineImports.descriptor "refineImports" +refineImportsPlugin :: PluginDescriptor IdeState +refineImportsPlugin = RefineImports.descriptor "refineImports" -- code action tests codeActionGoldenTest :: FilePath -> Int -> Int -> TestTree -codeActionGoldenTest fp l c = goldenGitDiff (fp <> " (golden)") goldenFilePath $ - runSessionWithServer plugin testDataDir $ do - doc <- openDoc hsFilePath "haskell" - actions <- getCodeActions doc (pointRange l c) - case find ((== Just "Refine all imports") . caTitle) actions of - Just (InR x) -> do - executeCodeAction x - LBS.fromStrict . encodeUtf8 <$> documentContents doc - _ -> liftIO $ assertFailure "Unable to find CodeAction" - where - hsFilePath = fp <.> "hs" - goldenFilePath = testDataDir fp <.> "expected" <.> "hs" +codeActionGoldenTest fp l c = goldenWithRefineImports fp $ \doc -> do + actions <- getCodeActions doc (pointRange l c) + case find ((== Just "Refine all imports") . caTitle) actions of + Just (InR x) -> executeCodeAction x + _ -> liftIO $ assertFailure "Unable to find CodeAction" caTitle :: (Command |? CodeAction) -> Maybe Text caTitle (InR CodeAction {_title}) = Just _title @@ -50,16 +43,10 @@ caTitle _ = Nothing -- code lens tests codeLensGoldenTest :: FilePath -> Int -> TestTree -codeLensGoldenTest fp codeLensIdx = goldenGitDiff (fp <> " (golden)") goldenFilePath $ - runSessionWithServer plugin testDataDir $ do - doc <- openDoc hsFilePath "haskell" - codeLens <- (!! codeLensIdx) <$> getCodeLensesBy isRefineImports doc - mapM_ executeCmd - [c | CodeLens{_command = Just c} <- [codeLens]] - LBS.fromStrict . encodeUtf8 <$> documentContents doc - where - hsFilePath = fp <.> "hs" - goldenFilePath = testDataDir fp <.> "expected" <.> "hs" +codeLensGoldenTest fp codeLensIdx = goldenWithRefineImports fp $ \doc -> do + codeLens <- (!! codeLensIdx) <$> getCodeLensesBy isRefineImports doc + mapM_ executeCmd + [c | CodeLens{_command = Just c} <- [codeLens]] getCodeLensesBy :: (CodeLens -> Bool) -> TextDocumentIdentifier -> Session [CodeLens] getCodeLensesBy f doc = filter f <$> getCodeLenses doc @@ -79,6 +66,9 @@ executeCmd cmd = do -- helpers +goldenWithRefineImports :: FilePath -> (TextDocumentIdentifier -> Session ()) -> TestTree +goldenWithRefineImports fp = goldenWithHaskellDoc refineImportsPlugin (fp <> " (golden)") testDataDir fp "expected" "hs" + testDataDir :: String testDataDir = "test" "testdata" From eab6382d71845cc2c4ea2f709b50b76945ca026f Mon Sep 17 00:00:00 2001 From: Junyoung/Clare Jang Date: Sun, 16 May 2021 00:52:15 -0400 Subject: [PATCH 14/20] Clean up retrie plugin --- plugins/hls-retrie-plugin/hls-retrie-plugin.cabal | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/plugins/hls-retrie-plugin/hls-retrie-plugin.cabal b/plugins/hls-retrie-plugin/hls-retrie-plugin.cabal index 978abeb285..2ca0e31652 100644 --- a/plugins/hls-retrie-plugin/hls-retrie-plugin.cabal +++ b/plugins/hls-retrie-plugin/hls-retrie-plugin.cabal @@ -8,8 +8,7 @@ author: Pepe Iborra maintainer: pepeiborra@gmail.com category: Development build-type: Simple -extra-source-files: - LICENSE +extra-source-files: LICENSE library exposed-modules: Ide.Plugin.Retrie @@ -22,7 +21,7 @@ library , directory , extra , ghc - , ghcide >=1.2 && <1.4 + , ghcide >=1.2 && <1.4 , hashable , hls-plugin-api ^>=1.1 , lsp From 4bc05a5490199de342b819d35476913f1bf24b9f Mon Sep 17 00:00:00 2001 From: Junyoung/Clare Jang Date: Sun, 16 May 2021 01:07:27 -0400 Subject: [PATCH 15/20] Clean up splice plugin --- .../hls-splice-plugin/hls-splice-plugin.cabal | 10 +- plugins/hls-splice-plugin/test/Main.hs | 185 ++++++++---------- ...Error.hs.error => TDeclKindError.error.hs} | 0 ...hs.expected => TDeclKindError.expected.hs} | 0 ...rExp.hs.expected => TErrorExp.expected.hs} | 0 ...rPat.hs.expected => TErrorPat.expected.hs} | 0 ...QQDecl.hs.expected => TQQDecl.expected.hs} | 0 ...{TQQExp.hs.expected => TQQExp.expected.hs} | 0 ...or.hs.expected => TQQExpError.expected.hs} | 0 ...{TQQPat.hs.expected => TQQPat.expected.hs} | 0 ...or.hs.expected => TQQPatError.expected.hs} | 0 ...QQType.hs.expected => TQQType.expected.hs} | 0 ....expected => TQQTypeTypeError.expected.hs} | 0 ...cl.hs.expected => TSimpleDecl.expected.hs} | 0 ...Exp.hs.expected => TSimpleExp.expected.hs} | 0 ...Pat.hs.expected => TSimplePat.expected.hs} | 0 ...pe.hs.expected => TSimpleType.expected.hs} | 0 ...xp.hs.expected => TTypeAppExp.expected.hs} | 0 ...Error.hs.error => TTypeKindError.error.hs} | 0 ...hs.expected => TTypeKindError.expected.hs} | 0 ...hs.expected => TTypeTypeError.expected.hs} | 0 21 files changed, 82 insertions(+), 113 deletions(-) rename plugins/hls-splice-plugin/test/testdata/{TDeclKindError.hs.error => TDeclKindError.error.hs} (100%) rename plugins/hls-splice-plugin/test/testdata/{TDeclKindError.hs.expected => TDeclKindError.expected.hs} (100%) rename plugins/hls-splice-plugin/test/testdata/{TErrorExp.hs.expected => TErrorExp.expected.hs} (100%) rename plugins/hls-splice-plugin/test/testdata/{TErrorPat.hs.expected => TErrorPat.expected.hs} (100%) rename plugins/hls-splice-plugin/test/testdata/{TQQDecl.hs.expected => TQQDecl.expected.hs} (100%) rename plugins/hls-splice-plugin/test/testdata/{TQQExp.hs.expected => TQQExp.expected.hs} (100%) rename plugins/hls-splice-plugin/test/testdata/{TQQExpError.hs.expected => TQQExpError.expected.hs} (100%) rename plugins/hls-splice-plugin/test/testdata/{TQQPat.hs.expected => TQQPat.expected.hs} (100%) rename plugins/hls-splice-plugin/test/testdata/{TQQPatError.hs.expected => TQQPatError.expected.hs} (100%) rename plugins/hls-splice-plugin/test/testdata/{TQQType.hs.expected => TQQType.expected.hs} (100%) rename plugins/hls-splice-plugin/test/testdata/{TQQTypeTypeError.hs.expected => TQQTypeTypeError.expected.hs} (100%) rename plugins/hls-splice-plugin/test/testdata/{TSimpleDecl.hs.expected => TSimpleDecl.expected.hs} (100%) rename plugins/hls-splice-plugin/test/testdata/{TSimpleExp.hs.expected => TSimpleExp.expected.hs} (100%) rename plugins/hls-splice-plugin/test/testdata/{TSimplePat.hs.expected => TSimplePat.expected.hs} (100%) rename plugins/hls-splice-plugin/test/testdata/{TSimpleType.hs.expected => TSimpleType.expected.hs} (100%) rename plugins/hls-splice-plugin/test/testdata/{TTypeAppExp.hs.expected => TTypeAppExp.expected.hs} (100%) rename plugins/hls-splice-plugin/test/testdata/{TTypeKindError.hs.error => TTypeKindError.error.hs} (100%) rename plugins/hls-splice-plugin/test/testdata/{TTypeKindError.hs.expected => TTypeKindError.expected.hs} (100%) rename plugins/hls-splice-plugin/test/testdata/{TTypeTypeError.hs.expected => TTypeTypeError.expected.hs} (100%) diff --git a/plugins/hls-splice-plugin/hls-splice-plugin.cabal b/plugins/hls-splice-plugin/hls-splice-plugin.cabal index 46dd85f8e4..9e184bd20e 100644 --- a/plugins/hls-splice-plugin/hls-splice-plugin.cabal +++ b/plugins/hls-splice-plugin/hls-splice-plugin.cabal @@ -19,8 +19,6 @@ category: Development build-type: Simple extra-source-files: LICENSE - test/testdata/*.error - test/testdata/*.expected test/testdata/*.hs test/testdata/*.yaml @@ -33,14 +31,14 @@ library hs-source-dirs: src build-depends: , aeson - , base >=4.12 && <5 + , base >=4.12 && <5 , containers , dlist , extra , foldl , ghc , ghc-exactprint - , ghcide >=1.2 && <1.4 + , ghcide >=1.2 && <1.4 , hls-plugin-api ^>=1.1 , lens , lsp @@ -64,9 +62,7 @@ test-suite tests ghc-options: -threaded -rtsopts -with-rtsopts=-N build-depends: , base - , directory - , extra , filepath , hls-splice-plugin - , hls-test-utils ^>= 1.0 + , hls-test-utils ^>=1.0 , text diff --git a/plugins/hls-splice-plugin/test/Main.hs b/plugins/hls-splice-plugin/test/Main.hs index 3fed1435df..c12640dc91 100644 --- a/plugins/hls-splice-plugin/test/Main.hs +++ b/plugins/hls-splice-plugin/test/Main.hs @@ -1,136 +1,109 @@ -{-# LANGUAGE CPP #-} -{-# LANGUAGE DataKinds #-} {-# LANGUAGE DuplicateRecordFields #-} +{-# LANGUAGE NamedFieldPuns #-} {-# LANGUAGE OverloadedStrings #-} -{-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE TypeOperators #-} {-# LANGUAGE ViewPatterns #-} -module Main (main) where +module Main + ( main + ) where -import Control.Monad +import Control.Monad (void) import Data.List (find) import Data.Text (Text) import qualified Data.Text as T import qualified Data.Text.IO as T import qualified Ide.Plugin.Splice as Splice import Ide.Plugin.Splice.Types -import System.Directory import System.FilePath -import System.Time.Extra (sleep) import Test.Hls main :: IO () main = defaultTestRunner tests -plugin :: PluginDescriptor IdeState -plugin = Splice.descriptor "splice" +splicePlugin :: PluginDescriptor IdeState +splicePlugin = Splice.descriptor "splice" tests :: TestTree -tests = - testGroup - "splice" - [ goldenTest "TSimpleExp.hs" Inplace 6 15 - , goldenTest "TSimpleExp.hs" Inplace 6 24 - , goldenTest "TTypeAppExp.hs" Inplace 7 5 - , goldenTest "TErrorExp.hs" Inplace 6 15 - , goldenTest "TErrorExp.hs" Inplace 6 51 - , goldenTest "TQQExp.hs" Inplace 6 17 - , goldenTest "TQQExp.hs" Inplace 6 25 - , goldenTest "TQQExpError.hs" Inplace 6 13 - , goldenTest "TQQExpError.hs" Inplace 6 22 - , testGroup "Pattern Splices" - [ goldenTest "TSimplePat.hs" Inplace 6 3 - , goldenTest "TSimplePat.hs" Inplace 6 22 - , goldenTest "TSimplePat.hs" Inplace 6 3 - , goldenTest "TSimplePat.hs" Inplace 6 22 - , goldenTest "TErrorPat.hs" Inplace 6 3 - , goldenTest "TErrorPat.hs" Inplace 6 18 - , goldenTest "TQQPat.hs" Inplace 6 3 - , goldenTest "TQQPat.hs" Inplace 6 11 - , goldenTest "TQQPatError.hs" Inplace 6 3 - , goldenTest "TQQPatError.hs" Inplace 6 11 - ] - , goldenTest "TSimpleType.hs" Inplace 5 12 - , goldenTest "TSimpleType.hs" Inplace 5 22 - , goldenTest "TTypeTypeError.hs" Inplace 7 12 - , goldenTest "TTypeTypeError.hs" Inplace 7 52 - , goldenTest "TQQType.hs" Inplace 8 19 - , goldenTest "TQQType.hs" Inplace 8 28 - , goldenTest "TQQTypeTypeError.hs" Inplace 8 19 - , goldenTest "TQQTypeTypeError.hs" Inplace 8 28 - , goldenTest "TSimpleDecl.hs" Inplace 8 1 - , goldenTest "TQQDecl.hs" Inplace 5 1 - , goldenTestWithEdit "TTypeKindError.hs" Inplace 7 9 - , goldenTestWithEdit "TDeclKindError.hs" Inplace 8 1 - ] +tests = testGroup "splice" + [ goldenTest "TSimpleExp" Inplace 6 15 + , goldenTest "TSimpleExp" Inplace 6 24 + , goldenTest "TTypeAppExp" Inplace 7 5 + , goldenTest "TErrorExp" Inplace 6 15 + , goldenTest "TErrorExp" Inplace 6 51 + , goldenTest "TQQExp" Inplace 6 17 + , goldenTest "TQQExp" Inplace 6 25 + , goldenTest "TQQExpError" Inplace 6 13 + , goldenTest "TQQExpError" Inplace 6 22 + , testGroup "Pattern Splices" + [ goldenTest "TSimplePat" Inplace 6 3 + , goldenTest "TSimplePat" Inplace 6 22 + , goldenTest "TSimplePat" Inplace 6 3 + , goldenTest "TSimplePat" Inplace 6 22 + , goldenTest "TErrorPat" Inplace 6 3 + , goldenTest "TErrorPat" Inplace 6 18 + , goldenTest "TQQPat" Inplace 6 3 + , goldenTest "TQQPat" Inplace 6 11 + , goldenTest "TQQPatError" Inplace 6 3 + , goldenTest "TQQPatError" Inplace 6 11 + ] + , goldenTest "TSimpleType" Inplace 5 12 + , goldenTest "TSimpleType" Inplace 5 22 + , goldenTest "TTypeTypeError" Inplace 7 12 + , goldenTest "TTypeTypeError" Inplace 7 52 + , goldenTest "TQQType" Inplace 8 19 + , goldenTest "TQQType" Inplace 8 28 + , goldenTest "TQQTypeTypeError" Inplace 8 19 + , goldenTest "TQQTypeTypeError" Inplace 8 28 + , goldenTest "TSimpleDecl" Inplace 8 1 + , goldenTest "TQQDecl" Inplace 5 1 + , goldenTestWithEdit "TTypeKindError" Inplace 7 9 + , goldenTestWithEdit "TDeclKindError" Inplace 8 1 + ] goldenTest :: FilePath -> ExpandStyle -> Int -> Int -> TestTree -goldenTest input tc line col = - testCase (input <> " (golden)") $ do - runSessionWithServer plugin spliceTestPath $ do - doc <- openDoc input "haskell" - _ <- waitForDiagnostics - actions <- getCodeActions doc $ pointRange line col - case find ((== Just (toExpandCmdTitle tc)) . codeActionTitle) actions of - Just (InR CodeAction {_command = Just c}) -> do - executeCommand c - _resp <- skipManyTill anyMessage (message SWorkspaceApplyEdit) - edited <- documentContents doc - let expected_name = input <.> "expected" - -- Write golden tests if they don't already exist - liftIO $ - (doesFileExist expected_name >>=) $ - flip unless $ do - T.writeFile expected_name edited - expected <- liftIO $ T.readFile expected_name - liftIO $ edited @?= expected - _ -> liftIO $ assertFailure "No CodeAction detected" +goldenTest fp tc line col = + goldenWithHaskellDoc splicePlugin (fp <> " (golden)") testDataDir fp "expected" "hs" $ \doc -> do + _ <- waitForDiagnostics + actions <- getCodeActions doc $ pointRange line col + case find ((== Just (toExpandCmdTitle tc)) . codeActionTitle) actions of + Just (InR CodeAction {_command = Just c}) -> do + executeCommand c + void $ skipManyTill anyMessage (message SWorkspaceApplyEdit) + _ -> liftIO $ assertFailure "No CodeAction detected" goldenTestWithEdit :: FilePath -> ExpandStyle -> Int -> Int -> TestTree -goldenTestWithEdit input tc line col = - testCase (input <> " (golden)") $ do - runSessionWithServer plugin spliceTestPath $ do - doc <- openDoc input "haskell" - orig <- documentContents doc - let lns = T.lines orig - theRange = - Range - { _start = Position 0 0 - , _end = Position (length lns + 1) 1 - } - waitForProgressDone -- cradle - waitForProgressDone - alt <- liftIO $ T.readFile (input <.> "error") - void $ applyEdit doc $ TextEdit theRange alt - changeDoc doc [TextDocumentContentChangeEvent (Just theRange) Nothing alt] - void waitForDiagnostics - actions <- getCodeActions doc $ pointRange line col - case find ((== Just (toExpandCmdTitle tc)) . codeActionTitle) actions of - Just (InR CodeAction {_command = Just c}) -> do - executeCommand c - _resp <- skipManyTill anyMessage (message SWorkspaceApplyEdit) - edited <- documentContents doc - let expected_name = input <.> "expected" - -- Write golden tests if they don't already exist - liftIO $ - (doesFileExist expected_name >>=) $ - flip unless $ do - T.writeFile expected_name edited - expected <- liftIO $ T.readFile expected_name - liftIO $ edited @?= expected - _ -> liftIO $ assertFailure "No CodeAction detected" +goldenTestWithEdit fp tc line col = + goldenWithHaskellDoc splicePlugin (fp <> " (golden)") testDataDir fp "expected" "hs" $ \doc -> do + orig <- documentContents doc + let + lns = T.lines orig + theRange = + Range + { _start = Position 0 0 + , _end = Position (length lns + 1) 1 + } + waitForProgressDone -- cradle + waitForProgressDone + alt <- liftIO $ T.readFile (fp <.> "error.hs") + void $ applyEdit doc $ TextEdit theRange alt + changeDoc doc [TextDocumentContentChangeEvent (Just theRange) Nothing alt] + void waitForDiagnostics + actions <- getCodeActions doc $ pointRange line col + case find ((== Just (toExpandCmdTitle tc)) . codeActionTitle) actions of + Just (InR CodeAction {_command = Just c}) -> do + executeCommand c + void $ skipManyTill anyMessage (message SWorkspaceApplyEdit) + _ -> liftIO $ assertFailure "No CodeAction detected" -spliceTestPath :: FilePath -spliceTestPath = "test" "testdata" +testDataDir :: FilePath +testDataDir = "test" "testdata" pointRange :: Int -> Int -> Range -pointRange - (subtract 1 -> line) - (subtract 1 -> col) = - Range (Position line col) (Position line $ col + 1) +pointRange (subtract 1 -> line) (subtract 1 -> col) = + Range (Position line col) (Position line $ col + 1) -- | Get the title of a code action. codeActionTitle :: (Command |? CodeAction) -> Maybe Text -codeActionTitle InL{} = Nothing -codeActionTitle (InR(CodeAction title _ _ _ _ _ _ _)) = Just title +codeActionTitle InL {} = Nothing +codeActionTitle (InR CodeAction {_title}) = Just _title diff --git a/plugins/hls-splice-plugin/test/testdata/TDeclKindError.hs.error b/plugins/hls-splice-plugin/test/testdata/TDeclKindError.error.hs similarity index 100% rename from plugins/hls-splice-plugin/test/testdata/TDeclKindError.hs.error rename to plugins/hls-splice-plugin/test/testdata/TDeclKindError.error.hs diff --git a/plugins/hls-splice-plugin/test/testdata/TDeclKindError.hs.expected b/plugins/hls-splice-plugin/test/testdata/TDeclKindError.expected.hs similarity index 100% rename from plugins/hls-splice-plugin/test/testdata/TDeclKindError.hs.expected rename to plugins/hls-splice-plugin/test/testdata/TDeclKindError.expected.hs diff --git a/plugins/hls-splice-plugin/test/testdata/TErrorExp.hs.expected b/plugins/hls-splice-plugin/test/testdata/TErrorExp.expected.hs similarity index 100% rename from plugins/hls-splice-plugin/test/testdata/TErrorExp.hs.expected rename to plugins/hls-splice-plugin/test/testdata/TErrorExp.expected.hs diff --git a/plugins/hls-splice-plugin/test/testdata/TErrorPat.hs.expected b/plugins/hls-splice-plugin/test/testdata/TErrorPat.expected.hs similarity index 100% rename from plugins/hls-splice-plugin/test/testdata/TErrorPat.hs.expected rename to plugins/hls-splice-plugin/test/testdata/TErrorPat.expected.hs diff --git a/plugins/hls-splice-plugin/test/testdata/TQQDecl.hs.expected b/plugins/hls-splice-plugin/test/testdata/TQQDecl.expected.hs similarity index 100% rename from plugins/hls-splice-plugin/test/testdata/TQQDecl.hs.expected rename to plugins/hls-splice-plugin/test/testdata/TQQDecl.expected.hs diff --git a/plugins/hls-splice-plugin/test/testdata/TQQExp.hs.expected b/plugins/hls-splice-plugin/test/testdata/TQQExp.expected.hs similarity index 100% rename from plugins/hls-splice-plugin/test/testdata/TQQExp.hs.expected rename to plugins/hls-splice-plugin/test/testdata/TQQExp.expected.hs diff --git a/plugins/hls-splice-plugin/test/testdata/TQQExpError.hs.expected b/plugins/hls-splice-plugin/test/testdata/TQQExpError.expected.hs similarity index 100% rename from plugins/hls-splice-plugin/test/testdata/TQQExpError.hs.expected rename to plugins/hls-splice-plugin/test/testdata/TQQExpError.expected.hs diff --git a/plugins/hls-splice-plugin/test/testdata/TQQPat.hs.expected b/plugins/hls-splice-plugin/test/testdata/TQQPat.expected.hs similarity index 100% rename from plugins/hls-splice-plugin/test/testdata/TQQPat.hs.expected rename to plugins/hls-splice-plugin/test/testdata/TQQPat.expected.hs diff --git a/plugins/hls-splice-plugin/test/testdata/TQQPatError.hs.expected b/plugins/hls-splice-plugin/test/testdata/TQQPatError.expected.hs similarity index 100% rename from plugins/hls-splice-plugin/test/testdata/TQQPatError.hs.expected rename to plugins/hls-splice-plugin/test/testdata/TQQPatError.expected.hs diff --git a/plugins/hls-splice-plugin/test/testdata/TQQType.hs.expected b/plugins/hls-splice-plugin/test/testdata/TQQType.expected.hs similarity index 100% rename from plugins/hls-splice-plugin/test/testdata/TQQType.hs.expected rename to plugins/hls-splice-plugin/test/testdata/TQQType.expected.hs diff --git a/plugins/hls-splice-plugin/test/testdata/TQQTypeTypeError.hs.expected b/plugins/hls-splice-plugin/test/testdata/TQQTypeTypeError.expected.hs similarity index 100% rename from plugins/hls-splice-plugin/test/testdata/TQQTypeTypeError.hs.expected rename to plugins/hls-splice-plugin/test/testdata/TQQTypeTypeError.expected.hs diff --git a/plugins/hls-splice-plugin/test/testdata/TSimpleDecl.hs.expected b/plugins/hls-splice-plugin/test/testdata/TSimpleDecl.expected.hs similarity index 100% rename from plugins/hls-splice-plugin/test/testdata/TSimpleDecl.hs.expected rename to plugins/hls-splice-plugin/test/testdata/TSimpleDecl.expected.hs diff --git a/plugins/hls-splice-plugin/test/testdata/TSimpleExp.hs.expected b/plugins/hls-splice-plugin/test/testdata/TSimpleExp.expected.hs similarity index 100% rename from plugins/hls-splice-plugin/test/testdata/TSimpleExp.hs.expected rename to plugins/hls-splice-plugin/test/testdata/TSimpleExp.expected.hs diff --git a/plugins/hls-splice-plugin/test/testdata/TSimplePat.hs.expected b/plugins/hls-splice-plugin/test/testdata/TSimplePat.expected.hs similarity index 100% rename from plugins/hls-splice-plugin/test/testdata/TSimplePat.hs.expected rename to plugins/hls-splice-plugin/test/testdata/TSimplePat.expected.hs diff --git a/plugins/hls-splice-plugin/test/testdata/TSimpleType.hs.expected b/plugins/hls-splice-plugin/test/testdata/TSimpleType.expected.hs similarity index 100% rename from plugins/hls-splice-plugin/test/testdata/TSimpleType.hs.expected rename to plugins/hls-splice-plugin/test/testdata/TSimpleType.expected.hs diff --git a/plugins/hls-splice-plugin/test/testdata/TTypeAppExp.hs.expected b/plugins/hls-splice-plugin/test/testdata/TTypeAppExp.expected.hs similarity index 100% rename from plugins/hls-splice-plugin/test/testdata/TTypeAppExp.hs.expected rename to plugins/hls-splice-plugin/test/testdata/TTypeAppExp.expected.hs diff --git a/plugins/hls-splice-plugin/test/testdata/TTypeKindError.hs.error b/plugins/hls-splice-plugin/test/testdata/TTypeKindError.error.hs similarity index 100% rename from plugins/hls-splice-plugin/test/testdata/TTypeKindError.hs.error rename to plugins/hls-splice-plugin/test/testdata/TTypeKindError.error.hs diff --git a/plugins/hls-splice-plugin/test/testdata/TTypeKindError.hs.expected b/plugins/hls-splice-plugin/test/testdata/TTypeKindError.expected.hs similarity index 100% rename from plugins/hls-splice-plugin/test/testdata/TTypeKindError.hs.expected rename to plugins/hls-splice-plugin/test/testdata/TTypeKindError.expected.hs diff --git a/plugins/hls-splice-plugin/test/testdata/TTypeTypeError.hs.expected b/plugins/hls-splice-plugin/test/testdata/TTypeTypeError.expected.hs similarity index 100% rename from plugins/hls-splice-plugin/test/testdata/TTypeTypeError.hs.expected rename to plugins/hls-splice-plugin/test/testdata/TTypeTypeError.expected.hs From 34093a879cc980c0bbba11b3ed744dbadbb3bd5d Mon Sep 17 00:00:00 2001 From: Junyoung/Clare Jang Date: Sun, 16 May 2021 01:13:59 -0400 Subject: [PATCH 16/20] Clean up stylish haskell plugin --- .../hls-stylish-haskell-plugin.cabal | 6 ++-- .../src/Ide/Plugin/StylishHaskell.hs | 4 +-- .../hls-stylish-haskell-plugin/test/Main.hs | 28 ++++++++++--------- .../test/testdata/hie.yaml | 2 ++ 4 files changed, 20 insertions(+), 20 deletions(-) create mode 100644 plugins/hls-stylish-haskell-plugin/test/testdata/hie.yaml diff --git a/plugins/hls-stylish-haskell-plugin/hls-stylish-haskell-plugin.cabal b/plugins/hls-stylish-haskell-plugin/hls-stylish-haskell-plugin.cabal index 6231cd32de..de1d58f20e 100644 --- a/plugins/hls-stylish-haskell-plugin/hls-stylish-haskell-plugin.cabal +++ b/plugins/hls-stylish-haskell-plugin/hls-stylish-haskell-plugin.cabal @@ -22,10 +22,9 @@ library , filepath , ghc , ghc-boot-th - , ghcide >=1.2 && <1.4 + , ghcide >=1.2 && <1.4 , hls-plugin-api ^>=1.1 , lsp-types - , mtl , stylish-haskell ^>=0.12 , text @@ -39,7 +38,6 @@ test-suite tests ghc-options: -threaded -rtsopts -with-rtsopts=-N build-depends: , base - , bytestring + , filepath , hls-stylish-haskell-plugin , hls-test-utils ^>=1.0 - , text diff --git a/plugins/hls-stylish-haskell-plugin/src/Ide/Plugin/StylishHaskell.hs b/plugins/hls-stylish-haskell-plugin/src/Ide/Plugin/StylishHaskell.hs index 5f610b3c8b..9082c2b634 100644 --- a/plugins/hls-stylish-haskell-plugin/src/Ide/Plugin/StylishHaskell.hs +++ b/plugins/hls-stylish-haskell-plugin/src/Ide/Plugin/StylishHaskell.hs @@ -1,7 +1,6 @@ {-# LANGUAGE OverloadedStrings #-} module Ide.Plugin.StylishHaskell - ( - descriptor + ( descriptor , provider ) where @@ -18,7 +17,6 @@ import Ide.PluginUtils import Ide.Types import Language.Haskell.Stylish import Language.LSP.Types as J - import System.Directory import System.FilePath diff --git a/plugins/hls-stylish-haskell-plugin/test/Main.hs b/plugins/hls-stylish-haskell-plugin/test/Main.hs index 311e43172a..35513dd1b9 100644 --- a/plugins/hls-stylish-haskell-plugin/test/Main.hs +++ b/plugins/hls-stylish-haskell-plugin/test/Main.hs @@ -1,26 +1,28 @@ {-# 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.StylishHaskell as StylishHaskell +import System.FilePath import Test.Hls main :: IO () main = defaultTestRunner tests -plugin :: PluginDescriptor IdeState -plugin = StylishHaskell.descriptor "stylishHaskell" +stylishHaskellPlugin :: PluginDescriptor IdeState +stylishHaskellPlugin = StylishHaskell.descriptor "stylishHaskell" tests :: TestTree -tests = testGroup "stylish-haskell" [ - goldenGitDiff "formats a document" "test/testdata/StylishHaskell.formatted_document.hs" $ runSessionWithServerFormatter plugin "stylishHaskell" "test/testdata" $ do - doc <- openDoc "StylishHaskell.hs" "haskell" +tests = testGroup "stylish-haskell" + [ goldenWithStylishHaskell "formats a document" "StylishHaskell" "formatted_document" $ \doc -> do formatDoc doc (FormattingOptions 2 True Nothing Nothing Nothing) - BS.fromStrict . T.encodeUtf8 <$> documentContents doc - , goldenGitDiff "formats a range" "test/testdata/StylishHaskell.formatted_range.hs" $ runSessionWithServerFormatter plugin "stylishHaskell" "test/testdata" $ do - doc <- openDoc "StylishHaskell.hs" "haskell" + , goldenWithStylishHaskell "formats a range" "StylishHaskell" "formatted_range" $ \doc -> do formatRange doc (FormattingOptions 2 True Nothing Nothing Nothing) (Range (Position 0 0) (Position 2 21)) - BS.fromStrict . T.encodeUtf8 <$> documentContents doc ] + +goldenWithStylishHaskell :: TestName -> FilePath -> FilePath -> (TextDocumentIdentifier -> Session ()) -> TestTree +goldenWithStylishHaskell title fp desc = goldenWithHaskellDoc stylishHaskellPlugin title testDataDir fp desc "hs" + +testDataDir :: FilePath +testDataDir = "test" "data" diff --git a/plugins/hls-stylish-haskell-plugin/test/testdata/hie.yaml b/plugins/hls-stylish-haskell-plugin/test/testdata/hie.yaml new file mode 100644 index 0000000000..47db6b9bc8 --- /dev/null +++ b/plugins/hls-stylish-haskell-plugin/test/testdata/hie.yaml @@ -0,0 +1,2 @@ +cradle: + direct: From e71318ebf1a5264f4f274906697f21795123cbe0 Mon Sep 17 00:00:00 2001 From: Junyoung/Clare Jang Date: Sun, 16 May 2021 14:00:08 -0400 Subject: [PATCH 17/20] Fix formatter tests --- hls-test-utils/src/Test/Hls.hs | 20 +++++++++++++++++++ plugins/hls-brittany-plugin/test/Main.hs | 2 +- plugins/hls-floskell-plugin/test/Main.hs | 2 +- plugins/hls-fourmolu-plugin/test/Main.hs | 2 +- .../test/testdata/Fourmolu.formatted.hs | 2 +- plugins/hls-ormolu-plugin/test/Main.hs | 2 +- .../hls-stylish-haskell-plugin/test/Main.hs | 4 ++-- 7 files changed, 27 insertions(+), 7 deletions(-) diff --git a/hls-test-utils/src/Test/Hls.hs b/hls-test-utils/src/Test/Hls.hs index 4c081f6ebe..2f37196a20 100644 --- a/hls-test-utils/src/Test/Hls.hs +++ b/hls-test-utils/src/Test/Hls.hs @@ -13,6 +13,7 @@ module Test.Hls defaultTestRunner, goldenGitDiff, goldenWithHaskellDoc, + goldenWithHaskellDocFormatter, def, runSessionWithServer, runSessionWithServerFormatter, @@ -90,6 +91,25 @@ goldenWithHaskellDoc plugin title testDataDir path desc ext act = 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 diff --git a/plugins/hls-brittany-plugin/test/Main.hs b/plugins/hls-brittany-plugin/test/Main.hs index 258532442d..2a4ef9f7d4 100644 --- a/plugins/hls-brittany-plugin/test/Main.hs +++ b/plugins/hls-brittany-plugin/test/Main.hs @@ -31,7 +31,7 @@ tests = testGroup "brittany" ] brittanyGolden :: TestName -> FilePath -> FilePath -> (TextDocumentIdentifier -> Session ()) -> TestTree -brittanyGolden title path desc = goldenWithHaskellDoc brittanyPlugin title testDataDir path desc "hs" +brittanyGolden title path desc = goldenWithHaskellDocFormatter brittanyPlugin "brittany" title testDataDir path desc "hs" testDataDir :: FilePath testDataDir = "test" "testdata" diff --git a/plugins/hls-floskell-plugin/test/Main.hs b/plugins/hls-floskell-plugin/test/Main.hs index 162230b94d..e63aee2f2e 100644 --- a/plugins/hls-floskell-plugin/test/Main.hs +++ b/plugins/hls-floskell-plugin/test/Main.hs @@ -24,7 +24,7 @@ tests = testGroup "floskell" ] goldenWithFloskell :: TestName -> FilePath -> FilePath -> (TextDocumentIdentifier -> Session ()) -> TestTree -goldenWithFloskell title path desc = goldenWithHaskellDoc floskellPlugin title testDataDir path desc "hs" +goldenWithFloskell title path desc = goldenWithHaskellDocFormatter floskellPlugin "floskell" title testDataDir path desc "hs" testDataDir :: FilePath testDataDir = "test" "testdata" diff --git a/plugins/hls-fourmolu-plugin/test/Main.hs b/plugins/hls-fourmolu-plugin/test/Main.hs index b10e900ae0..a33b505790 100644 --- a/plugins/hls-fourmolu-plugin/test/Main.hs +++ b/plugins/hls-fourmolu-plugin/test/Main.hs @@ -24,7 +24,7 @@ tests = testGroup "fourmolu" ] goldenWithFourmolu :: TestName -> FilePath -> FilePath -> (TextDocumentIdentifier -> Session ()) -> TestTree -goldenWithFourmolu title path desc = goldenWithHaskellDoc fourmoluPlugin title testDataDir path desc "hs" +goldenWithFourmolu title path desc = goldenWithHaskellDocFormatter fourmoluPlugin "fourmolu" title testDataDir path desc "hs" testDataDir :: FilePath testDataDir = "test" "testdata" diff --git a/plugins/hls-fourmolu-plugin/test/testdata/Fourmolu.formatted.hs b/plugins/hls-fourmolu-plugin/test/testdata/Fourmolu.formatted.hs index 5342473189..bdc198b408 100644 --- a/plugins/hls-fourmolu-plugin/test/testdata/Fourmolu.formatted.hs +++ b/plugins/hls-fourmolu-plugin/test/testdata/Fourmolu.formatted.hs @@ -1,4 +1,4 @@ -module Format where +module Fourmolu where import Data.List diff --git a/plugins/hls-ormolu-plugin/test/Main.hs b/plugins/hls-ormolu-plugin/test/Main.hs index ffb34f3f63..d42cc7fb91 100644 --- a/plugins/hls-ormolu-plugin/test/Main.hs +++ b/plugins/hls-ormolu-plugin/test/Main.hs @@ -23,7 +23,7 @@ tests = testGroup "ormolu" ] goldenWithOrmolu :: TestName -> FilePath -> FilePath -> (TextDocumentIdentifier -> Session ()) -> TestTree -goldenWithOrmolu title path desc = goldenWithHaskellDoc ormoluPlugin title testDataDir path desc "hs" +goldenWithOrmolu title path desc = goldenWithHaskellDocFormatter ormoluPlugin "ormolu" title testDataDir path desc "hs" testDataDir :: FilePath testDataDir = "test" "testdata" diff --git a/plugins/hls-stylish-haskell-plugin/test/Main.hs b/plugins/hls-stylish-haskell-plugin/test/Main.hs index 35513dd1b9..d8cc09157f 100644 --- a/plugins/hls-stylish-haskell-plugin/test/Main.hs +++ b/plugins/hls-stylish-haskell-plugin/test/Main.hs @@ -22,7 +22,7 @@ tests = testGroup "stylish-haskell" ] goldenWithStylishHaskell :: TestName -> FilePath -> FilePath -> (TextDocumentIdentifier -> Session ()) -> TestTree -goldenWithStylishHaskell title fp desc = goldenWithHaskellDoc stylishHaskellPlugin title testDataDir fp desc "hs" +goldenWithStylishHaskell title fp desc = goldenWithHaskellDocFormatter stylishHaskellPlugin "stylishHaskell" title testDataDir fp desc "hs" testDataDir :: FilePath -testDataDir = "test" "data" +testDataDir = "test" "testdata" From 14b5425f6a2d8ebd2f342a58f81c425c6652fb09 Mon Sep 17 00:00:00 2001 From: Junyoung/Clare Jang Date: Sun, 16 May 2021 14:22:04 -0400 Subject: [PATCH 18/20] Fix tests' hie.yaml --- plugins/hls-brittany-plugin/test/testdata/hie.yaml | 1 + plugins/hls-class-plugin/test/testdata/hie.yaml | 1 + plugins/hls-floskell-plugin/test/testdata/hie.yaml | 1 + plugins/hls-fourmolu-plugin/test/testdata/hie.yaml | 1 + plugins/hls-haddock-comments-plugin/test/testdata/hie.yaml | 1 + plugins/hls-ormolu-plugin/test/testdata/hie.yaml | 1 + plugins/hls-stylish-haskell-plugin/test/testdata/hie.yaml | 1 + 7 files changed, 7 insertions(+) diff --git a/plugins/hls-brittany-plugin/test/testdata/hie.yaml b/plugins/hls-brittany-plugin/test/testdata/hie.yaml index 47db6b9bc8..824558147d 100644 --- a/plugins/hls-brittany-plugin/test/testdata/hie.yaml +++ b/plugins/hls-brittany-plugin/test/testdata/hie.yaml @@ -1,2 +1,3 @@ cradle: direct: + arguments: [] diff --git a/plugins/hls-class-plugin/test/testdata/hie.yaml b/plugins/hls-class-plugin/test/testdata/hie.yaml index 47db6b9bc8..824558147d 100644 --- a/plugins/hls-class-plugin/test/testdata/hie.yaml +++ b/plugins/hls-class-plugin/test/testdata/hie.yaml @@ -1,2 +1,3 @@ cradle: direct: + arguments: [] diff --git a/plugins/hls-floskell-plugin/test/testdata/hie.yaml b/plugins/hls-floskell-plugin/test/testdata/hie.yaml index 47db6b9bc8..824558147d 100644 --- a/plugins/hls-floskell-plugin/test/testdata/hie.yaml +++ b/plugins/hls-floskell-plugin/test/testdata/hie.yaml @@ -1,2 +1,3 @@ cradle: direct: + arguments: [] diff --git a/plugins/hls-fourmolu-plugin/test/testdata/hie.yaml b/plugins/hls-fourmolu-plugin/test/testdata/hie.yaml index 47db6b9bc8..824558147d 100644 --- a/plugins/hls-fourmolu-plugin/test/testdata/hie.yaml +++ b/plugins/hls-fourmolu-plugin/test/testdata/hie.yaml @@ -1,2 +1,3 @@ cradle: direct: + arguments: [] diff --git a/plugins/hls-haddock-comments-plugin/test/testdata/hie.yaml b/plugins/hls-haddock-comments-plugin/test/testdata/hie.yaml index 47db6b9bc8..824558147d 100644 --- a/plugins/hls-haddock-comments-plugin/test/testdata/hie.yaml +++ b/plugins/hls-haddock-comments-plugin/test/testdata/hie.yaml @@ -1,2 +1,3 @@ cradle: direct: + arguments: [] diff --git a/plugins/hls-ormolu-plugin/test/testdata/hie.yaml b/plugins/hls-ormolu-plugin/test/testdata/hie.yaml index 47db6b9bc8..824558147d 100644 --- a/plugins/hls-ormolu-plugin/test/testdata/hie.yaml +++ b/plugins/hls-ormolu-plugin/test/testdata/hie.yaml @@ -1,2 +1,3 @@ cradle: direct: + arguments: [] diff --git a/plugins/hls-stylish-haskell-plugin/test/testdata/hie.yaml b/plugins/hls-stylish-haskell-plugin/test/testdata/hie.yaml index 47db6b9bc8..824558147d 100644 --- a/plugins/hls-stylish-haskell-plugin/test/testdata/hie.yaml +++ b/plugins/hls-stylish-haskell-plugin/test/testdata/hie.yaml @@ -1,2 +1,3 @@ cradle: direct: + arguments: [] From f0c006216c5137b66cdd4d51ec61f464db1b4842 Mon Sep 17 00:00:00 2001 From: Junyoung/Clare Jang Date: Sun, 16 May 2021 14:27:33 -0400 Subject: [PATCH 19/20] Clean up Wingman --- .../hls-tactics-plugin.cabal | 17 ++- .../test/CodeAction/AutoSpec.hs | 119 +++++++++--------- .../test/CodeAction/DestructAllSpec.hs | 21 ++-- .../test/CodeAction/DestructPunSpec.hs | 17 +-- .../test/CodeAction/DestructSpec.hs | 41 +++--- .../test/CodeAction/IntrosSpec.hs | 9 +- .../test/CodeAction/RefineSpec.hs | 17 +-- .../test/CodeAction/RunMetaprogramSpec.hs | 21 ++-- .../test/CodeAction/UseDataConSpec.hs | 19 ++- .../test/CodeLens/EmptyCaseSpec.hs | 19 ++- .../hls-tactics-plugin/test/ProviderSpec.hs | 27 ++-- plugins/hls-tactics-plugin/test/Utils.hs | 14 +-- ...s.expected => AutoEmptyString.expected.hs} | 0 ...oEndo.hs.expected => AutoEndo.expected.hs} | 0 ...hs.expected => AutoInfixApply.expected.hs} | 0 ...xpected => AutoInfixApplyMany.expected.hs} | 0 ...hs.expected => AutoInfixInfix.expected.hs} | 0 ....hs.expected => AutoPatSynUse.expected.hs} | 0 ....hs.expected => AutoSplitGADT.expected.hs} | 0 ...hs.expected => AutoThetaEqCtx.expected.hs} | 0 ...s.expected => AutoThetaEqGADT.expected.hs} | 0 ...ed => AutoThetaEqGADTDestruct.expected.hs} | 0 ...x.hs.expected => AutoThetaFix.expected.hs} | 0 ....hs.expected => AutoThetaGADT.expected.hs} | 0 ...cted => AutoThetaGADTDestruct.expected.hs} | 0 ...hs.expected => AutoThetaRankN.expected.hs} | 0 ....hs.expected => AutoThetaRefl.expected.hs} | 0 ...cted => AutoThetaReflDestruct.expected.hs} | 0 ...utoZip.hs.expected => AutoZip.expected.hs} | 0 ...hs.expected => DestructAllAnd.expected.hs} | 0 ...s.expected => DestructAllFunc.expected.hs} | 0 ...s.expected => DestructAllMany.expected.hs} | 0 ... => DestructAllNonVarTopMatch.expected.hs} | 0 ...s.expected => DestructCthulhu.expected.hs} | 0 ...un.hs.expected => DestructPun.expected.hs} | 0 ...T.hs.expected => EmptyCaseADT.expected.hs} | 0 ...hs.expected => EmptyCaseApply.expected.hs} | 0 ....hs.expected => EmptyCaseGADT.expected.hs} | 0 ...s.expected => EmptyCaseNested.expected.hs} | 0 ...s.expected => EmptyCaseParens.expected.hs} | 0 ...s.expected => EmptyCaseShadow.expected.hs} | 0 .../{Fgmap.hs.expected => Fgmap.expected.hs} | 0 ...pBoth.hs.expected => FmapBoth.expected.hs} | 0 ...pJoin.hs.expected => FmapJoin.expected.hs} | 0 ....hs.expected => FmapJoinInLet.expected.hs} | 0 ...s.expected => GoldenArbitrary.expected.hs} | 0 ...hs.expected => GoldenBigTuple.expected.hs} | 0 ....expected => GoldenEitherAuto.expected.hs} | 0 ...ed => GoldenEitherHomomorphic.expected.hs} | 0 ...hs.expected => GoldenFmapTree.expected.hs} | 0 ...dr.hs.expected => GoldenFoldr.expected.hs} | 0 ...s.expected => GoldenFromMaybe.expected.hs} | 0 ...hs.expected => GoldenGADTAuto.expected.hs} | 0 ...xpected => GoldenGADTDestruct.expected.hs} | 0 ...=> GoldenGADTDestructCoercion.expected.hs} | 0 ...s.expected => GoldenIdTypeFam.expected.hs} | 0 ...cted => GoldenIdentityFunctor.expected.hs} | 0 ...s.hs.expected => GoldenIntros.expected.hs} | 0 ...hs.expected => GoldenJoinCont.expected.hs} | 0 ...hs.expected => GoldenListFmap.expected.hs} | 0 ...ote.hs.expected => GoldenNote.expected.hs} | 0 ...hs.expected => GoldenPureList.expected.hs} | 0 ...hs.expected => GoldenSafeHead.expected.hs} | 0 ...how.hs.expected => GoldenShow.expected.hs} | 0 ...expected => GoldenShowCompose.expected.hs} | 0 ...expected => GoldenShowMapChar.expected.hs} | 0 ....expected => GoldenSuperclass.expected.hs} | 0 ...wap.hs.expected => GoldenSwap.expected.hs} | 0 ...hs.expected => GoldenSwapMany.expected.hs} | 0 ...expected => KnownBigSemigroup.expected.hs} | 0 ... KnownCounterfactualSemigroup.expected.hs} | 0 ...d => KnownDestructedSemigroup.expected.hs} | 0 ...xpected => KnownMissingMonoid.expected.hs} | 0 ...cted => KnownMissingSemigroup.expected.hs} | 0 ... KnownModuleInstanceSemigroup.expected.hs} | 0 ...id.hs.expected => KnownMonoid.expected.hs} | 0 ...s.expected => KnownPolyMonoid.expected.hs} | 0 ...pected => KnownThetaSemigroup.expected.hs} | 0 ...ind.hs.expected => LayoutBind.expected.hs} | 0 ...s.expected => LayoutDollarApp.expected.hs} | 0 ...tLam.hs.expected => LayoutLam.expected.hs} | 0 ...pp.hs.expected => LayoutOpApp.expected.hs} | 0 ....expected => LayoutSplitClass.expected.hs} | 0 ....expected => LayoutSplitGuard.expected.hs} | 0 ....hs.expected => LayoutSplitIn.expected.hs} | 0 ...hs.expected => LayoutSplitLet.expected.hs} | 0 ...expected => LayoutSplitPatSyn.expected.hs} | 0 ...xpected => LayoutSplitPattern.expected.hs} | 0 ...xpected => LayoutSplitViewPat.expected.hs} | 0 ....expected => LayoutSplitWhere.expected.hs} | 0 ...egin.hs.expected => MetaBegin.expected.hs} | 0 ...ll.hs.expected => MetaBindAll.expected.hs} | 0 ...ne.hs.expected => MetaBindOne.expected.hs} | 0 ...ice.hs.expected => MetaChoice.expected.hs} | 0 ...Ap.hs.expected => MetaMaybeAp.expected.hs} | 0 ...etaTry.hs.expected => MetaTry.expected.hs} | 0 ....hs.expected => NewtypeRecord.expected.hs} | 0 ...unGADT.hs.expected => PunGADT.expected.hs} | 0 ...unMany.hs.expected => PunMany.expected.hs} | 0 ...DT.hs.expected => PunManyGADT.expected.hs} | 0 ...g.hs.expected => PunShadowing.expected.hs} | 0 ...mple.hs.expected => PunSimple.expected.hs} | 0 ...dCon.hs.expected => RecordCon.expected.hs} | 0 ...eCon.hs.expected => RefineCon.expected.hs} | 0 ...ADT.hs.expected => RefineGADT.expected.hs} | 0 ...ro.hs.expected => RefineIntro.expected.hs} | 0 ...r.hs.expected => RefineReader.expected.hs} | 0 ...n.hs.expected => SplitPattern.expected.hs} | 0 ...eft.hs.expected => UseConLeft.expected.hs} | 0 ...air.hs.expected => UseConPair.expected.hs} | 0 ...ht.hs.expected => UseConRight.expected.hs} | 0 111 files changed, 145 insertions(+), 196 deletions(-) rename plugins/hls-tactics-plugin/test/golden/{AutoEmptyString.hs.expected => AutoEmptyString.expected.hs} (100%) rename plugins/hls-tactics-plugin/test/golden/{AutoEndo.hs.expected => AutoEndo.expected.hs} (100%) rename plugins/hls-tactics-plugin/test/golden/{AutoInfixApply.hs.expected => AutoInfixApply.expected.hs} (100%) rename plugins/hls-tactics-plugin/test/golden/{AutoInfixApplyMany.hs.expected => AutoInfixApplyMany.expected.hs} (100%) rename plugins/hls-tactics-plugin/test/golden/{AutoInfixInfix.hs.expected => AutoInfixInfix.expected.hs} (100%) rename plugins/hls-tactics-plugin/test/golden/{AutoPatSynUse.hs.expected => AutoPatSynUse.expected.hs} (100%) rename plugins/hls-tactics-plugin/test/golden/{AutoSplitGADT.hs.expected => AutoSplitGADT.expected.hs} (100%) rename plugins/hls-tactics-plugin/test/golden/{AutoThetaEqCtx.hs.expected => AutoThetaEqCtx.expected.hs} (100%) rename plugins/hls-tactics-plugin/test/golden/{AutoThetaEqGADT.hs.expected => AutoThetaEqGADT.expected.hs} (100%) rename plugins/hls-tactics-plugin/test/golden/{AutoThetaEqGADTDestruct.hs.expected => AutoThetaEqGADTDestruct.expected.hs} (100%) rename plugins/hls-tactics-plugin/test/golden/{AutoThetaFix.hs.expected => AutoThetaFix.expected.hs} (100%) rename plugins/hls-tactics-plugin/test/golden/{AutoThetaGADT.hs.expected => AutoThetaGADT.expected.hs} (100%) rename plugins/hls-tactics-plugin/test/golden/{AutoThetaGADTDestruct.hs.expected => AutoThetaGADTDestruct.expected.hs} (100%) rename plugins/hls-tactics-plugin/test/golden/{AutoThetaRankN.hs.expected => AutoThetaRankN.expected.hs} (100%) rename plugins/hls-tactics-plugin/test/golden/{AutoThetaRefl.hs.expected => AutoThetaRefl.expected.hs} (100%) rename plugins/hls-tactics-plugin/test/golden/{AutoThetaReflDestruct.hs.expected => AutoThetaReflDestruct.expected.hs} (100%) rename plugins/hls-tactics-plugin/test/golden/{AutoZip.hs.expected => AutoZip.expected.hs} (100%) rename plugins/hls-tactics-plugin/test/golden/{DestructAllAnd.hs.expected => DestructAllAnd.expected.hs} (100%) rename plugins/hls-tactics-plugin/test/golden/{DestructAllFunc.hs.expected => DestructAllFunc.expected.hs} (100%) rename plugins/hls-tactics-plugin/test/golden/{DestructAllMany.hs.expected => DestructAllMany.expected.hs} (100%) rename plugins/hls-tactics-plugin/test/golden/{DestructAllNonVarTopMatch.hs.expected => DestructAllNonVarTopMatch.expected.hs} (100%) rename plugins/hls-tactics-plugin/test/golden/{DestructCthulhu.hs.expected => DestructCthulhu.expected.hs} (100%) rename plugins/hls-tactics-plugin/test/golden/{DestructPun.hs.expected => DestructPun.expected.hs} (100%) rename plugins/hls-tactics-plugin/test/golden/{EmptyCaseADT.hs.expected => EmptyCaseADT.expected.hs} (100%) rename plugins/hls-tactics-plugin/test/golden/{EmptyCaseApply.hs.expected => EmptyCaseApply.expected.hs} (100%) rename plugins/hls-tactics-plugin/test/golden/{EmptyCaseGADT.hs.expected => EmptyCaseGADT.expected.hs} (100%) rename plugins/hls-tactics-plugin/test/golden/{EmptyCaseNested.hs.expected => EmptyCaseNested.expected.hs} (100%) rename plugins/hls-tactics-plugin/test/golden/{EmptyCaseParens.hs.expected => EmptyCaseParens.expected.hs} (100%) rename plugins/hls-tactics-plugin/test/golden/{EmptyCaseShadow.hs.expected => EmptyCaseShadow.expected.hs} (100%) rename plugins/hls-tactics-plugin/test/golden/{Fgmap.hs.expected => Fgmap.expected.hs} (100%) rename plugins/hls-tactics-plugin/test/golden/{FmapBoth.hs.expected => FmapBoth.expected.hs} (100%) rename plugins/hls-tactics-plugin/test/golden/{FmapJoin.hs.expected => FmapJoin.expected.hs} (100%) rename plugins/hls-tactics-plugin/test/golden/{FmapJoinInLet.hs.expected => FmapJoinInLet.expected.hs} (100%) rename plugins/hls-tactics-plugin/test/golden/{GoldenArbitrary.hs.expected => GoldenArbitrary.expected.hs} (100%) rename plugins/hls-tactics-plugin/test/golden/{GoldenBigTuple.hs.expected => GoldenBigTuple.expected.hs} (100%) rename plugins/hls-tactics-plugin/test/golden/{GoldenEitherAuto.hs.expected => GoldenEitherAuto.expected.hs} (100%) rename plugins/hls-tactics-plugin/test/golden/{GoldenEitherHomomorphic.hs.expected => GoldenEitherHomomorphic.expected.hs} (100%) rename plugins/hls-tactics-plugin/test/golden/{GoldenFmapTree.hs.expected => GoldenFmapTree.expected.hs} (100%) rename plugins/hls-tactics-plugin/test/golden/{GoldenFoldr.hs.expected => GoldenFoldr.expected.hs} (100%) rename plugins/hls-tactics-plugin/test/golden/{GoldenFromMaybe.hs.expected => GoldenFromMaybe.expected.hs} (100%) rename plugins/hls-tactics-plugin/test/golden/{GoldenGADTAuto.hs.expected => GoldenGADTAuto.expected.hs} (100%) rename plugins/hls-tactics-plugin/test/golden/{GoldenGADTDestruct.hs.expected => GoldenGADTDestruct.expected.hs} (100%) rename plugins/hls-tactics-plugin/test/golden/{GoldenGADTDestructCoercion.hs.expected => GoldenGADTDestructCoercion.expected.hs} (100%) rename plugins/hls-tactics-plugin/test/golden/{GoldenIdTypeFam.hs.expected => GoldenIdTypeFam.expected.hs} (100%) rename plugins/hls-tactics-plugin/test/golden/{GoldenIdentityFunctor.hs.expected => GoldenIdentityFunctor.expected.hs} (100%) rename plugins/hls-tactics-plugin/test/golden/{GoldenIntros.hs.expected => GoldenIntros.expected.hs} (100%) rename plugins/hls-tactics-plugin/test/golden/{GoldenJoinCont.hs.expected => GoldenJoinCont.expected.hs} (100%) rename plugins/hls-tactics-plugin/test/golden/{GoldenListFmap.hs.expected => GoldenListFmap.expected.hs} (100%) rename plugins/hls-tactics-plugin/test/golden/{GoldenNote.hs.expected => GoldenNote.expected.hs} (100%) rename plugins/hls-tactics-plugin/test/golden/{GoldenPureList.hs.expected => GoldenPureList.expected.hs} (100%) rename plugins/hls-tactics-plugin/test/golden/{GoldenSafeHead.hs.expected => GoldenSafeHead.expected.hs} (100%) rename plugins/hls-tactics-plugin/test/golden/{GoldenShow.hs.expected => GoldenShow.expected.hs} (100%) rename plugins/hls-tactics-plugin/test/golden/{GoldenShowCompose.hs.expected => GoldenShowCompose.expected.hs} (100%) rename plugins/hls-tactics-plugin/test/golden/{GoldenShowMapChar.hs.expected => GoldenShowMapChar.expected.hs} (100%) rename plugins/hls-tactics-plugin/test/golden/{GoldenSuperclass.hs.expected => GoldenSuperclass.expected.hs} (100%) rename plugins/hls-tactics-plugin/test/golden/{GoldenSwap.hs.expected => GoldenSwap.expected.hs} (100%) rename plugins/hls-tactics-plugin/test/golden/{GoldenSwapMany.hs.expected => GoldenSwapMany.expected.hs} (100%) rename plugins/hls-tactics-plugin/test/golden/{KnownBigSemigroup.hs.expected => KnownBigSemigroup.expected.hs} (100%) rename plugins/hls-tactics-plugin/test/golden/{KnownCounterfactualSemigroup.hs.expected => KnownCounterfactualSemigroup.expected.hs} (100%) rename plugins/hls-tactics-plugin/test/golden/{KnownDestructedSemigroup.hs.expected => KnownDestructedSemigroup.expected.hs} (100%) rename plugins/hls-tactics-plugin/test/golden/{KnownMissingMonoid.hs.expected => KnownMissingMonoid.expected.hs} (100%) rename plugins/hls-tactics-plugin/test/golden/{KnownMissingSemigroup.hs.expected => KnownMissingSemigroup.expected.hs} (100%) rename plugins/hls-tactics-plugin/test/golden/{KnownModuleInstanceSemigroup.hs.expected => KnownModuleInstanceSemigroup.expected.hs} (100%) rename plugins/hls-tactics-plugin/test/golden/{KnownMonoid.hs.expected => KnownMonoid.expected.hs} (100%) rename plugins/hls-tactics-plugin/test/golden/{KnownPolyMonoid.hs.expected => KnownPolyMonoid.expected.hs} (100%) rename plugins/hls-tactics-plugin/test/golden/{KnownThetaSemigroup.hs.expected => KnownThetaSemigroup.expected.hs} (100%) rename plugins/hls-tactics-plugin/test/golden/{LayoutBind.hs.expected => LayoutBind.expected.hs} (100%) rename plugins/hls-tactics-plugin/test/golden/{LayoutDollarApp.hs.expected => LayoutDollarApp.expected.hs} (100%) rename plugins/hls-tactics-plugin/test/golden/{LayoutLam.hs.expected => LayoutLam.expected.hs} (100%) rename plugins/hls-tactics-plugin/test/golden/{LayoutOpApp.hs.expected => LayoutOpApp.expected.hs} (100%) rename plugins/hls-tactics-plugin/test/golden/{LayoutSplitClass.hs.expected => LayoutSplitClass.expected.hs} (100%) rename plugins/hls-tactics-plugin/test/golden/{LayoutSplitGuard.hs.expected => LayoutSplitGuard.expected.hs} (100%) rename plugins/hls-tactics-plugin/test/golden/{LayoutSplitIn.hs.expected => LayoutSplitIn.expected.hs} (100%) rename plugins/hls-tactics-plugin/test/golden/{LayoutSplitLet.hs.expected => LayoutSplitLet.expected.hs} (100%) rename plugins/hls-tactics-plugin/test/golden/{LayoutSplitPatSyn.hs.expected => LayoutSplitPatSyn.expected.hs} (100%) rename plugins/hls-tactics-plugin/test/golden/{LayoutSplitPattern.hs.expected => LayoutSplitPattern.expected.hs} (100%) rename plugins/hls-tactics-plugin/test/golden/{LayoutSplitViewPat.hs.expected => LayoutSplitViewPat.expected.hs} (100%) rename plugins/hls-tactics-plugin/test/golden/{LayoutSplitWhere.hs.expected => LayoutSplitWhere.expected.hs} (100%) rename plugins/hls-tactics-plugin/test/golden/{MetaBegin.hs.expected => MetaBegin.expected.hs} (100%) rename plugins/hls-tactics-plugin/test/golden/{MetaBindAll.hs.expected => MetaBindAll.expected.hs} (100%) rename plugins/hls-tactics-plugin/test/golden/{MetaBindOne.hs.expected => MetaBindOne.expected.hs} (100%) rename plugins/hls-tactics-plugin/test/golden/{MetaChoice.hs.expected => MetaChoice.expected.hs} (100%) rename plugins/hls-tactics-plugin/test/golden/{MetaMaybeAp.hs.expected => MetaMaybeAp.expected.hs} (100%) rename plugins/hls-tactics-plugin/test/golden/{MetaTry.hs.expected => MetaTry.expected.hs} (100%) rename plugins/hls-tactics-plugin/test/golden/{NewtypeRecord.hs.expected => NewtypeRecord.expected.hs} (100%) rename plugins/hls-tactics-plugin/test/golden/{PunGADT.hs.expected => PunGADT.expected.hs} (100%) rename plugins/hls-tactics-plugin/test/golden/{PunMany.hs.expected => PunMany.expected.hs} (100%) rename plugins/hls-tactics-plugin/test/golden/{PunManyGADT.hs.expected => PunManyGADT.expected.hs} (100%) rename plugins/hls-tactics-plugin/test/golden/{PunShadowing.hs.expected => PunShadowing.expected.hs} (100%) rename plugins/hls-tactics-plugin/test/golden/{PunSimple.hs.expected => PunSimple.expected.hs} (100%) rename plugins/hls-tactics-plugin/test/golden/{RecordCon.hs.expected => RecordCon.expected.hs} (100%) rename plugins/hls-tactics-plugin/test/golden/{RefineCon.hs.expected => RefineCon.expected.hs} (100%) rename plugins/hls-tactics-plugin/test/golden/{RefineGADT.hs.expected => RefineGADT.expected.hs} (100%) rename plugins/hls-tactics-plugin/test/golden/{RefineIntro.hs.expected => RefineIntro.expected.hs} (100%) rename plugins/hls-tactics-plugin/test/golden/{RefineReader.hs.expected => RefineReader.expected.hs} (100%) rename plugins/hls-tactics-plugin/test/golden/{SplitPattern.hs.expected => SplitPattern.expected.hs} (100%) rename plugins/hls-tactics-plugin/test/golden/{UseConLeft.hs.expected => UseConLeft.expected.hs} (100%) rename plugins/hls-tactics-plugin/test/golden/{UseConPair.hs.expected => UseConPair.expected.hs} (100%) rename plugins/hls-tactics-plugin/test/golden/{UseConRight.hs.expected => UseConRight.expected.hs} (100%) diff --git a/plugins/hls-tactics-plugin/hls-tactics-plugin.cabal b/plugins/hls-tactics-plugin/hls-tactics-plugin.cabal index 56573c5223..3a18e9393e 100644 --- a/plugins/hls-tactics-plugin/hls-tactics-plugin.cabal +++ b/plugins/hls-tactics-plugin/hls-tactics-plugin.cabal @@ -15,7 +15,6 @@ build-type: Simple extra-source-files: README.md test/golden/*.cabal - test/golden/*.expected test/golden/*.hs test/golden/*.yaml @@ -43,17 +42,17 @@ library Wingman.KnownStrategies Wingman.KnownStrategies.QuickCheck Wingman.LanguageServer - Wingman.LanguageServer.TacticProviders Wingman.LanguageServer.Metaprogram + Wingman.LanguageServer.TacticProviders Wingman.Machinery Wingman.Metaprogramming.Lexer Wingman.Metaprogramming.Parser Wingman.Metaprogramming.ProofState Wingman.Naming Wingman.Plugin - Wingman.StaticPlugin Wingman.Range Wingman.Simplify + Wingman.StaticPlugin Wingman.Tactics Wingman.Types @@ -79,21 +78,21 @@ library , ghc-exactprint , ghc-source-gen , ghcide ^>=1.3 + , hls-graph , hls-plugin-api ^>=1.1 + , hyphenation , lens , lsp + , megaparsec ^>=9 , mtl + , parser-combinators + , prettyprinter , refinery ^>=0.3 , retrie >=0.1.1.0 - , hls-graph , syb , text , transformers , unordered-containers - , hyphenation - , megaparsec ^>=9 - , parser-combinators - , prettyprinter default-language: Haskell2010 default-extensions: @@ -154,7 +153,7 @@ test-suite tests , ghcide , hls-plugin-api , hls-tactics-plugin - , hls-test-utils ^>= 1.0 + , hls-test-utils ^>=1.0 , hspec , hspec-expectations , lens diff --git a/plugins/hls-tactics-plugin/test/CodeAction/AutoSpec.hs b/plugins/hls-tactics-plugin/test/CodeAction/AutoSpec.hs index 0c81255756..5c6b6efff5 100644 --- a/plugins/hls-tactics-plugin/test/CodeAction/AutoSpec.hs +++ b/plugins/hls-tactics-plugin/test/CodeAction/AutoSpec.hs @@ -1,9 +1,4 @@ -{-# LANGUAGE DataKinds #-} -{-# LANGUAGE DuplicateRecordFields #-} -{-# LANGUAGE OverloadedStrings #-} -{-# LANGUAGE ScopedTypeVariables #-} -{-# LANGUAGE TypeOperators #-} -{-# LANGUAGE ViewPatterns #-} +{-# LANGUAGE OverloadedStrings #-} module CodeAction.AutoSpec where @@ -19,72 +14,72 @@ spec = do autoTestNoWhitespace = goldenTestNoWhitespace Auto "" describe "golden" $ do - autoTest 11 8 "AutoSplitGADT.hs" - autoTest 2 11 "GoldenEitherAuto.hs" - autoTest 4 12 "GoldenJoinCont.hs" - autoTest 3 11 "GoldenIdentityFunctor.hs" - autoTest 7 11 "GoldenIdTypeFam.hs" - autoTest 2 15 "GoldenEitherHomomorphic.hs" - autoTest 2 8 "GoldenNote.hs" - autoTest 2 12 "GoldenPureList.hs" - autoTest 2 12 "GoldenListFmap.hs" - autoTest 2 13 "GoldenFromMaybe.hs" - autoTest 2 10 "GoldenFoldr.hs" - autoTest 2 8 "GoldenSwap.hs" - autoTest 4 11 "GoldenFmapTree.hs" - autoTest 7 13 "GoldenGADTAuto.hs" - autoTest 2 12 "GoldenSwapMany.hs" - autoTest 4 12 "GoldenBigTuple.hs" - autoTest 2 10 "GoldenShow.hs" - autoTest 2 15 "GoldenShowCompose.hs" - autoTest 2 8 "GoldenShowMapChar.hs" - autoTest 7 8 "GoldenSuperclass.hs" - autoTest 2 12 "GoldenSafeHead.hs" - autoTest 2 12 "FmapBoth.hs" - autoTest 7 8 "RecordCon.hs" - autoTest 6 8 "NewtypeRecord.hs" - autoTest 2 14 "FmapJoin.hs" - autoTest 2 9 "Fgmap.hs" - autoTest 4 19 "FmapJoinInLet.hs" - autoTest 9 12 "AutoEndo.hs" - autoTest 2 16 "AutoEmptyString.hs" - autoTest 7 35 "AutoPatSynUse.hs" - autoTest 2 28 "AutoZip.hs" - autoTest 2 17 "AutoInfixApply.hs" - autoTest 2 19 "AutoInfixApplyMany.hs" - autoTest 2 25 "AutoInfixInfix.hs" + autoTest 11 8 "AutoSplitGADT" + autoTest 2 11 "GoldenEitherAuto" + autoTest 4 12 "GoldenJoinCont" + autoTest 3 11 "GoldenIdentityFunctor" + autoTest 7 11 "GoldenIdTypeFam" + autoTest 2 15 "GoldenEitherHomomorphic" + autoTest 2 8 "GoldenNote" + autoTest 2 12 "GoldenPureList" + autoTest 2 12 "GoldenListFmap" + autoTest 2 13 "GoldenFromMaybe" + autoTest 2 10 "GoldenFoldr" + autoTest 2 8 "GoldenSwap" + autoTest 4 11 "GoldenFmapTree" + autoTest 7 13 "GoldenGADTAuto" + autoTest 2 12 "GoldenSwapMany" + autoTest 4 12 "GoldenBigTuple" + autoTest 2 10 "GoldenShow" + autoTest 2 15 "GoldenShowCompose" + autoTest 2 8 "GoldenShowMapChar" + autoTest 7 8 "GoldenSuperclass" + autoTest 2 12 "GoldenSafeHead" + autoTest 2 12 "FmapBoth" + autoTest 7 8 "RecordCon" + autoTest 6 8 "NewtypeRecord" + autoTest 2 14 "FmapJoin" + autoTest 2 9 "Fgmap" + autoTest 4 19 "FmapJoinInLet" + autoTest 9 12 "AutoEndo" + autoTest 2 16 "AutoEmptyString" + autoTest 7 35 "AutoPatSynUse" + autoTest 2 28 "AutoZip" + autoTest 2 17 "AutoInfixApply" + autoTest 2 19 "AutoInfixApplyMany" + autoTest 2 25 "AutoInfixInfix" failing "flaky in CI" $ - autoTest 2 11 "GoldenApplicativeThen.hs" + autoTest 2 11 "GoldenApplicativeThen" failing "not enough auto gas" $ - autoTest 5 18 "GoldenFish.hs" + autoTest 5 18 "GoldenFish" describe "theta" $ do - autoTest 12 10 "AutoThetaFix.hs" - autoTest 7 20 "AutoThetaRankN.hs" - autoTest 6 10 "AutoThetaGADT.hs" - autoTest 6 8 "AutoThetaGADTDestruct.hs" - autoTest 4 8 "AutoThetaEqCtx.hs" - autoTest 6 10 "AutoThetaEqGADT.hs" - autoTest 6 8 "AutoThetaEqGADTDestruct.hs" - autoTest 6 10 "AutoThetaRefl.hs" - autoTest 6 8 "AutoThetaReflDestruct.hs" + autoTest 12 10 "AutoThetaFix" + autoTest 7 20 "AutoThetaRankN" + autoTest 6 10 "AutoThetaGADT" + autoTest 6 8 "AutoThetaGADTDestruct" + autoTest 4 8 "AutoThetaEqCtx" + autoTest 6 10 "AutoThetaEqGADT" + autoTest 6 8 "AutoThetaEqGADTDestruct" + autoTest 6 10 "AutoThetaRefl" + autoTest 6 8 "AutoThetaReflDestruct" describe "known" $ do - autoTest 25 13 "GoldenArbitrary.hs" + autoTest 25 13 "GoldenArbitrary" autoTestNoWhitespace - 6 10 "KnownBigSemigroup.hs" - autoTest 4 10 "KnownThetaSemigroup.hs" - autoTest 6 10 "KnownCounterfactualSemigroup.hs" - autoTest 10 10 "KnownModuleInstanceSemigroup.hs" - autoTest 4 22 "KnownDestructedSemigroup.hs" - autoTest 4 10 "KnownMissingSemigroup.hs" - autoTest 7 12 "KnownMonoid.hs" - autoTest 7 12 "KnownPolyMonoid.hs" - autoTest 7 12 "KnownMissingMonoid.hs" + 6 10 "KnownBigSemigroup" + autoTest 4 10 "KnownThetaSemigroup" + autoTest 6 10 "KnownCounterfactualSemigroup" + autoTest 10 10 "KnownModuleInstanceSemigroup" + autoTest 4 22 "KnownDestructedSemigroup" + autoTest 4 10 "KnownMissingSemigroup" + autoTest 7 12 "KnownMonoid" + autoTest 7 12 "KnownPolyMonoid" + autoTest 7 12 "KnownMissingMonoid" describe "messages" $ do - mkShowMessageTest allFeatures Auto "" 2 8 "MessageForallA.hs" TacticErrors + mkShowMessageTest allFeatures Auto "" 2 8 "MessageForallA" TacticErrors diff --git a/plugins/hls-tactics-plugin/test/CodeAction/DestructAllSpec.hs b/plugins/hls-tactics-plugin/test/CodeAction/DestructAllSpec.hs index afdddc08ed..89579f7ba9 100644 --- a/plugins/hls-tactics-plugin/test/CodeAction/DestructAllSpec.hs +++ b/plugins/hls-tactics-plugin/test/CodeAction/DestructAllSpec.hs @@ -1,9 +1,4 @@ -{-# LANGUAGE DataKinds #-} -{-# LANGUAGE DuplicateRecordFields #-} -{-# LANGUAGE OverloadedStrings #-} -{-# LANGUAGE ScopedTypeVariables #-} -{-# LANGUAGE TypeOperators #-} -{-# LANGUAGE ViewPatterns #-} +{-# LANGUAGE OverloadedStrings #-} module CodeAction.DestructAllSpec where @@ -18,25 +13,25 @@ spec = do describe "provider" $ do mkTest "Requires args on lhs of =" - "DestructAllProvider.hs" 3 21 + "DestructAllProvider" 3 21 [ (not, DestructAll, "") ] mkTest "Can't be a non-top-hole" - "DestructAllProvider.hs" 8 19 + "DestructAllProvider" 8 19 [ (not, DestructAll, "") , (id, Destruct, "a") , (id, Destruct, "b") ] mkTest "Provides a destruct all otherwise" - "DestructAllProvider.hs" 12 22 + "DestructAllProvider" 12 22 [ (id, DestructAll, "") ] describe "golden" $ do - destructAllTest 2 11 "DestructAllAnd.hs" - destructAllTest 4 23 "DestructAllMany.hs" - destructAllTest 2 18 "DestructAllNonVarTopMatch.hs" - destructAllTest 2 18 "DestructAllFunc.hs" + destructAllTest 2 11 "DestructAllAnd" + destructAllTest 4 23 "DestructAllMany" + destructAllTest 2 18 "DestructAllNonVarTopMatch" + destructAllTest 2 18 "DestructAllFunc" diff --git a/plugins/hls-tactics-plugin/test/CodeAction/DestructPunSpec.hs b/plugins/hls-tactics-plugin/test/CodeAction/DestructPunSpec.hs index 6b721058d2..7d17aa1d2c 100644 --- a/plugins/hls-tactics-plugin/test/CodeAction/DestructPunSpec.hs +++ b/plugins/hls-tactics-plugin/test/CodeAction/DestructPunSpec.hs @@ -1,9 +1,4 @@ -{-# LANGUAGE DataKinds #-} -{-# LANGUAGE DuplicateRecordFields #-} -{-# LANGUAGE OverloadedStrings #-} -{-# LANGUAGE ScopedTypeVariables #-} -{-# LANGUAGE TypeOperators #-} -{-# LANGUAGE ViewPatterns #-} +{-# LANGUAGE OverloadedStrings #-} module CodeAction.DestructPunSpec where @@ -17,9 +12,9 @@ spec = do let destructTest = goldenTest DestructPun describe "golden" $ do - destructTest "x" 4 9 "PunSimple.hs" - destructTest "x" 6 10 "PunMany.hs" - destructTest "x" 11 11 "PunGADT.hs" - destructTest "x" 17 11 "PunManyGADT.hs" - destructTest "x" 4 12 "PunShadowing.hs" + destructTest "x" 4 9 "PunSimple" + destructTest "x" 6 10 "PunMany" + destructTest "x" 11 11 "PunGADT" + destructTest "x" 17 11 "PunManyGADT" + destructTest "x" 4 12 "PunShadowing" diff --git a/plugins/hls-tactics-plugin/test/CodeAction/DestructSpec.hs b/plugins/hls-tactics-plugin/test/CodeAction/DestructSpec.hs index aff0d3ee14..c2964ac555 100644 --- a/plugins/hls-tactics-plugin/test/CodeAction/DestructSpec.hs +++ b/plugins/hls-tactics-plugin/test/CodeAction/DestructSpec.hs @@ -1,9 +1,4 @@ -{-# LANGUAGE DataKinds #-} -{-# LANGUAGE DuplicateRecordFields #-} -{-# LANGUAGE OverloadedStrings #-} -{-# LANGUAGE ScopedTypeVariables #-} -{-# LANGUAGE TypeOperators #-} -{-# LANGUAGE ViewPatterns #-} +{-# LANGUAGE OverloadedStrings #-} module CodeAction.DestructSpec where @@ -17,23 +12,23 @@ spec = do let destructTest = goldenTest Destruct describe "golden" $ do - destructTest "gadt" 7 17 "GoldenGADTDestruct.hs" - destructTest "gadt" 8 17 "GoldenGADTDestructCoercion.hs" - destructTest "a" 7 25 "SplitPattern.hs" - destructTest "a" 6 18 "DestructPun.hs" - destructTest "fp" 31 14 "DestructCthulhu.hs" + destructTest "gadt" 7 17 "GoldenGADTDestruct" + destructTest "gadt" 8 17 "GoldenGADTDestructCoercion" + destructTest "a" 7 25 "SplitPattern" + destructTest "a" 6 18 "DestructPun" + destructTest "fp" 31 14 "DestructCthulhu" describe "layout" $ do - destructTest "b" 4 3 "LayoutBind.hs" - destructTest "b" 2 15 "LayoutDollarApp.hs" - destructTest "b" 2 18 "LayoutOpApp.hs" - destructTest "b" 2 14 "LayoutLam.hs" - destructTest "x" 11 15 "LayoutSplitWhere.hs" - destructTest "x" 3 12 "LayoutSplitClass.hs" - destructTest "b" 3 9 "LayoutSplitGuard.hs" - destructTest "b" 4 13 "LayoutSplitLet.hs" - destructTest "a" 4 7 "LayoutSplitIn.hs" - destructTest "a" 4 31 "LayoutSplitViewPat.hs" - destructTest "a" 7 17 "LayoutSplitPattern.hs" - destructTest "a" 8 26 "LayoutSplitPatSyn.hs" + destructTest "b" 4 3 "LayoutBind" + destructTest "b" 2 15 "LayoutDollarApp" + destructTest "b" 2 18 "LayoutOpApp" + destructTest "b" 2 14 "LayoutLam" + destructTest "x" 11 15 "LayoutSplitWhere" + destructTest "x" 3 12 "LayoutSplitClass" + destructTest "b" 3 9 "LayoutSplitGuard" + destructTest "b" 4 13 "LayoutSplitLet" + destructTest "a" 4 7 "LayoutSplitIn" + destructTest "a" 4 31 "LayoutSplitViewPat" + destructTest "a" 7 17 "LayoutSplitPattern" + destructTest "a" 8 26 "LayoutSplitPatSyn" diff --git a/plugins/hls-tactics-plugin/test/CodeAction/IntrosSpec.hs b/plugins/hls-tactics-plugin/test/CodeAction/IntrosSpec.hs index 821e48a61b..254ec68522 100644 --- a/plugins/hls-tactics-plugin/test/CodeAction/IntrosSpec.hs +++ b/plugins/hls-tactics-plugin/test/CodeAction/IntrosSpec.hs @@ -1,9 +1,4 @@ -{-# LANGUAGE DataKinds #-} -{-# LANGUAGE DuplicateRecordFields #-} -{-# LANGUAGE OverloadedStrings #-} -{-# LANGUAGE ScopedTypeVariables #-} -{-# LANGUAGE TypeOperators #-} -{-# LANGUAGE ViewPatterns #-} +{-# LANGUAGE OverloadedStrings #-} module CodeAction.IntrosSpec where @@ -17,5 +12,5 @@ spec = do let introsTest = goldenTest Intros "" describe "golden" $ do - introsTest 2 8 "GoldenIntros.hs" + introsTest 2 8 "GoldenIntros" diff --git a/plugins/hls-tactics-plugin/test/CodeAction/RefineSpec.hs b/plugins/hls-tactics-plugin/test/CodeAction/RefineSpec.hs index 12f1f9ce8a..6a4aa11feb 100644 --- a/plugins/hls-tactics-plugin/test/CodeAction/RefineSpec.hs +++ b/plugins/hls-tactics-plugin/test/CodeAction/RefineSpec.hs @@ -1,9 +1,4 @@ -{-# LANGUAGE DataKinds #-} -{-# LANGUAGE DuplicateRecordFields #-} -{-# LANGUAGE OverloadedStrings #-} -{-# LANGUAGE ScopedTypeVariables #-} -{-# LANGUAGE TypeOperators #-} -{-# LANGUAGE ViewPatterns #-} +{-# LANGUAGE OverloadedStrings #-} module CodeAction.RefineSpec where @@ -18,11 +13,11 @@ spec = do let refineTest = goldenTest Refine "" describe "golden" $ do - refineTest 2 8 "RefineIntro.hs" - refineTest 2 8 "RefineCon.hs" - refineTest 4 8 "RefineReader.hs" - refineTest 8 8 "RefineGADT.hs" + refineTest 2 8 "RefineIntro" + refineTest 2 8 "RefineCon" + refineTest 4 8 "RefineReader" + refineTest 8 8 "RefineGADT" describe "messages" $ do - mkShowMessageTest allFeatures Refine "" 2 8 "MessageForallA.hs" NothingToDo + mkShowMessageTest allFeatures Refine "" 2 8 "MessageForallA" NothingToDo diff --git a/plugins/hls-tactics-plugin/test/CodeAction/RunMetaprogramSpec.hs b/plugins/hls-tactics-plugin/test/CodeAction/RunMetaprogramSpec.hs index bc42de54a1..17750c93ca 100644 --- a/plugins/hls-tactics-plugin/test/CodeAction/RunMetaprogramSpec.hs +++ b/plugins/hls-tactics-plugin/test/CodeAction/RunMetaprogramSpec.hs @@ -1,10 +1,5 @@ -{-# LANGUAGE CPP #-} -{-# LANGUAGE DataKinds #-} -{-# LANGUAGE DuplicateRecordFields #-} -{-# LANGUAGE OverloadedStrings #-} -{-# LANGUAGE ScopedTypeVariables #-} -{-# LANGUAGE TypeOperators #-} -{-# LANGUAGE ViewPatterns #-} +{-# LANGUAGE CPP #-} +{-# LANGUAGE OverloadedStrings #-} module CodeAction.RunMetaprogramSpec where @@ -24,13 +19,13 @@ spec = do #if __GLASGOW_HASKELL__ >= 808 describe "beginMetaprogram" $ do - goldenTest BeginMetaprogram "" 1 7 "MetaBegin.hs" + goldenTest BeginMetaprogram "" 1 7 "MetaBegin" #endif describe "golden" $ do - metaTest 6 11 "MetaMaybeAp.hs" - metaTest 2 32 "MetaBindOne.hs" - metaTest 2 32 "MetaBindAll.hs" - metaTest 2 13 "MetaTry.hs" - metaTest 2 74 "MetaChoice.hs" + metaTest 6 11 "MetaMaybeAp" + metaTest 2 32 "MetaBindOne" + metaTest 2 32 "MetaBindAll" + metaTest 2 13 "MetaTry" + metaTest 2 74 "MetaChoice" diff --git a/plugins/hls-tactics-plugin/test/CodeAction/UseDataConSpec.hs b/plugins/hls-tactics-plugin/test/CodeAction/UseDataConSpec.hs index 676111bc6f..94a1d17550 100644 --- a/plugins/hls-tactics-plugin/test/CodeAction/UseDataConSpec.hs +++ b/plugins/hls-tactics-plugin/test/CodeAction/UseDataConSpec.hs @@ -1,9 +1,4 @@ -{-# LANGUAGE DataKinds #-} -{-# LANGUAGE DuplicateRecordFields #-} -{-# LANGUAGE OverloadedStrings #-} -{-# LANGUAGE ScopedTypeVariables #-} -{-# LANGUAGE TypeOperators #-} -{-# LANGUAGE ViewPatterns #-} +{-# LANGUAGE OverloadedStrings #-} module CodeAction.UseDataConSpec where @@ -20,7 +15,7 @@ spec = do describe "provider" $ do mkTest "Suggests all data cons for Either" - "ConProviders.hs" 5 6 + "ConProviders" 5 6 [ (id, UseDataCon, "Left") , (id, UseDataCon, "Right") , (not, UseDataCon, ":") @@ -29,19 +24,19 @@ spec = do ] mkTest "Suggests no data cons for big types" - "ConProviders.hs" 11 17 $ do + "ConProviders" 11 17 $ do c <- [1 :: Int .. 10] pure $ (not, UseDataCon, T.pack $ show c) mkTest "Suggests only matching data cons for GADT" - "ConProviders.hs" 20 12 + "ConProviders" 20 12 [ (id, UseDataCon, "IntGADT") , (id, UseDataCon, "VarGADT") , (not, UseDataCon, "BoolGADT") ] describe "golden" $ do - useTest "(,)" 2 8 "UseConPair.hs" - useTest "Left" 2 8 "UseConLeft.hs" - useTest "Right" 2 8 "UseConRight.hs" + useTest "(,)" 2 8 "UseConPair" + useTest "Left" 2 8 "UseConLeft" + useTest "Right" 2 8 "UseConRight" diff --git a/plugins/hls-tactics-plugin/test/CodeLens/EmptyCaseSpec.hs b/plugins/hls-tactics-plugin/test/CodeLens/EmptyCaseSpec.hs index c670697c6d..66901defcd 100644 --- a/plugins/hls-tactics-plugin/test/CodeLens/EmptyCaseSpec.hs +++ b/plugins/hls-tactics-plugin/test/CodeLens/EmptyCaseSpec.hs @@ -1,9 +1,4 @@ -{-# LANGUAGE DataKinds #-} -{-# LANGUAGE DuplicateRecordFields #-} -{-# LANGUAGE OverloadedStrings #-} -{-# LANGUAGE ScopedTypeVariables #-} -{-# LANGUAGE TypeOperators #-} -{-# LANGUAGE ViewPatterns #-} +{-# LANGUAGE OverloadedStrings #-} module CodeLens.EmptyCaseSpec where @@ -17,10 +12,10 @@ spec = do let test = mkCodeLensTest allFeatures describe "golden" $ do - test "EmptyCaseADT.hs" - test "EmptyCaseShadow.hs" - test "EmptyCaseParens.hs" - test "EmptyCaseNested.hs" - test "EmptyCaseApply.hs" - test "EmptyCaseGADT.hs" + test "EmptyCaseADT" + test "EmptyCaseShadow" + test "EmptyCaseParens" + test "EmptyCaseNested" + test "EmptyCaseApply" + test "EmptyCaseGADT" diff --git a/plugins/hls-tactics-plugin/test/ProviderSpec.hs b/plugins/hls-tactics-plugin/test/ProviderSpec.hs index d1e7877a30..0c70b8d9af 100644 --- a/plugins/hls-tactics-plugin/test/ProviderSpec.hs +++ b/plugins/hls-tactics-plugin/test/ProviderSpec.hs @@ -1,9 +1,4 @@ -{-# LANGUAGE DataKinds #-} -{-# LANGUAGE DuplicateRecordFields #-} -{-# LANGUAGE OverloadedStrings #-} -{-# LANGUAGE ScopedTypeVariables #-} -{-# LANGUAGE TypeOperators #-} -{-# LANGUAGE ViewPatterns #-} +{-# LANGUAGE OverloadedStrings #-} module ProviderSpec where @@ -16,58 +11,58 @@ spec :: Spec spec = do mkTest "Produces intros code action" - "T1.hs" 2 14 + "T1" 2 14 [ (id, Intros, "") ] mkTest "Produces destruct and homomorphism code actions" - "T2.hs" 2 21 + "T2" 2 21 [ (id, Destruct, "eab") , (id, Homomorphism, "eab") , (not, DestructPun, "eab") ] mkTest "Won't suggest homomorphism on the wrong type" - "T2.hs" 8 8 + "T2" 8 8 [ (not, Homomorphism, "global") ] mkTest "Won't suggest intros on the wrong type" - "T2.hs" 8 8 + "T2" 8 8 [ (not, Intros, "") ] mkTest "Produces (homomorphic) lambdacase code actions" - "T3.hs" 4 24 + "T3" 4 24 [ (id, HomomorphismLambdaCase, "") , (id, DestructLambdaCase, "") ] mkTest "Produces lambdacase code actions" - "T3.hs" 7 13 + "T3" 7 13 [ (id, DestructLambdaCase, "") ] mkTest "Doesn't suggest lambdacase without -XLambdaCase" - "T2.hs" 11 25 + "T2" 11 25 [ (not, DestructLambdaCase, "") ] mkTest "Doesn't suggest destruct if already destructed" - "ProvideAlreadyDestructed.hs" 6 18 + "ProvideAlreadyDestructed" 6 18 [ (not, Destruct, "x") ] mkTest "...but does suggest destruct if destructed in a different branch" - "ProvideAlreadyDestructed.hs" 9 7 + "ProvideAlreadyDestructed" 9 7 [ (id, Destruct, "x") ] mkTest "Doesn't suggest destruct on class methods" - "ProvideLocalHyOnly.hs" 2 12 + "ProvideLocalHyOnly" 2 12 [ (not, Destruct, "mempty") ] diff --git a/plugins/hls-tactics-plugin/test/Utils.hs b/plugins/hls-tactics-plugin/test/Utils.hs index 2e78105682..d2f7356563 100644 --- a/plugins/hls-tactics-plugin/test/Utils.hs +++ b/plugins/hls-tactics-plugin/test/Utils.hs @@ -61,7 +61,7 @@ codeActionTitle (InR(CodeAction title _ _ _ _ _ _ _)) = Just title mkTest :: Foldable t => String -- ^ The test name - -> FilePath -- ^ The file to load + -> FilePath -- ^ The file name stem (without extension) to load -> Int -- ^ Cursor line -> Int -- ^ Cursor columnn -> t ( Bool -> Bool -- Use 'not' for actions that shouldnt be present @@ -72,7 +72,7 @@ mkTest mkTest name fp line col ts = it name $ do runSessionWithServer plugin tacticPath $ do setFeatureSet allFeatures - doc <- openDoc fp "haskell" + doc <- openDoc (fp <.> "hs") "haskell" _ <- waitForDiagnostics actions <- getCodeActions doc $ pointRange line col let titles = mapMaybe codeActionTitle actions @@ -111,7 +111,7 @@ mkGoldenTest eq features tc occ line col input = it (input <> " (golden)") $ do runSessionWithServer plugin tacticPath $ do setFeatureSet features - doc <- openDoc input "haskell" + doc <- openDoc (input <.> "hs") "haskell" _ <- waitForDiagnostics actions <- getCodeActions doc $ pointRange line col Just (InR CodeAction {_command = Just c}) @@ -119,7 +119,7 @@ mkGoldenTest eq features tc occ line col input = executeCommand c _resp <- skipManyTill anyMessage (message SWorkspaceApplyEdit) edited <- documentContents doc - let expected_name = input <.> "expected" + let expected_name = input <.> "expected" <.> "hs" -- Write golden tests if they don't already exist liftIO $ (doesFileExist expected_name >>=) $ flip unless $ do T.writeFile expected_name edited @@ -135,14 +135,14 @@ mkCodeLensTest features input = it (input <> " (golden)") $ do runSessionWithServer plugin tacticPath $ do setFeatureSet features - doc <- openDoc input "haskell" + doc <- openDoc (input <.> "hs") "haskell" _ <- waitForDiagnostics lenses <- fmap (reverse . filter isWingmanLens) $ getCodeLenses doc for_ lenses $ \(CodeLens _ (Just cmd) _) -> executeCommand cmd _resp <- skipManyTill anyMessage (message SWorkspaceApplyEdit) edited <- documentContents doc - let expected_name = input <.> "expected" + let expected_name = input <.> "expected" <.> "hs" -- Write golden tests if they don't already exist liftIO $ (doesFileExist expected_name >>=) $ flip unless $ do T.writeFile expected_name edited @@ -170,7 +170,7 @@ mkShowMessageTest features tc occ line col input ufm = it (input <> " (golden)") $ do runSessionWithServer plugin tacticPath $ do setFeatureSet features - doc <- openDoc input "haskell" + doc <- openDoc (input <.> "hs") "haskell" _ <- waitForDiagnostics actions <- getCodeActions doc $ pointRange line col Just (InR CodeAction {_command = Just c}) diff --git a/plugins/hls-tactics-plugin/test/golden/AutoEmptyString.hs.expected b/plugins/hls-tactics-plugin/test/golden/AutoEmptyString.expected.hs similarity index 100% rename from plugins/hls-tactics-plugin/test/golden/AutoEmptyString.hs.expected rename to plugins/hls-tactics-plugin/test/golden/AutoEmptyString.expected.hs diff --git a/plugins/hls-tactics-plugin/test/golden/AutoEndo.hs.expected b/plugins/hls-tactics-plugin/test/golden/AutoEndo.expected.hs similarity index 100% rename from plugins/hls-tactics-plugin/test/golden/AutoEndo.hs.expected rename to plugins/hls-tactics-plugin/test/golden/AutoEndo.expected.hs diff --git a/plugins/hls-tactics-plugin/test/golden/AutoInfixApply.hs.expected b/plugins/hls-tactics-plugin/test/golden/AutoInfixApply.expected.hs similarity index 100% rename from plugins/hls-tactics-plugin/test/golden/AutoInfixApply.hs.expected rename to plugins/hls-tactics-plugin/test/golden/AutoInfixApply.expected.hs diff --git a/plugins/hls-tactics-plugin/test/golden/AutoInfixApplyMany.hs.expected b/plugins/hls-tactics-plugin/test/golden/AutoInfixApplyMany.expected.hs similarity index 100% rename from plugins/hls-tactics-plugin/test/golden/AutoInfixApplyMany.hs.expected rename to plugins/hls-tactics-plugin/test/golden/AutoInfixApplyMany.expected.hs diff --git a/plugins/hls-tactics-plugin/test/golden/AutoInfixInfix.hs.expected b/plugins/hls-tactics-plugin/test/golden/AutoInfixInfix.expected.hs similarity index 100% rename from plugins/hls-tactics-plugin/test/golden/AutoInfixInfix.hs.expected rename to plugins/hls-tactics-plugin/test/golden/AutoInfixInfix.expected.hs diff --git a/plugins/hls-tactics-plugin/test/golden/AutoPatSynUse.hs.expected b/plugins/hls-tactics-plugin/test/golden/AutoPatSynUse.expected.hs similarity index 100% rename from plugins/hls-tactics-plugin/test/golden/AutoPatSynUse.hs.expected rename to plugins/hls-tactics-plugin/test/golden/AutoPatSynUse.expected.hs diff --git a/plugins/hls-tactics-plugin/test/golden/AutoSplitGADT.hs.expected b/plugins/hls-tactics-plugin/test/golden/AutoSplitGADT.expected.hs similarity index 100% rename from plugins/hls-tactics-plugin/test/golden/AutoSplitGADT.hs.expected rename to plugins/hls-tactics-plugin/test/golden/AutoSplitGADT.expected.hs diff --git a/plugins/hls-tactics-plugin/test/golden/AutoThetaEqCtx.hs.expected b/plugins/hls-tactics-plugin/test/golden/AutoThetaEqCtx.expected.hs similarity index 100% rename from plugins/hls-tactics-plugin/test/golden/AutoThetaEqCtx.hs.expected rename to plugins/hls-tactics-plugin/test/golden/AutoThetaEqCtx.expected.hs diff --git a/plugins/hls-tactics-plugin/test/golden/AutoThetaEqGADT.hs.expected b/plugins/hls-tactics-plugin/test/golden/AutoThetaEqGADT.expected.hs similarity index 100% rename from plugins/hls-tactics-plugin/test/golden/AutoThetaEqGADT.hs.expected rename to plugins/hls-tactics-plugin/test/golden/AutoThetaEqGADT.expected.hs diff --git a/plugins/hls-tactics-plugin/test/golden/AutoThetaEqGADTDestruct.hs.expected b/plugins/hls-tactics-plugin/test/golden/AutoThetaEqGADTDestruct.expected.hs similarity index 100% rename from plugins/hls-tactics-plugin/test/golden/AutoThetaEqGADTDestruct.hs.expected rename to plugins/hls-tactics-plugin/test/golden/AutoThetaEqGADTDestruct.expected.hs diff --git a/plugins/hls-tactics-plugin/test/golden/AutoThetaFix.hs.expected b/plugins/hls-tactics-plugin/test/golden/AutoThetaFix.expected.hs similarity index 100% rename from plugins/hls-tactics-plugin/test/golden/AutoThetaFix.hs.expected rename to plugins/hls-tactics-plugin/test/golden/AutoThetaFix.expected.hs diff --git a/plugins/hls-tactics-plugin/test/golden/AutoThetaGADT.hs.expected b/plugins/hls-tactics-plugin/test/golden/AutoThetaGADT.expected.hs similarity index 100% rename from plugins/hls-tactics-plugin/test/golden/AutoThetaGADT.hs.expected rename to plugins/hls-tactics-plugin/test/golden/AutoThetaGADT.expected.hs diff --git a/plugins/hls-tactics-plugin/test/golden/AutoThetaGADTDestruct.hs.expected b/plugins/hls-tactics-plugin/test/golden/AutoThetaGADTDestruct.expected.hs similarity index 100% rename from plugins/hls-tactics-plugin/test/golden/AutoThetaGADTDestruct.hs.expected rename to plugins/hls-tactics-plugin/test/golden/AutoThetaGADTDestruct.expected.hs diff --git a/plugins/hls-tactics-plugin/test/golden/AutoThetaRankN.hs.expected b/plugins/hls-tactics-plugin/test/golden/AutoThetaRankN.expected.hs similarity index 100% rename from plugins/hls-tactics-plugin/test/golden/AutoThetaRankN.hs.expected rename to plugins/hls-tactics-plugin/test/golden/AutoThetaRankN.expected.hs diff --git a/plugins/hls-tactics-plugin/test/golden/AutoThetaRefl.hs.expected b/plugins/hls-tactics-plugin/test/golden/AutoThetaRefl.expected.hs similarity index 100% rename from plugins/hls-tactics-plugin/test/golden/AutoThetaRefl.hs.expected rename to plugins/hls-tactics-plugin/test/golden/AutoThetaRefl.expected.hs diff --git a/plugins/hls-tactics-plugin/test/golden/AutoThetaReflDestruct.hs.expected b/plugins/hls-tactics-plugin/test/golden/AutoThetaReflDestruct.expected.hs similarity index 100% rename from plugins/hls-tactics-plugin/test/golden/AutoThetaReflDestruct.hs.expected rename to plugins/hls-tactics-plugin/test/golden/AutoThetaReflDestruct.expected.hs diff --git a/plugins/hls-tactics-plugin/test/golden/AutoZip.hs.expected b/plugins/hls-tactics-plugin/test/golden/AutoZip.expected.hs similarity index 100% rename from plugins/hls-tactics-plugin/test/golden/AutoZip.hs.expected rename to plugins/hls-tactics-plugin/test/golden/AutoZip.expected.hs diff --git a/plugins/hls-tactics-plugin/test/golden/DestructAllAnd.hs.expected b/plugins/hls-tactics-plugin/test/golden/DestructAllAnd.expected.hs similarity index 100% rename from plugins/hls-tactics-plugin/test/golden/DestructAllAnd.hs.expected rename to plugins/hls-tactics-plugin/test/golden/DestructAllAnd.expected.hs diff --git a/plugins/hls-tactics-plugin/test/golden/DestructAllFunc.hs.expected b/plugins/hls-tactics-plugin/test/golden/DestructAllFunc.expected.hs similarity index 100% rename from plugins/hls-tactics-plugin/test/golden/DestructAllFunc.hs.expected rename to plugins/hls-tactics-plugin/test/golden/DestructAllFunc.expected.hs diff --git a/plugins/hls-tactics-plugin/test/golden/DestructAllMany.hs.expected b/plugins/hls-tactics-plugin/test/golden/DestructAllMany.expected.hs similarity index 100% rename from plugins/hls-tactics-plugin/test/golden/DestructAllMany.hs.expected rename to plugins/hls-tactics-plugin/test/golden/DestructAllMany.expected.hs diff --git a/plugins/hls-tactics-plugin/test/golden/DestructAllNonVarTopMatch.hs.expected b/plugins/hls-tactics-plugin/test/golden/DestructAllNonVarTopMatch.expected.hs similarity index 100% rename from plugins/hls-tactics-plugin/test/golden/DestructAllNonVarTopMatch.hs.expected rename to plugins/hls-tactics-plugin/test/golden/DestructAllNonVarTopMatch.expected.hs diff --git a/plugins/hls-tactics-plugin/test/golden/DestructCthulhu.hs.expected b/plugins/hls-tactics-plugin/test/golden/DestructCthulhu.expected.hs similarity index 100% rename from plugins/hls-tactics-plugin/test/golden/DestructCthulhu.hs.expected rename to plugins/hls-tactics-plugin/test/golden/DestructCthulhu.expected.hs diff --git a/plugins/hls-tactics-plugin/test/golden/DestructPun.hs.expected b/plugins/hls-tactics-plugin/test/golden/DestructPun.expected.hs similarity index 100% rename from plugins/hls-tactics-plugin/test/golden/DestructPun.hs.expected rename to plugins/hls-tactics-plugin/test/golden/DestructPun.expected.hs diff --git a/plugins/hls-tactics-plugin/test/golden/EmptyCaseADT.hs.expected b/plugins/hls-tactics-plugin/test/golden/EmptyCaseADT.expected.hs similarity index 100% rename from plugins/hls-tactics-plugin/test/golden/EmptyCaseADT.hs.expected rename to plugins/hls-tactics-plugin/test/golden/EmptyCaseADT.expected.hs diff --git a/plugins/hls-tactics-plugin/test/golden/EmptyCaseApply.hs.expected b/plugins/hls-tactics-plugin/test/golden/EmptyCaseApply.expected.hs similarity index 100% rename from plugins/hls-tactics-plugin/test/golden/EmptyCaseApply.hs.expected rename to plugins/hls-tactics-plugin/test/golden/EmptyCaseApply.expected.hs diff --git a/plugins/hls-tactics-plugin/test/golden/EmptyCaseGADT.hs.expected b/plugins/hls-tactics-plugin/test/golden/EmptyCaseGADT.expected.hs similarity index 100% rename from plugins/hls-tactics-plugin/test/golden/EmptyCaseGADT.hs.expected rename to plugins/hls-tactics-plugin/test/golden/EmptyCaseGADT.expected.hs diff --git a/plugins/hls-tactics-plugin/test/golden/EmptyCaseNested.hs.expected b/plugins/hls-tactics-plugin/test/golden/EmptyCaseNested.expected.hs similarity index 100% rename from plugins/hls-tactics-plugin/test/golden/EmptyCaseNested.hs.expected rename to plugins/hls-tactics-plugin/test/golden/EmptyCaseNested.expected.hs diff --git a/plugins/hls-tactics-plugin/test/golden/EmptyCaseParens.hs.expected b/plugins/hls-tactics-plugin/test/golden/EmptyCaseParens.expected.hs similarity index 100% rename from plugins/hls-tactics-plugin/test/golden/EmptyCaseParens.hs.expected rename to plugins/hls-tactics-plugin/test/golden/EmptyCaseParens.expected.hs diff --git a/plugins/hls-tactics-plugin/test/golden/EmptyCaseShadow.hs.expected b/plugins/hls-tactics-plugin/test/golden/EmptyCaseShadow.expected.hs similarity index 100% rename from plugins/hls-tactics-plugin/test/golden/EmptyCaseShadow.hs.expected rename to plugins/hls-tactics-plugin/test/golden/EmptyCaseShadow.expected.hs diff --git a/plugins/hls-tactics-plugin/test/golden/Fgmap.hs.expected b/plugins/hls-tactics-plugin/test/golden/Fgmap.expected.hs similarity index 100% rename from plugins/hls-tactics-plugin/test/golden/Fgmap.hs.expected rename to plugins/hls-tactics-plugin/test/golden/Fgmap.expected.hs diff --git a/plugins/hls-tactics-plugin/test/golden/FmapBoth.hs.expected b/plugins/hls-tactics-plugin/test/golden/FmapBoth.expected.hs similarity index 100% rename from plugins/hls-tactics-plugin/test/golden/FmapBoth.hs.expected rename to plugins/hls-tactics-plugin/test/golden/FmapBoth.expected.hs diff --git a/plugins/hls-tactics-plugin/test/golden/FmapJoin.hs.expected b/plugins/hls-tactics-plugin/test/golden/FmapJoin.expected.hs similarity index 100% rename from plugins/hls-tactics-plugin/test/golden/FmapJoin.hs.expected rename to plugins/hls-tactics-plugin/test/golden/FmapJoin.expected.hs diff --git a/plugins/hls-tactics-plugin/test/golden/FmapJoinInLet.hs.expected b/plugins/hls-tactics-plugin/test/golden/FmapJoinInLet.expected.hs similarity index 100% rename from plugins/hls-tactics-plugin/test/golden/FmapJoinInLet.hs.expected rename to plugins/hls-tactics-plugin/test/golden/FmapJoinInLet.expected.hs diff --git a/plugins/hls-tactics-plugin/test/golden/GoldenArbitrary.hs.expected b/plugins/hls-tactics-plugin/test/golden/GoldenArbitrary.expected.hs similarity index 100% rename from plugins/hls-tactics-plugin/test/golden/GoldenArbitrary.hs.expected rename to plugins/hls-tactics-plugin/test/golden/GoldenArbitrary.expected.hs diff --git a/plugins/hls-tactics-plugin/test/golden/GoldenBigTuple.hs.expected b/plugins/hls-tactics-plugin/test/golden/GoldenBigTuple.expected.hs similarity index 100% rename from plugins/hls-tactics-plugin/test/golden/GoldenBigTuple.hs.expected rename to plugins/hls-tactics-plugin/test/golden/GoldenBigTuple.expected.hs diff --git a/plugins/hls-tactics-plugin/test/golden/GoldenEitherAuto.hs.expected b/plugins/hls-tactics-plugin/test/golden/GoldenEitherAuto.expected.hs similarity index 100% rename from plugins/hls-tactics-plugin/test/golden/GoldenEitherAuto.hs.expected rename to plugins/hls-tactics-plugin/test/golden/GoldenEitherAuto.expected.hs diff --git a/plugins/hls-tactics-plugin/test/golden/GoldenEitherHomomorphic.hs.expected b/plugins/hls-tactics-plugin/test/golden/GoldenEitherHomomorphic.expected.hs similarity index 100% rename from plugins/hls-tactics-plugin/test/golden/GoldenEitherHomomorphic.hs.expected rename to plugins/hls-tactics-plugin/test/golden/GoldenEitherHomomorphic.expected.hs diff --git a/plugins/hls-tactics-plugin/test/golden/GoldenFmapTree.hs.expected b/plugins/hls-tactics-plugin/test/golden/GoldenFmapTree.expected.hs similarity index 100% rename from plugins/hls-tactics-plugin/test/golden/GoldenFmapTree.hs.expected rename to plugins/hls-tactics-plugin/test/golden/GoldenFmapTree.expected.hs diff --git a/plugins/hls-tactics-plugin/test/golden/GoldenFoldr.hs.expected b/plugins/hls-tactics-plugin/test/golden/GoldenFoldr.expected.hs similarity index 100% rename from plugins/hls-tactics-plugin/test/golden/GoldenFoldr.hs.expected rename to plugins/hls-tactics-plugin/test/golden/GoldenFoldr.expected.hs diff --git a/plugins/hls-tactics-plugin/test/golden/GoldenFromMaybe.hs.expected b/plugins/hls-tactics-plugin/test/golden/GoldenFromMaybe.expected.hs similarity index 100% rename from plugins/hls-tactics-plugin/test/golden/GoldenFromMaybe.hs.expected rename to plugins/hls-tactics-plugin/test/golden/GoldenFromMaybe.expected.hs diff --git a/plugins/hls-tactics-plugin/test/golden/GoldenGADTAuto.hs.expected b/plugins/hls-tactics-plugin/test/golden/GoldenGADTAuto.expected.hs similarity index 100% rename from plugins/hls-tactics-plugin/test/golden/GoldenGADTAuto.hs.expected rename to plugins/hls-tactics-plugin/test/golden/GoldenGADTAuto.expected.hs diff --git a/plugins/hls-tactics-plugin/test/golden/GoldenGADTDestruct.hs.expected b/plugins/hls-tactics-plugin/test/golden/GoldenGADTDestruct.expected.hs similarity index 100% rename from plugins/hls-tactics-plugin/test/golden/GoldenGADTDestruct.hs.expected rename to plugins/hls-tactics-plugin/test/golden/GoldenGADTDestruct.expected.hs diff --git a/plugins/hls-tactics-plugin/test/golden/GoldenGADTDestructCoercion.hs.expected b/plugins/hls-tactics-plugin/test/golden/GoldenGADTDestructCoercion.expected.hs similarity index 100% rename from plugins/hls-tactics-plugin/test/golden/GoldenGADTDestructCoercion.hs.expected rename to plugins/hls-tactics-plugin/test/golden/GoldenGADTDestructCoercion.expected.hs diff --git a/plugins/hls-tactics-plugin/test/golden/GoldenIdTypeFam.hs.expected b/plugins/hls-tactics-plugin/test/golden/GoldenIdTypeFam.expected.hs similarity index 100% rename from plugins/hls-tactics-plugin/test/golden/GoldenIdTypeFam.hs.expected rename to plugins/hls-tactics-plugin/test/golden/GoldenIdTypeFam.expected.hs diff --git a/plugins/hls-tactics-plugin/test/golden/GoldenIdentityFunctor.hs.expected b/plugins/hls-tactics-plugin/test/golden/GoldenIdentityFunctor.expected.hs similarity index 100% rename from plugins/hls-tactics-plugin/test/golden/GoldenIdentityFunctor.hs.expected rename to plugins/hls-tactics-plugin/test/golden/GoldenIdentityFunctor.expected.hs diff --git a/plugins/hls-tactics-plugin/test/golden/GoldenIntros.hs.expected b/plugins/hls-tactics-plugin/test/golden/GoldenIntros.expected.hs similarity index 100% rename from plugins/hls-tactics-plugin/test/golden/GoldenIntros.hs.expected rename to plugins/hls-tactics-plugin/test/golden/GoldenIntros.expected.hs diff --git a/plugins/hls-tactics-plugin/test/golden/GoldenJoinCont.hs.expected b/plugins/hls-tactics-plugin/test/golden/GoldenJoinCont.expected.hs similarity index 100% rename from plugins/hls-tactics-plugin/test/golden/GoldenJoinCont.hs.expected rename to plugins/hls-tactics-plugin/test/golden/GoldenJoinCont.expected.hs diff --git a/plugins/hls-tactics-plugin/test/golden/GoldenListFmap.hs.expected b/plugins/hls-tactics-plugin/test/golden/GoldenListFmap.expected.hs similarity index 100% rename from plugins/hls-tactics-plugin/test/golden/GoldenListFmap.hs.expected rename to plugins/hls-tactics-plugin/test/golden/GoldenListFmap.expected.hs diff --git a/plugins/hls-tactics-plugin/test/golden/GoldenNote.hs.expected b/plugins/hls-tactics-plugin/test/golden/GoldenNote.expected.hs similarity index 100% rename from plugins/hls-tactics-plugin/test/golden/GoldenNote.hs.expected rename to plugins/hls-tactics-plugin/test/golden/GoldenNote.expected.hs diff --git a/plugins/hls-tactics-plugin/test/golden/GoldenPureList.hs.expected b/plugins/hls-tactics-plugin/test/golden/GoldenPureList.expected.hs similarity index 100% rename from plugins/hls-tactics-plugin/test/golden/GoldenPureList.hs.expected rename to plugins/hls-tactics-plugin/test/golden/GoldenPureList.expected.hs diff --git a/plugins/hls-tactics-plugin/test/golden/GoldenSafeHead.hs.expected b/plugins/hls-tactics-plugin/test/golden/GoldenSafeHead.expected.hs similarity index 100% rename from plugins/hls-tactics-plugin/test/golden/GoldenSafeHead.hs.expected rename to plugins/hls-tactics-plugin/test/golden/GoldenSafeHead.expected.hs diff --git a/plugins/hls-tactics-plugin/test/golden/GoldenShow.hs.expected b/plugins/hls-tactics-plugin/test/golden/GoldenShow.expected.hs similarity index 100% rename from plugins/hls-tactics-plugin/test/golden/GoldenShow.hs.expected rename to plugins/hls-tactics-plugin/test/golden/GoldenShow.expected.hs diff --git a/plugins/hls-tactics-plugin/test/golden/GoldenShowCompose.hs.expected b/plugins/hls-tactics-plugin/test/golden/GoldenShowCompose.expected.hs similarity index 100% rename from plugins/hls-tactics-plugin/test/golden/GoldenShowCompose.hs.expected rename to plugins/hls-tactics-plugin/test/golden/GoldenShowCompose.expected.hs diff --git a/plugins/hls-tactics-plugin/test/golden/GoldenShowMapChar.hs.expected b/plugins/hls-tactics-plugin/test/golden/GoldenShowMapChar.expected.hs similarity index 100% rename from plugins/hls-tactics-plugin/test/golden/GoldenShowMapChar.hs.expected rename to plugins/hls-tactics-plugin/test/golden/GoldenShowMapChar.expected.hs diff --git a/plugins/hls-tactics-plugin/test/golden/GoldenSuperclass.hs.expected b/plugins/hls-tactics-plugin/test/golden/GoldenSuperclass.expected.hs similarity index 100% rename from plugins/hls-tactics-plugin/test/golden/GoldenSuperclass.hs.expected rename to plugins/hls-tactics-plugin/test/golden/GoldenSuperclass.expected.hs diff --git a/plugins/hls-tactics-plugin/test/golden/GoldenSwap.hs.expected b/plugins/hls-tactics-plugin/test/golden/GoldenSwap.expected.hs similarity index 100% rename from plugins/hls-tactics-plugin/test/golden/GoldenSwap.hs.expected rename to plugins/hls-tactics-plugin/test/golden/GoldenSwap.expected.hs diff --git a/plugins/hls-tactics-plugin/test/golden/GoldenSwapMany.hs.expected b/plugins/hls-tactics-plugin/test/golden/GoldenSwapMany.expected.hs similarity index 100% rename from plugins/hls-tactics-plugin/test/golden/GoldenSwapMany.hs.expected rename to plugins/hls-tactics-plugin/test/golden/GoldenSwapMany.expected.hs diff --git a/plugins/hls-tactics-plugin/test/golden/KnownBigSemigroup.hs.expected b/plugins/hls-tactics-plugin/test/golden/KnownBigSemigroup.expected.hs similarity index 100% rename from plugins/hls-tactics-plugin/test/golden/KnownBigSemigroup.hs.expected rename to plugins/hls-tactics-plugin/test/golden/KnownBigSemigroup.expected.hs diff --git a/plugins/hls-tactics-plugin/test/golden/KnownCounterfactualSemigroup.hs.expected b/plugins/hls-tactics-plugin/test/golden/KnownCounterfactualSemigroup.expected.hs similarity index 100% rename from plugins/hls-tactics-plugin/test/golden/KnownCounterfactualSemigroup.hs.expected rename to plugins/hls-tactics-plugin/test/golden/KnownCounterfactualSemigroup.expected.hs diff --git a/plugins/hls-tactics-plugin/test/golden/KnownDestructedSemigroup.hs.expected b/plugins/hls-tactics-plugin/test/golden/KnownDestructedSemigroup.expected.hs similarity index 100% rename from plugins/hls-tactics-plugin/test/golden/KnownDestructedSemigroup.hs.expected rename to plugins/hls-tactics-plugin/test/golden/KnownDestructedSemigroup.expected.hs diff --git a/plugins/hls-tactics-plugin/test/golden/KnownMissingMonoid.hs.expected b/plugins/hls-tactics-plugin/test/golden/KnownMissingMonoid.expected.hs similarity index 100% rename from plugins/hls-tactics-plugin/test/golden/KnownMissingMonoid.hs.expected rename to plugins/hls-tactics-plugin/test/golden/KnownMissingMonoid.expected.hs diff --git a/plugins/hls-tactics-plugin/test/golden/KnownMissingSemigroup.hs.expected b/plugins/hls-tactics-plugin/test/golden/KnownMissingSemigroup.expected.hs similarity index 100% rename from plugins/hls-tactics-plugin/test/golden/KnownMissingSemigroup.hs.expected rename to plugins/hls-tactics-plugin/test/golden/KnownMissingSemigroup.expected.hs diff --git a/plugins/hls-tactics-plugin/test/golden/KnownModuleInstanceSemigroup.hs.expected b/plugins/hls-tactics-plugin/test/golden/KnownModuleInstanceSemigroup.expected.hs similarity index 100% rename from plugins/hls-tactics-plugin/test/golden/KnownModuleInstanceSemigroup.hs.expected rename to plugins/hls-tactics-plugin/test/golden/KnownModuleInstanceSemigroup.expected.hs diff --git a/plugins/hls-tactics-plugin/test/golden/KnownMonoid.hs.expected b/plugins/hls-tactics-plugin/test/golden/KnownMonoid.expected.hs similarity index 100% rename from plugins/hls-tactics-plugin/test/golden/KnownMonoid.hs.expected rename to plugins/hls-tactics-plugin/test/golden/KnownMonoid.expected.hs diff --git a/plugins/hls-tactics-plugin/test/golden/KnownPolyMonoid.hs.expected b/plugins/hls-tactics-plugin/test/golden/KnownPolyMonoid.expected.hs similarity index 100% rename from plugins/hls-tactics-plugin/test/golden/KnownPolyMonoid.hs.expected rename to plugins/hls-tactics-plugin/test/golden/KnownPolyMonoid.expected.hs diff --git a/plugins/hls-tactics-plugin/test/golden/KnownThetaSemigroup.hs.expected b/plugins/hls-tactics-plugin/test/golden/KnownThetaSemigroup.expected.hs similarity index 100% rename from plugins/hls-tactics-plugin/test/golden/KnownThetaSemigroup.hs.expected rename to plugins/hls-tactics-plugin/test/golden/KnownThetaSemigroup.expected.hs diff --git a/plugins/hls-tactics-plugin/test/golden/LayoutBind.hs.expected b/plugins/hls-tactics-plugin/test/golden/LayoutBind.expected.hs similarity index 100% rename from plugins/hls-tactics-plugin/test/golden/LayoutBind.hs.expected rename to plugins/hls-tactics-plugin/test/golden/LayoutBind.expected.hs diff --git a/plugins/hls-tactics-plugin/test/golden/LayoutDollarApp.hs.expected b/plugins/hls-tactics-plugin/test/golden/LayoutDollarApp.expected.hs similarity index 100% rename from plugins/hls-tactics-plugin/test/golden/LayoutDollarApp.hs.expected rename to plugins/hls-tactics-plugin/test/golden/LayoutDollarApp.expected.hs diff --git a/plugins/hls-tactics-plugin/test/golden/LayoutLam.hs.expected b/plugins/hls-tactics-plugin/test/golden/LayoutLam.expected.hs similarity index 100% rename from plugins/hls-tactics-plugin/test/golden/LayoutLam.hs.expected rename to plugins/hls-tactics-plugin/test/golden/LayoutLam.expected.hs diff --git a/plugins/hls-tactics-plugin/test/golden/LayoutOpApp.hs.expected b/plugins/hls-tactics-plugin/test/golden/LayoutOpApp.expected.hs similarity index 100% rename from plugins/hls-tactics-plugin/test/golden/LayoutOpApp.hs.expected rename to plugins/hls-tactics-plugin/test/golden/LayoutOpApp.expected.hs diff --git a/plugins/hls-tactics-plugin/test/golden/LayoutSplitClass.hs.expected b/plugins/hls-tactics-plugin/test/golden/LayoutSplitClass.expected.hs similarity index 100% rename from plugins/hls-tactics-plugin/test/golden/LayoutSplitClass.hs.expected rename to plugins/hls-tactics-plugin/test/golden/LayoutSplitClass.expected.hs diff --git a/plugins/hls-tactics-plugin/test/golden/LayoutSplitGuard.hs.expected b/plugins/hls-tactics-plugin/test/golden/LayoutSplitGuard.expected.hs similarity index 100% rename from plugins/hls-tactics-plugin/test/golden/LayoutSplitGuard.hs.expected rename to plugins/hls-tactics-plugin/test/golden/LayoutSplitGuard.expected.hs diff --git a/plugins/hls-tactics-plugin/test/golden/LayoutSplitIn.hs.expected b/plugins/hls-tactics-plugin/test/golden/LayoutSplitIn.expected.hs similarity index 100% rename from plugins/hls-tactics-plugin/test/golden/LayoutSplitIn.hs.expected rename to plugins/hls-tactics-plugin/test/golden/LayoutSplitIn.expected.hs diff --git a/plugins/hls-tactics-plugin/test/golden/LayoutSplitLet.hs.expected b/plugins/hls-tactics-plugin/test/golden/LayoutSplitLet.expected.hs similarity index 100% rename from plugins/hls-tactics-plugin/test/golden/LayoutSplitLet.hs.expected rename to plugins/hls-tactics-plugin/test/golden/LayoutSplitLet.expected.hs diff --git a/plugins/hls-tactics-plugin/test/golden/LayoutSplitPatSyn.hs.expected b/plugins/hls-tactics-plugin/test/golden/LayoutSplitPatSyn.expected.hs similarity index 100% rename from plugins/hls-tactics-plugin/test/golden/LayoutSplitPatSyn.hs.expected rename to plugins/hls-tactics-plugin/test/golden/LayoutSplitPatSyn.expected.hs diff --git a/plugins/hls-tactics-plugin/test/golden/LayoutSplitPattern.hs.expected b/plugins/hls-tactics-plugin/test/golden/LayoutSplitPattern.expected.hs similarity index 100% rename from plugins/hls-tactics-plugin/test/golden/LayoutSplitPattern.hs.expected rename to plugins/hls-tactics-plugin/test/golden/LayoutSplitPattern.expected.hs diff --git a/plugins/hls-tactics-plugin/test/golden/LayoutSplitViewPat.hs.expected b/plugins/hls-tactics-plugin/test/golden/LayoutSplitViewPat.expected.hs similarity index 100% rename from plugins/hls-tactics-plugin/test/golden/LayoutSplitViewPat.hs.expected rename to plugins/hls-tactics-plugin/test/golden/LayoutSplitViewPat.expected.hs diff --git a/plugins/hls-tactics-plugin/test/golden/LayoutSplitWhere.hs.expected b/plugins/hls-tactics-plugin/test/golden/LayoutSplitWhere.expected.hs similarity index 100% rename from plugins/hls-tactics-plugin/test/golden/LayoutSplitWhere.hs.expected rename to plugins/hls-tactics-plugin/test/golden/LayoutSplitWhere.expected.hs diff --git a/plugins/hls-tactics-plugin/test/golden/MetaBegin.hs.expected b/plugins/hls-tactics-plugin/test/golden/MetaBegin.expected.hs similarity index 100% rename from plugins/hls-tactics-plugin/test/golden/MetaBegin.hs.expected rename to plugins/hls-tactics-plugin/test/golden/MetaBegin.expected.hs diff --git a/plugins/hls-tactics-plugin/test/golden/MetaBindAll.hs.expected b/plugins/hls-tactics-plugin/test/golden/MetaBindAll.expected.hs similarity index 100% rename from plugins/hls-tactics-plugin/test/golden/MetaBindAll.hs.expected rename to plugins/hls-tactics-plugin/test/golden/MetaBindAll.expected.hs diff --git a/plugins/hls-tactics-plugin/test/golden/MetaBindOne.hs.expected b/plugins/hls-tactics-plugin/test/golden/MetaBindOne.expected.hs similarity index 100% rename from plugins/hls-tactics-plugin/test/golden/MetaBindOne.hs.expected rename to plugins/hls-tactics-plugin/test/golden/MetaBindOne.expected.hs diff --git a/plugins/hls-tactics-plugin/test/golden/MetaChoice.hs.expected b/plugins/hls-tactics-plugin/test/golden/MetaChoice.expected.hs similarity index 100% rename from plugins/hls-tactics-plugin/test/golden/MetaChoice.hs.expected rename to plugins/hls-tactics-plugin/test/golden/MetaChoice.expected.hs diff --git a/plugins/hls-tactics-plugin/test/golden/MetaMaybeAp.hs.expected b/plugins/hls-tactics-plugin/test/golden/MetaMaybeAp.expected.hs similarity index 100% rename from plugins/hls-tactics-plugin/test/golden/MetaMaybeAp.hs.expected rename to plugins/hls-tactics-plugin/test/golden/MetaMaybeAp.expected.hs diff --git a/plugins/hls-tactics-plugin/test/golden/MetaTry.hs.expected b/plugins/hls-tactics-plugin/test/golden/MetaTry.expected.hs similarity index 100% rename from plugins/hls-tactics-plugin/test/golden/MetaTry.hs.expected rename to plugins/hls-tactics-plugin/test/golden/MetaTry.expected.hs diff --git a/plugins/hls-tactics-plugin/test/golden/NewtypeRecord.hs.expected b/plugins/hls-tactics-plugin/test/golden/NewtypeRecord.expected.hs similarity index 100% rename from plugins/hls-tactics-plugin/test/golden/NewtypeRecord.hs.expected rename to plugins/hls-tactics-plugin/test/golden/NewtypeRecord.expected.hs diff --git a/plugins/hls-tactics-plugin/test/golden/PunGADT.hs.expected b/plugins/hls-tactics-plugin/test/golden/PunGADT.expected.hs similarity index 100% rename from plugins/hls-tactics-plugin/test/golden/PunGADT.hs.expected rename to plugins/hls-tactics-plugin/test/golden/PunGADT.expected.hs diff --git a/plugins/hls-tactics-plugin/test/golden/PunMany.hs.expected b/plugins/hls-tactics-plugin/test/golden/PunMany.expected.hs similarity index 100% rename from plugins/hls-tactics-plugin/test/golden/PunMany.hs.expected rename to plugins/hls-tactics-plugin/test/golden/PunMany.expected.hs diff --git a/plugins/hls-tactics-plugin/test/golden/PunManyGADT.hs.expected b/plugins/hls-tactics-plugin/test/golden/PunManyGADT.expected.hs similarity index 100% rename from plugins/hls-tactics-plugin/test/golden/PunManyGADT.hs.expected rename to plugins/hls-tactics-plugin/test/golden/PunManyGADT.expected.hs diff --git a/plugins/hls-tactics-plugin/test/golden/PunShadowing.hs.expected b/plugins/hls-tactics-plugin/test/golden/PunShadowing.expected.hs similarity index 100% rename from plugins/hls-tactics-plugin/test/golden/PunShadowing.hs.expected rename to plugins/hls-tactics-plugin/test/golden/PunShadowing.expected.hs diff --git a/plugins/hls-tactics-plugin/test/golden/PunSimple.hs.expected b/plugins/hls-tactics-plugin/test/golden/PunSimple.expected.hs similarity index 100% rename from plugins/hls-tactics-plugin/test/golden/PunSimple.hs.expected rename to plugins/hls-tactics-plugin/test/golden/PunSimple.expected.hs diff --git a/plugins/hls-tactics-plugin/test/golden/RecordCon.hs.expected b/plugins/hls-tactics-plugin/test/golden/RecordCon.expected.hs similarity index 100% rename from plugins/hls-tactics-plugin/test/golden/RecordCon.hs.expected rename to plugins/hls-tactics-plugin/test/golden/RecordCon.expected.hs diff --git a/plugins/hls-tactics-plugin/test/golden/RefineCon.hs.expected b/plugins/hls-tactics-plugin/test/golden/RefineCon.expected.hs similarity index 100% rename from plugins/hls-tactics-plugin/test/golden/RefineCon.hs.expected rename to plugins/hls-tactics-plugin/test/golden/RefineCon.expected.hs diff --git a/plugins/hls-tactics-plugin/test/golden/RefineGADT.hs.expected b/plugins/hls-tactics-plugin/test/golden/RefineGADT.expected.hs similarity index 100% rename from plugins/hls-tactics-plugin/test/golden/RefineGADT.hs.expected rename to plugins/hls-tactics-plugin/test/golden/RefineGADT.expected.hs diff --git a/plugins/hls-tactics-plugin/test/golden/RefineIntro.hs.expected b/plugins/hls-tactics-plugin/test/golden/RefineIntro.expected.hs similarity index 100% rename from plugins/hls-tactics-plugin/test/golden/RefineIntro.hs.expected rename to plugins/hls-tactics-plugin/test/golden/RefineIntro.expected.hs diff --git a/plugins/hls-tactics-plugin/test/golden/RefineReader.hs.expected b/plugins/hls-tactics-plugin/test/golden/RefineReader.expected.hs similarity index 100% rename from plugins/hls-tactics-plugin/test/golden/RefineReader.hs.expected rename to plugins/hls-tactics-plugin/test/golden/RefineReader.expected.hs diff --git a/plugins/hls-tactics-plugin/test/golden/SplitPattern.hs.expected b/plugins/hls-tactics-plugin/test/golden/SplitPattern.expected.hs similarity index 100% rename from plugins/hls-tactics-plugin/test/golden/SplitPattern.hs.expected rename to plugins/hls-tactics-plugin/test/golden/SplitPattern.expected.hs diff --git a/plugins/hls-tactics-plugin/test/golden/UseConLeft.hs.expected b/plugins/hls-tactics-plugin/test/golden/UseConLeft.expected.hs similarity index 100% rename from plugins/hls-tactics-plugin/test/golden/UseConLeft.hs.expected rename to plugins/hls-tactics-plugin/test/golden/UseConLeft.expected.hs diff --git a/plugins/hls-tactics-plugin/test/golden/UseConPair.hs.expected b/plugins/hls-tactics-plugin/test/golden/UseConPair.expected.hs similarity index 100% rename from plugins/hls-tactics-plugin/test/golden/UseConPair.hs.expected rename to plugins/hls-tactics-plugin/test/golden/UseConPair.expected.hs diff --git a/plugins/hls-tactics-plugin/test/golden/UseConRight.hs.expected b/plugins/hls-tactics-plugin/test/golden/UseConRight.expected.hs similarity index 100% rename from plugins/hls-tactics-plugin/test/golden/UseConRight.hs.expected rename to plugins/hls-tactics-plugin/test/golden/UseConRight.expected.hs From 71c6f7c7b55de20cba1e2c6c4c44afa69eaa1d84 Mon Sep 17 00:00:00 2001 From: Junyoung/Clare Jang Date: Sun, 16 May 2021 20:33:14 -0400 Subject: [PATCH 20/20] Fix eval tests --- plugins/hls-eval-plugin/test/Main.hs | 5 ++--- plugins/hls-eval-plugin/test/testdata/T11.expected.hs | 2 +- plugins/hls-eval-plugin/test/testdata/T13.expected.hs | 2 +- plugins/hls-eval-plugin/test/testdata/T17.expected.hs | 2 +- plugins/hls-eval-plugin/test/testdata/T26.expected.hs | 2 +- plugins/hls-eval-plugin/test/testdata/T26.hs | 2 +- plugins/hls-eval-plugin/test/testdata/T8.expected.hs | 2 +- plugins/hls-eval-plugin/test/testdata/TFlags.expected.hs | 4 ++-- plugins/hls-eval-plugin/test/testdata/THaddock.expected.hs | 2 ++ plugins/hls-eval-plugin/test/testdata/THaddock.hs | 2 ++ .../{TLHSLateX.expected.lhs => TLHSLaTeX.expected.lhs} | 0 .../test/testdata/TLanguageOptionsTupleSections.expected.hs | 5 +++-- .../test/testdata/TLanguageOptionsTupleSections.hs | 2 +- plugins/hls-eval-plugin/test/testdata/TNested.expected.hs | 2 +- plugins/hls-eval-plugin/test/testdata/TNested.hs | 2 +- .../hls-eval-plugin/test/testdata/TPlainComment.expected.hs | 3 ++- plugins/hls-eval-plugin/test/testdata/TPlainComment.hs | 3 ++- plugins/hls-eval-plugin/test/testdata/cabal.project | 2 +- plugins/hls-eval-plugin/test/testdata/hie.yaml | 2 +- 19 files changed, 26 insertions(+), 20 deletions(-) rename plugins/hls-eval-plugin/test/testdata/{TLHSLateX.expected.lhs => TLHSLaTeX.expected.lhs} (100%) diff --git a/plugins/hls-eval-plugin/test/Main.hs b/plugins/hls-eval-plugin/test/Main.hs index d5de5477b6..eb7912e694 100644 --- a/plugins/hls-eval-plugin/test/Main.hs +++ b/plugins/hls-eval-plugin/test/Main.hs @@ -87,9 +87,8 @@ tests = , goldenWithEval "Evaluate expressions in Haddock comments in both single line and multi line format" "THaddock" "hs" , goldenWithEval "Compare results (for Haddock tests only)" "TCompare" "hs" , goldenWithEval "Local Modules imports are accessible in a test" "TLocalImport" "hs" - , -- , goldenWithEval "Local Modules can be imported in a test" "TLocalImportInTest" "hs" - expectFailBecause "Unexplained but minor issue" $ - goldenWithEval "Setting language option TupleSections" "TLanguageOptionsTupleSections" "hs" + -- , goldenWithEval "Local Modules can be imported in a test" "TLocalImportInTest" "hs" + , goldenWithEval "Setting language option TupleSections" "TLanguageOptionsTupleSections" "hs" , goldenWithEval ":set accepts ghci flags" "TFlags" "hs" , goldenWithEval "IO expressions are supported, stdout/stderr output is ignored" "TIO" "hs" , goldenWithEval "Property checking" "TProperty" "hs" diff --git a/plugins/hls-eval-plugin/test/testdata/T11.expected.hs b/plugins/hls-eval-plugin/test/testdata/T11.expected.hs index c3651ba3cc..fac41da1cd 100644 --- a/plugins/hls-eval-plugin/test/testdata/T11.expected.hs +++ b/plugins/hls-eval-plugin/test/testdata/T11.expected.hs @@ -1,4 +1,4 @@ module T11 where -- >>> :kind! a --- Not in scope: type variable 'a' +-- Not in scope: type variable ‘a’ diff --git a/plugins/hls-eval-plugin/test/testdata/T13.expected.hs b/plugins/hls-eval-plugin/test/testdata/T13.expected.hs index ef4643037e..c76a2af295 100644 --- a/plugins/hls-eval-plugin/test/testdata/T13.expected.hs +++ b/plugins/hls-eval-plugin/test/testdata/T13.expected.hs @@ -1,4 +1,4 @@ module T13 where -- >>> :kind a --- Not in scope: type variable 'a' +-- Not in scope: type variable ‘a’ diff --git a/plugins/hls-eval-plugin/test/testdata/T17.expected.hs b/plugins/hls-eval-plugin/test/testdata/T17.expected.hs index fd0bce327f..14e2aa74a1 100644 --- a/plugins/hls-eval-plugin/test/testdata/T17.expected.hs +++ b/plugins/hls-eval-plugin/test/testdata/T17.expected.hs @@ -1,4 +1,4 @@ module T17 where -- >>> :type +no 42 --- parse error on input '+' +-- parse error on input ‘+’ diff --git a/plugins/hls-eval-plugin/test/testdata/T26.expected.hs b/plugins/hls-eval-plugin/test/testdata/T26.expected.hs index bf9ebacc5a..c500f9b0e7 100644 --- a/plugins/hls-eval-plugin/test/testdata/T26.expected.hs +++ b/plugins/hls-eval-plugin/test/testdata/T26.expected.hs @@ -1,5 +1,5 @@ module T26 where -import T25 () +import Util () -- >>> "hello" -- "hello" diff --git a/plugins/hls-eval-plugin/test/testdata/T26.hs b/plugins/hls-eval-plugin/test/testdata/T26.hs index 424cdf12c5..059fc79ea9 100644 --- a/plugins/hls-eval-plugin/test/testdata/T26.hs +++ b/plugins/hls-eval-plugin/test/testdata/T26.hs @@ -1,4 +1,4 @@ module T26 where -import T25 () +import Util () -- >>> "hello" diff --git a/plugins/hls-eval-plugin/test/testdata/T8.expected.hs b/plugins/hls-eval-plugin/test/testdata/T8.expected.hs index 1a42fecfdf..2089d3d78f 100644 --- a/plugins/hls-eval-plugin/test/testdata/T8.expected.hs +++ b/plugins/hls-eval-plugin/test/testdata/T8.expected.hs @@ -5,7 +5,7 @@ module T8 where -- Variable not in scope: noFunctionWithThisName -- >>> "a" + "bc" --- No instance for (Num [Char]) arising from a use of '+' +-- No instance for (Num [Char]) arising from a use of ‘+’ -- >>> " -- lexical error in string/character literal at end of input diff --git a/plugins/hls-eval-plugin/test/testdata/TFlags.expected.hs b/plugins/hls-eval-plugin/test/testdata/TFlags.expected.hs index 9c20bf5889..9d6196e5bf 100644 --- a/plugins/hls-eval-plugin/test/testdata/TFlags.expected.hs +++ b/plugins/hls-eval-plugin/test/testdata/TFlags.expected.hs @@ -18,7 +18,7 @@ module TFlags where Options apply only in the section where they are defined (unless they are in the setup section), so this will fail: >>> class L a b c -Too many parameters for class 'L' +Too many parameters for class ‘L’ (Enable MultiParamTypeClasses to allow multi-parameter classes) -} @@ -29,7 +29,7 @@ Options apply to all tests in the same section after their declaration. Not set yet: >>> class D -No parameters for class 'D' +No parameters for class ‘D’ (Enable MultiParamTypeClasses to allow no-parameter classes) Now it works: diff --git a/plugins/hls-eval-plugin/test/testdata/THaddock.expected.hs b/plugins/hls-eval-plugin/test/testdata/THaddock.expected.hs index c7d0a6b5ef..222bedfc67 100644 --- a/plugins/hls-eval-plugin/test/testdata/THaddock.expected.hs +++ b/plugins/hls-eval-plugin/test/testdata/THaddock.expected.hs @@ -18,6 +18,7 @@ module THaddock () where "bc" -} +double :: Num a => a -> a double a = a + a -- ^ Single line backward comments -- >>> double 11 @@ -37,4 +38,5 @@ twice a = a ++ a >>> IGNORED as it does not start on the first column -} +five :: Integer five = 5 diff --git a/plugins/hls-eval-plugin/test/testdata/THaddock.hs b/plugins/hls-eval-plugin/test/testdata/THaddock.hs index 57cc5e70f8..03a28975e0 100644 --- a/plugins/hls-eval-plugin/test/testdata/THaddock.hs +++ b/plugins/hls-eval-plugin/test/testdata/THaddock.hs @@ -16,6 +16,7 @@ module THaddock () where >>> "b"++"c" -} +double :: Num a => a -> a double a = a + a -- ^ Single line backward comments -- >>> double 11 @@ -32,4 +33,5 @@ twice a = a ++ a >>> IGNORED as it does not start on the first column -} +five :: Integer five = 5 diff --git a/plugins/hls-eval-plugin/test/testdata/TLHSLateX.expected.lhs b/plugins/hls-eval-plugin/test/testdata/TLHSLaTeX.expected.lhs similarity index 100% rename from plugins/hls-eval-plugin/test/testdata/TLHSLateX.expected.lhs rename to plugins/hls-eval-plugin/test/testdata/TLHSLaTeX.expected.lhs diff --git a/plugins/hls-eval-plugin/test/testdata/TLanguageOptionsTupleSections.expected.hs b/plugins/hls-eval-plugin/test/testdata/TLanguageOptionsTupleSections.expected.hs index 2262df9109..c5f9e0ae60 100644 --- a/plugins/hls-eval-plugin/test/testdata/TLanguageOptionsTupleSections.expected.hs +++ b/plugins/hls-eval-plugin/test/testdata/TLanguageOptionsTupleSections.expected.hs @@ -1,8 +1,9 @@ -- This works fine: {-# LANGUAGE TupleSections #-} -module TLanguageOptionsTupleSection where +module TLanguageOptionsTupleSections where -- Why oh why is this not working? -- What is special about TupleSections? -- >>> :set -XTupleSections -- >>> ("a",) "b" --- ("a","b") \ No newline at end of file +-- ("a","b") + diff --git a/plugins/hls-eval-plugin/test/testdata/TLanguageOptionsTupleSections.hs b/plugins/hls-eval-plugin/test/testdata/TLanguageOptionsTupleSections.hs index 800f1fa525..c5f9e0ae60 100644 --- a/plugins/hls-eval-plugin/test/testdata/TLanguageOptionsTupleSections.hs +++ b/plugins/hls-eval-plugin/test/testdata/TLanguageOptionsTupleSections.hs @@ -1,5 +1,5 @@ -- This works fine: {-# LANGUAGE TupleSections #-} -module TLanguageOptionsTupleSection where +module TLanguageOptionsTupleSections where -- Why oh why is this not working? -- What is special about TupleSections? diff --git a/plugins/hls-eval-plugin/test/testdata/TNested.expected.hs b/plugins/hls-eval-plugin/test/testdata/TNested.expected.hs index 86369f01c1..ea5aa78423 100644 --- a/plugins/hls-eval-plugin/test/testdata/TNested.expected.hs +++ b/plugins/hls-eval-plugin/test/testdata/TNested.expected.hs @@ -1,4 +1,4 @@ -module TNseted () where +module TNested () where {- >>> 54 54 diff --git a/plugins/hls-eval-plugin/test/testdata/TNested.hs b/plugins/hls-eval-plugin/test/testdata/TNested.hs index 7acd11f5bc..8089bdb29b 100644 --- a/plugins/hls-eval-plugin/test/testdata/TNested.hs +++ b/plugins/hls-eval-plugin/test/testdata/TNested.hs @@ -1,4 +1,4 @@ -module TNseted () where +module TNested () where {- >>> 54 {- diff --git a/plugins/hls-eval-plugin/test/testdata/TPlainComment.expected.hs b/plugins/hls-eval-plugin/test/testdata/TPlainComment.expected.hs index 49333aaf4f..0243a715d8 100644 --- a/plugins/hls-eval-plugin/test/testdata/TPlainComment.expected.hs +++ b/plugins/hls-eval-plugin/test/testdata/TPlainComment.expected.hs @@ -4,7 +4,7 @@ Tests are ignored if: * do not start on the first column * are in multi line comments that open and close on the same line -} -module TPlain where +module TPlainComment where {- ORMOLU_DISABLE -} @@ -25,4 +25,5 @@ module TPlain where >>> IGNORED as it does not start on the first column -} +five :: Integer five = 5 diff --git a/plugins/hls-eval-plugin/test/testdata/TPlainComment.hs b/plugins/hls-eval-plugin/test/testdata/TPlainComment.hs index 4951f76874..2455d26a86 100644 --- a/plugins/hls-eval-plugin/test/testdata/TPlainComment.hs +++ b/plugins/hls-eval-plugin/test/testdata/TPlainComment.hs @@ -4,7 +4,7 @@ Tests are ignored if: * do not start on the first column * are in multi line comments that open and close on the same line -} -module TPlain where +module TPlainComment where {- ORMOLU_DISABLE -} @@ -22,4 +22,5 @@ module TPlain where >>> IGNORED as it does not start on the first column -} +five :: Integer five = 5 diff --git a/plugins/hls-eval-plugin/test/testdata/cabal.project b/plugins/hls-eval-plugin/test/testdata/cabal.project index e6fdbadb43..6f920794c8 100644 --- a/plugins/hls-eval-plugin/test/testdata/cabal.project +++ b/plugins/hls-eval-plugin/test/testdata/cabal.project @@ -1 +1 @@ -packages: . +packages: ./ diff --git a/plugins/hls-eval-plugin/test/testdata/hie.yaml b/plugins/hls-eval-plugin/test/testdata/hie.yaml index 7251e586cd..5aa5d712ea 100644 --- a/plugins/hls-eval-plugin/test/testdata/hie.yaml +++ b/plugins/hls-eval-plugin/test/testdata/hie.yaml @@ -1,4 +1,4 @@ cradle: cabal: - - path: "././" + - path: "./" component: "lib:test"