From 2583afcd414bae4ae62e96cc0332b0f0b51854eb Mon Sep 17 00:00:00 2001 From: Nick Suchecki Date: Tue, 6 Sep 2022 22:12:17 -0400 Subject: [PATCH 01/13] Only run the pre-commit hook on changed files --- .github/workflows/pre-commit.yml | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index af9f4981af..7a407edcf7 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -10,6 +10,10 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 + - uses: technote-space/get-diff-action@v4.0.1 + with: + PATTERNS: | + +src/**/*.hs - uses: ./.github/actions/setup-build with: @@ -20,10 +24,12 @@ jobs: run: | cabal install stylish-haskell echo "${HOME}/.cabal/bin" >> $GITHUB_PATH + if: env.GIT_DIFF - name: "Check stylish-haskell is available" run: | echo $(which stylish-haskell) + if: env.GIT_DIFF - name: Compiled deps cache id: stylish-haskell-compiled-cache @@ -37,6 +43,11 @@ jobs: ${{ inputs.cache-prefix }}${{ env.cache-name }}-${{ inputs.os }}-${{ inputs.ghc }}-${{ env.INDEX_STATE }}- ${{ inputs.cache-prefix }}${{ env.cache-name }}-${{ inputs.os }}-${{ inputs.ghc }}- ${{ inputs.cache-prefix }}${{ env.cache-name }}-${{ inputs.os }}- + if: env.GIT_DIFF - uses: actions/setup-python@v4 + if: env.GIT_DIFF - uses: pre-commit/action@v3.0.0 + with: + extra_args: --files env.GIT_DIFF + if: env.GIT_DIFF From 66dae39abcdc7931bf20144eaac46ba8682dbc5a Mon Sep 17 00:00:00 2001 From: Nick Suchecki Date: Tue, 6 Sep 2022 22:18:35 -0400 Subject: [PATCH 02/13] Let's change a haskell file --- .../src/Ide/Plugin/Literals.hs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/plugins/hls-alternate-number-format-plugin/src/Ide/Plugin/Literals.hs b/plugins/hls-alternate-number-format-plugin/src/Ide/Plugin/Literals.hs index a3935b92e9..a59e3de0e5 100644 --- a/plugins/hls-alternate-number-format-plugin/src/Ide/Plugin/Literals.hs +++ b/plugins/hls-alternate-number-format-plugin/src/Ide/Plugin/Literals.hs @@ -9,6 +9,7 @@ module Ide.Plugin.Literals ( , Literal(..) , getSrcText , getSrcSpan + , testCodeForPreCommitGithubAction ) where import Data.Maybe (maybeToList) @@ -71,6 +72,9 @@ type LocPat a = GenLocated SrcSpan (Pat a) type LocPat a = LPat a #endif +testCodeForPreCommitGithubAction :: String +testCodeForPreCommitGithubAction = undefined + -- | Destructure Patterns to unwrap any Literals getPattern :: LocPat GhcPs -> Maybe Literal getPattern (L (locA -> (RealSrcSpan patSpan _)) pat) = case pat of From eaf9f2e1573ef8b2763fbe990de7d5866e972821 Mon Sep 17 00:00:00 2001 From: Nick Suchecki Date: Tue, 6 Sep 2022 22:25:32 -0400 Subject: [PATCH 03/13] Didn't use the PATTERN field correctly --- .github/workflows/pre-commit.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index 7a407edcf7..57c0c07960 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -13,12 +13,13 @@ jobs: - uses: technote-space/get-diff-action@v4.0.1 with: PATTERNS: | - +src/**/*.hs + +(src|exe|test|ghcide|plugins|hls-plugin-api|hie-compat|hls-graph|hls-test-utils)/**/*.hs - uses: ./.github/actions/setup-build with: os: ${{ runner.os }} shorten-hls: false + if: env.GIT_DIFF - name: "Install stylish-haskell" run: | From 3c07cf1fae64a1a657e8d21a48d4a3bfb186b7ba Mon Sep 17 00:00:00 2001 From: Nick Suchecki Date: Tue, 6 Sep 2022 22:38:59 -0400 Subject: [PATCH 04/13] Move pre-commit block before building stylish-haskell --- .github/workflows/pre-commit.yml | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index 57c0c07960..827cf93f06 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -15,6 +15,13 @@ jobs: PATTERNS: | +(src|exe|test|ghcide|plugins|hls-plugin-api|hie-compat|hls-graph|hls-test-utils)/**/*.hs + - uses: actions/setup-python@v4 + if: env.GIT_DIFF + - uses: pre-commit/action@v3.0.0 + with: + extra_args: --files $env.GIT_DIFF + if: env.GIT_DIFF + - uses: ./.github/actions/setup-build with: os: ${{ runner.os }} @@ -46,9 +53,3 @@ jobs: ${{ inputs.cache-prefix }}${{ env.cache-name }}-${{ inputs.os }}- if: env.GIT_DIFF - - uses: actions/setup-python@v4 - if: env.GIT_DIFF - - uses: pre-commit/action@v3.0.0 - with: - extra_args: --files env.GIT_DIFF - if: env.GIT_DIFF From 94717b5bb4ca755c0983e460acae51eb68c2efac Mon Sep 17 00:00:00 2001 From: Nick Suchecki Date: Tue, 6 Sep 2022 22:40:44 -0400 Subject: [PATCH 05/13] Try to evaluate GIT_DIFF value to pass to pre-commit --- .github/workflows/pre-commit.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index 827cf93f06..00ac03189d 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -19,7 +19,7 @@ jobs: if: env.GIT_DIFF - uses: pre-commit/action@v3.0.0 with: - extra_args: --files $env.GIT_DIFF + extra_args: --files $GIT_DIFF if: env.GIT_DIFF - uses: ./.github/actions/setup-build From a74b699b7814f039bec9fe27a58d278664fae103 Mon Sep 17 00:00:00 2001 From: Nick Suchecki Date: Tue, 6 Sep 2022 22:42:37 -0400 Subject: [PATCH 06/13] Try to evaluate GIT_DIFF value to pass to pre-commit --- .github/workflows/pre-commit.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index 00ac03189d..cfe5ba5986 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -19,7 +19,7 @@ jobs: if: env.GIT_DIFF - uses: pre-commit/action@v3.0.0 with: - extra_args: --files $GIT_DIFF + extra_args: --files ${{ env.GIT_DIFF }} if: env.GIT_DIFF - uses: ./.github/actions/setup-build From 14355fb276f42a0c002dc0adc6bff28b8612f22a Mon Sep 17 00:00:00 2001 From: Nick Suchecki Date: Tue, 6 Sep 2022 22:44:28 -0400 Subject: [PATCH 07/13] Move pre-commit action back to original spot --- .github/workflows/pre-commit.yml | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index cfe5ba5986..a096a3951d 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -15,13 +15,6 @@ jobs: PATTERNS: | +(src|exe|test|ghcide|plugins|hls-plugin-api|hie-compat|hls-graph|hls-test-utils)/**/*.hs - - uses: actions/setup-python@v4 - if: env.GIT_DIFF - - uses: pre-commit/action@v3.0.0 - with: - extra_args: --files ${{ env.GIT_DIFF }} - if: env.GIT_DIFF - - uses: ./.github/actions/setup-build with: os: ${{ runner.os }} @@ -53,3 +46,9 @@ jobs: ${{ inputs.cache-prefix }}${{ env.cache-name }}-${{ inputs.os }}- if: env.GIT_DIFF + - uses: actions/setup-python@v4 + if: env.GIT_DIFF + - uses: pre-commit/action@v3.0.0 + with: + extra_args: --files ${{ env.GIT_DIFF }} + if: env.GIT_DIFF From b8bbbc9fa466ad46046f52cd0e498b5067f567f1 Mon Sep 17 00:00:00 2001 From: Nick Suchecki Date: Tue, 6 Sep 2022 22:50:42 -0400 Subject: [PATCH 08/13] Introduce bad formatting in a file --- ghcide/src/Development/IDE/Core/Compile.hs | 15 +++++++++------ .../src/Ide/Plugin/Literals.hs | 7 ++++++- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/ghcide/src/Development/IDE/Core/Compile.hs b/ghcide/src/Development/IDE/Core/Compile.hs index e6094a470d..b399e325f3 100644 --- a/ghcide/src/Development/IDE/Core/Compile.hs +++ b/ghcide/src/Development/IDE/Core/Compile.hs @@ -38,6 +38,7 @@ module Development.IDE.Core.Compile import Control.Concurrent.Extra import Control.Concurrent.STM.Stats hiding (orElse) + import Control.DeepSeq (NFData (..), force, liftRnf, rnf, rwhnf) import Control.Exception (evaluate) @@ -47,17 +48,17 @@ import Control.Monad.Except import Control.Monad.Extra import Control.Monad.Trans.Except import qualified Control.Monad.Trans.State.Strict as S -import Data.Aeson (toJSON) -import Data.Bifunctor (first, second) +import Data.Aeson (toJSON) +import Data.Bifunctor (first, second) import Data.Binary -import qualified Data.ByteString as BS +import qualified Data.ByteString as BS import Data.Coerce -import qualified Data.DList as DL +import qualified Data.DList as DL import Data.Functor import Data.Generics.Aliases import Data.Generics.Schemes import qualified Data.HashMap.Strict as HashMap -import Data.IntMap (IntMap) +import Data.IntMap (IntMap) import qualified Data.IntMap.Strict as IntMap import Data.IORef import Data.List.Extra @@ -147,7 +148,9 @@ parseModule parseModule IdeOptions{..} env filename ms = fmap (either (, Nothing) id) $ runExceptT $ do + (diag, modu) <- parseFileContents env optPreprocessor filename ms + return (diag, Just modu) @@ -159,7 +162,7 @@ computePackageDeps computePackageDeps env pkg = do case lookupUnit env pkg of Nothing -> return $ Left [ideErrorText (toNormalizedFilePath' noFilePath) $ - T.pack $ "unknown package: " ++ show pkg] + T.pack $ "unknown package: " ++ show pkg] Just pkgInfo -> return $ Right $ unitDepends pkgInfo data TypecheckHelpers diff --git a/plugins/hls-alternate-number-format-plugin/src/Ide/Plugin/Literals.hs b/plugins/hls-alternate-number-format-plugin/src/Ide/Plugin/Literals.hs index a59e3de0e5..913627f205 100644 --- a/plugins/hls-alternate-number-format-plugin/src/Ide/Plugin/Literals.hs +++ b/plugins/hls-alternate-number-format-plugin/src/Ide/Plugin/Literals.hs @@ -12,11 +12,16 @@ module Ide.Plugin.Literals ( , testCodeForPreCommitGithubAction ) where -import Data.Maybe (maybeToList) import Data.Text (Text) + +import Data.Maybe (maybeToList) + import qualified Data.Text as T + import Development.IDE.GHC.Compat hiding (getSrcSpan) + import Development.IDE.Graph.Classes (NFData (rnf)) + import Generics.SYB (Data, Typeable, everything, extQ) import qualified GHC.Generics as GHC From b3eb1edfb0c56a1e17787c8f0fcbeeb7b33aa44d Mon Sep 17 00:00:00 2001 From: Nick Suchecki Date: Tue, 6 Sep 2022 23:22:46 -0400 Subject: [PATCH 09/13] Conditionally run the pre-commit job only when there are haskell source changes --- .github/workflows/pre-commit.yml | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index a096a3951d..bb0ca8e7d2 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -6,31 +6,31 @@ on: branches: [master] jobs: - pre-commit: - runs-on: ubuntu-latest - steps: + file-diff: - uses: actions/checkout@v3 - uses: technote-space/get-diff-action@v4.0.1 with: PATTERNS: | +(src|exe|test|ghcide|plugins|hls-plugin-api|hie-compat|hls-graph|hls-test-utils)/**/*.hs + pre-commit: + needs: file-diff + if env.GIT_DIFF + runs-on: ubuntu-latest + steps: - uses: ./.github/actions/setup-build with: os: ${{ runner.os }} shorten-hls: false - if: env.GIT_DIFF - name: "Install stylish-haskell" run: | cabal install stylish-haskell echo "${HOME}/.cabal/bin" >> $GITHUB_PATH - if: env.GIT_DIFF - name: "Check stylish-haskell is available" run: | echo $(which stylish-haskell) - if: env.GIT_DIFF - name: Compiled deps cache id: stylish-haskell-compiled-cache @@ -44,11 +44,8 @@ jobs: ${{ inputs.cache-prefix }}${{ env.cache-name }}-${{ inputs.os }}-${{ inputs.ghc }}-${{ env.INDEX_STATE }}- ${{ inputs.cache-prefix }}${{ env.cache-name }}-${{ inputs.os }}-${{ inputs.ghc }}- ${{ inputs.cache-prefix }}${{ env.cache-name }}-${{ inputs.os }}- - if: env.GIT_DIFF - uses: actions/setup-python@v4 - if: env.GIT_DIFF - uses: pre-commit/action@v3.0.0 with: extra_args: --files ${{ env.GIT_DIFF }} - if: env.GIT_DIFF From 572a7567266cc8181699e22333e615ee29e97236 Mon Sep 17 00:00:00 2001 From: Nick Suchecki Date: Tue, 6 Sep 2022 23:26:06 -0400 Subject: [PATCH 10/13] Restore haskell files we used for testing --- ghcide/src/Development/IDE/Core/Compile.hs | 15 ++++++--------- .../src/Ide/Plugin/Literals.hs | 11 +---------- 2 files changed, 7 insertions(+), 19 deletions(-) diff --git a/ghcide/src/Development/IDE/Core/Compile.hs b/ghcide/src/Development/IDE/Core/Compile.hs index b399e325f3..e6094a470d 100644 --- a/ghcide/src/Development/IDE/Core/Compile.hs +++ b/ghcide/src/Development/IDE/Core/Compile.hs @@ -38,7 +38,6 @@ module Development.IDE.Core.Compile import Control.Concurrent.Extra import Control.Concurrent.STM.Stats hiding (orElse) - import Control.DeepSeq (NFData (..), force, liftRnf, rnf, rwhnf) import Control.Exception (evaluate) @@ -48,17 +47,17 @@ import Control.Monad.Except import Control.Monad.Extra import Control.Monad.Trans.Except import qualified Control.Monad.Trans.State.Strict as S -import Data.Aeson (toJSON) -import Data.Bifunctor (first, second) +import Data.Aeson (toJSON) +import Data.Bifunctor (first, second) import Data.Binary -import qualified Data.ByteString as BS +import qualified Data.ByteString as BS import Data.Coerce -import qualified Data.DList as DL +import qualified Data.DList as DL import Data.Functor import Data.Generics.Aliases import Data.Generics.Schemes import qualified Data.HashMap.Strict as HashMap -import Data.IntMap (IntMap) +import Data.IntMap (IntMap) import qualified Data.IntMap.Strict as IntMap import Data.IORef import Data.List.Extra @@ -148,9 +147,7 @@ parseModule parseModule IdeOptions{..} env filename ms = fmap (either (, Nothing) id) $ runExceptT $ do - (diag, modu) <- parseFileContents env optPreprocessor filename ms - return (diag, Just modu) @@ -162,7 +159,7 @@ computePackageDeps computePackageDeps env pkg = do case lookupUnit env pkg of Nothing -> return $ Left [ideErrorText (toNormalizedFilePath' noFilePath) $ - T.pack $ "unknown package: " ++ show pkg] + T.pack $ "unknown package: " ++ show pkg] Just pkgInfo -> return $ Right $ unitDepends pkgInfo data TypecheckHelpers diff --git a/plugins/hls-alternate-number-format-plugin/src/Ide/Plugin/Literals.hs b/plugins/hls-alternate-number-format-plugin/src/Ide/Plugin/Literals.hs index 913627f205..a3935b92e9 100644 --- a/plugins/hls-alternate-number-format-plugin/src/Ide/Plugin/Literals.hs +++ b/plugins/hls-alternate-number-format-plugin/src/Ide/Plugin/Literals.hs @@ -9,19 +9,13 @@ module Ide.Plugin.Literals ( , Literal(..) , getSrcText , getSrcSpan - , testCodeForPreCommitGithubAction ) where -import Data.Text (Text) - import Data.Maybe (maybeToList) - +import Data.Text (Text) import qualified Data.Text as T - import Development.IDE.GHC.Compat hiding (getSrcSpan) - import Development.IDE.Graph.Classes (NFData (rnf)) - import Generics.SYB (Data, Typeable, everything, extQ) import qualified GHC.Generics as GHC @@ -77,9 +71,6 @@ type LocPat a = GenLocated SrcSpan (Pat a) type LocPat a = LPat a #endif -testCodeForPreCommitGithubAction :: String -testCodeForPreCommitGithubAction = undefined - -- | Destructure Patterns to unwrap any Literals getPattern :: LocPat GhcPs -> Maybe Literal getPattern (L (locA -> (RealSrcSpan patSpan _)) pat) = case pat of From 99108875b3827fcc6c0f9b479a945246c171dcd8 Mon Sep 17 00:00:00 2001 From: Nick Suchecki Date: Tue, 6 Sep 2022 23:32:41 -0400 Subject: [PATCH 11/13] workflow fixes --- .github/workflows/pre-commit.yml | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index bb0ca8e7d2..6fc433a5f1 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -7,17 +7,20 @@ on: jobs: file-diff: + runs-on: ubuntu-latest + outputs: + changed_files: ${{ env.GIT_DIFF }} + steps: - uses: actions/checkout@v3 - uses: technote-space/get-diff-action@v4.0.1 with: PATTERNS: | +(src|exe|test|ghcide|plugins|hls-plugin-api|hie-compat|hls-graph|hls-test-utils)/**/*.hs pre-commit: - needs: file-diff - if env.GIT_DIFF runs-on: ubuntu-latest + needs: file-diff + if: needs.file-diff.changed_files steps: - - uses: ./.github/actions/setup-build with: os: ${{ runner.os }} @@ -48,4 +51,4 @@ jobs: - uses: actions/setup-python@v4 - uses: pre-commit/action@v3.0.0 with: - extra_args: --files ${{ env.GIT_DIFF }} + extra_args: --files ${{ needs.file-diff.changed_files }} From a8d928d49a26c89a870487ca994c9b3685bd03e1 Mon Sep 17 00:00:00 2001 From: Nick Suchecki Date: Tue, 6 Sep 2022 23:41:55 -0400 Subject: [PATCH 12/13] Try changing haskell source files with new workflow structure --- .github/workflows/pre-commit.yml | 21 ++++++++++++------- ghcide/src/Development/IDE/Plugin/HLS.hs | 13 ++++++------ .../src/Ide/Plugin/Literals.hs | 13 ++++++++---- 3 files changed, 29 insertions(+), 18 deletions(-) diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index 6fc433a5f1..bdff37b090 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -9,18 +9,23 @@ jobs: file-diff: runs-on: ubuntu-latest outputs: - changed_files: ${{ env.GIT_DIFF }} + git-diff: ${{ steps.git-diff.outputs.diff }} steps: - - uses: actions/checkout@v3 - - uses: technote-space/get-diff-action@v4.0.1 - with: - PATTERNS: | - +(src|exe|test|ghcide|plugins|hls-plugin-api|hie-compat|hls-graph|hls-test-utils)/**/*.hs + - name: Checkout code + uses: actions/checkout@v3 + - name: Find changed files + uses: technote-space/get-diff-action@v4.0.1 + id: git-diff + with: + PATTERNS: | + +(src|exe|test|ghcide|plugins|hls-plugin-api|hie-compat|hls-graph|hls-test-utils)/**/*.hs pre-commit: runs-on: ubuntu-latest needs: file-diff - if: needs.file-diff.changed_files steps: + - name: "ECHO changed files" + run: echo ${{ needs.file-diff.outputs.git-diff }} + - uses: actions/checkout@v3 - uses: ./.github/actions/setup-build with: os: ${{ runner.os }} @@ -51,4 +56,4 @@ jobs: - uses: actions/setup-python@v4 - uses: pre-commit/action@v3.0.0 with: - extra_args: --files ${{ needs.file-diff.changed_files }} + extra_args: --files ${{ needs.file-diff.outputs.git-diff }} diff --git a/ghcide/src/Development/IDE/Plugin/HLS.hs b/ghcide/src/Development/IDE/Plugin/HLS.hs index 8749a9efda..aaa8cc1ae7 100644 --- a/ghcide/src/Development/IDE/Plugin/HLS.hs +++ b/ghcide/src/Development/IDE/Plugin/HLS.hs @@ -10,16 +10,16 @@ module Development.IDE.Plugin.HLS ) where import Control.Exception (SomeException) -import Control.Lens ((^.)) +import Control.Lens ((^.)) import Control.Monad -import qualified Data.Aeson as J +import qualified Data.Aeson as J import Data.Dependent.Map (DMap) import qualified Data.Dependent.Map as DMap import Data.Dependent.Sum import Data.Either -import qualified Data.List as List +import qualified Data.List as List import Data.List.NonEmpty (NonEmpty, nonEmpty, toList) -import qualified Data.Map as Map +import qualified Data.Map as Map import Data.String import Data.Text (Text) import qualified Data.Text as T @@ -133,7 +133,7 @@ executeCommandHandlers recorder ecs = requestHandler SWorkspaceExecuteCommand ex parseCmdId x = case T.splitOn ":" x of [plugin, command] -> Just (PluginId plugin, CommandId command) [_, plugin, command] -> Just (PluginId plugin, CommandId command) - _ -> Nothing + _ -> Nothing -- The parameters to the HLS command are always the first element @@ -141,7 +141,7 @@ executeCommandHandlers recorder ecs = requestHandler SWorkspaceExecuteCommand ex let cmdParams :: J.Value cmdParams = case args of Just (J.List (x:_)) -> x - _ -> J.Null + _ -> J.Null case parseCmdId cmdId of -- Shortcut for immediately applying a applyWorkspaceEdit as a fallback for v3.8 code actions Just ("hls", "fallbackCodeAction") -> @@ -206,6 +206,7 @@ extensiblePlugins recorder xs = mempty { P.pluginHandlers = handlers } Nothing -> pure $ Left $ combineErrors errs Just xs -> do caps <- LSP.getClientCapabilities + pure $ Right $ combineResponses m config caps params xs -- --------------------------------------------------------------------- diff --git a/plugins/hls-alternate-number-format-plugin/src/Ide/Plugin/Literals.hs b/plugins/hls-alternate-number-format-plugin/src/Ide/Plugin/Literals.hs index a3935b92e9..460116e2a4 100644 --- a/plugins/hls-alternate-number-format-plugin/src/Ide/Plugin/Literals.hs +++ b/plugins/hls-alternate-number-format-plugin/src/Ide/Plugin/Literals.hs @@ -8,6 +8,7 @@ module Ide.Plugin.Literals ( collectLiterals , Literal(..) , getSrcText + , getSrcSpan ) where @@ -16,7 +17,7 @@ import Data.Text (Text) import qualified Data.Text as T import Development.IDE.GHC.Compat hiding (getSrcSpan) import Development.IDE.Graph.Classes (NFData (rnf)) -import Generics.SYB (Data, Typeable, everything, +import Generics.SYB (Data, Typeable, everything, extQ) import qualified GHC.Generics as GHC @@ -29,8 +30,12 @@ data Literal = IntLiteral LiteralSrcSpan Text Integer deriving (GHC.Generic, Show, Ord, Eq, Data) newtype LiteralSrcSpan = LiteralSrcSpan { unLit :: RealSrcSpan } + deriving (GHC.Generic, Show, Ord, Eq, Data) + + + instance NFData LiteralSrcSpan where rnf x = x `seq` () @@ -40,14 +45,14 @@ instance NFData Literal -- | Return a Literal's Source representation getSrcText :: Literal -> Text getSrcText = \case - IntLiteral _ txt _ -> txt + IntLiteral _ txt _ -> txt FracLiteral _ txt _ -> txt -- | Return a Literal's Real Source location getSrcSpan :: Literal -> RealSrcSpan getSrcSpan = \case - IntLiteral ss _ _ -> unLit ss - FracLiteral ss _ _ -> unLit ss + IntLiteral ss _ _ -> unLit ss + FracLiteral ss _ _ -> unLit ss -- | Find all literals in a Parsed Source File collectLiterals :: (Data ast, Typeable ast) => ast -> [Literal] From 998bbb5cd09dcbb384a85dfd9cc490adbebe2f9c Mon Sep 17 00:00:00 2001 From: Nick Suchecki Date: Wed, 7 Sep 2022 21:46:57 -0400 Subject: [PATCH 13/13] Revert all changes to files during testing --- .github/workflows/pre-commit.yml | 2 -- ghcide/src/Development/IDE/Plugin/HLS.hs | 13 ++++++------- .../src/Ide/Plugin/Literals.hs | 13 ++++--------- 3 files changed, 10 insertions(+), 18 deletions(-) diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index bdff37b090..c385ab2727 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -23,8 +23,6 @@ jobs: runs-on: ubuntu-latest needs: file-diff steps: - - name: "ECHO changed files" - run: echo ${{ needs.file-diff.outputs.git-diff }} - uses: actions/checkout@v3 - uses: ./.github/actions/setup-build with: diff --git a/ghcide/src/Development/IDE/Plugin/HLS.hs b/ghcide/src/Development/IDE/Plugin/HLS.hs index aaa8cc1ae7..8749a9efda 100644 --- a/ghcide/src/Development/IDE/Plugin/HLS.hs +++ b/ghcide/src/Development/IDE/Plugin/HLS.hs @@ -10,16 +10,16 @@ module Development.IDE.Plugin.HLS ) where import Control.Exception (SomeException) -import Control.Lens ((^.)) +import Control.Lens ((^.)) import Control.Monad -import qualified Data.Aeson as J +import qualified Data.Aeson as J import Data.Dependent.Map (DMap) import qualified Data.Dependent.Map as DMap import Data.Dependent.Sum import Data.Either -import qualified Data.List as List +import qualified Data.List as List import Data.List.NonEmpty (NonEmpty, nonEmpty, toList) -import qualified Data.Map as Map +import qualified Data.Map as Map import Data.String import Data.Text (Text) import qualified Data.Text as T @@ -133,7 +133,7 @@ executeCommandHandlers recorder ecs = requestHandler SWorkspaceExecuteCommand ex parseCmdId x = case T.splitOn ":" x of [plugin, command] -> Just (PluginId plugin, CommandId command) [_, plugin, command] -> Just (PluginId plugin, CommandId command) - _ -> Nothing + _ -> Nothing -- The parameters to the HLS command are always the first element @@ -141,7 +141,7 @@ executeCommandHandlers recorder ecs = requestHandler SWorkspaceExecuteCommand ex let cmdParams :: J.Value cmdParams = case args of Just (J.List (x:_)) -> x - _ -> J.Null + _ -> J.Null case parseCmdId cmdId of -- Shortcut for immediately applying a applyWorkspaceEdit as a fallback for v3.8 code actions Just ("hls", "fallbackCodeAction") -> @@ -206,7 +206,6 @@ extensiblePlugins recorder xs = mempty { P.pluginHandlers = handlers } Nothing -> pure $ Left $ combineErrors errs Just xs -> do caps <- LSP.getClientCapabilities - pure $ Right $ combineResponses m config caps params xs -- --------------------------------------------------------------------- diff --git a/plugins/hls-alternate-number-format-plugin/src/Ide/Plugin/Literals.hs b/plugins/hls-alternate-number-format-plugin/src/Ide/Plugin/Literals.hs index 460116e2a4..a3935b92e9 100644 --- a/plugins/hls-alternate-number-format-plugin/src/Ide/Plugin/Literals.hs +++ b/plugins/hls-alternate-number-format-plugin/src/Ide/Plugin/Literals.hs @@ -8,7 +8,6 @@ module Ide.Plugin.Literals ( collectLiterals , Literal(..) , getSrcText - , getSrcSpan ) where @@ -17,7 +16,7 @@ import Data.Text (Text) import qualified Data.Text as T import Development.IDE.GHC.Compat hiding (getSrcSpan) import Development.IDE.Graph.Classes (NFData (rnf)) -import Generics.SYB (Data, Typeable, everything, +import Generics.SYB (Data, Typeable, everything, extQ) import qualified GHC.Generics as GHC @@ -30,12 +29,8 @@ data Literal = IntLiteral LiteralSrcSpan Text Integer deriving (GHC.Generic, Show, Ord, Eq, Data) newtype LiteralSrcSpan = LiteralSrcSpan { unLit :: RealSrcSpan } - deriving (GHC.Generic, Show, Ord, Eq, Data) - - - instance NFData LiteralSrcSpan where rnf x = x `seq` () @@ -45,14 +40,14 @@ instance NFData Literal -- | Return a Literal's Source representation getSrcText :: Literal -> Text getSrcText = \case - IntLiteral _ txt _ -> txt + IntLiteral _ txt _ -> txt FracLiteral _ txt _ -> txt -- | Return a Literal's Real Source location getSrcSpan :: Literal -> RealSrcSpan getSrcSpan = \case - IntLiteral ss _ _ -> unLit ss - FracLiteral ss _ _ -> unLit ss + IntLiteral ss _ _ -> unLit ss + FracLiteral ss _ _ -> unLit ss -- | Find all literals in a Parsed Source File collectLiterals :: (Data ast, Typeable ast) => ast -> [Literal]