From c22081dfc012c5e4ec602836898ab7d4f6387048 Mon Sep 17 00:00:00 2001 From: GuillaumedeVolpiano <63950565+GuillaumedeVolpiano@users.noreply.github.com> Date: Tue, 1 Apr 2025 17:01:25 +0200 Subject: [PATCH] reinstating ignore-plugins-ghc-bounds (#4532) --- haskell-language-server.cabal | 78 +++++++++---------- .../src/Ide/Plugin/Cabal/Completion/Data.hs | 29 +++++-- plugins/hls-cabal-plugin/test/Completer.hs | 25 +++++- .../completions/autogen-completions.cabal | 19 +++++ .../src/Ide/Plugin/ModuleName.hs | 2 +- 5 files changed, 104 insertions(+), 49 deletions(-) create mode 100644 plugins/hls-cabal-plugin/test/testdata/completions/autogen-completions.cabal diff --git a/haskell-language-server.cabal b/haskell-language-server.cabal index 0990d3502c..9b6fcea31b 100644 --- a/haskell-language-server.cabal +++ b/haskell-language-server.cabal @@ -174,7 +174,7 @@ flag cabalgild manual: True common cabalgild - if flag(cabalgild) && impl(ghc < 9.11) + if flag(cabalgild) && (impl(ghc < 9.11) || flag(ignore-plugins-ghc-bounds)) build-depends: haskell-language-server:hls-cabal-gild-plugin cpp-options: -Dhls_cabalgild @@ -186,7 +186,7 @@ flag isolateCabalGildTests library hls-cabal-gild-plugin import: defaults, pedantic, warnings - if !flag(cabalgild) || impl(ghc > 9.11) + if !flag(cabalgild) || (impl(ghc > 9.11) && !flag(ignore-plugins-ghc-bounds)) buildable: False exposed-modules: Ide.Plugin.CabalGild hs-source-dirs: plugins/hls-cabal-gild-plugin/src @@ -203,7 +203,7 @@ library hls-cabal-gild-plugin -- The `hls-cabal-plugin` is needed for tests, as we need to install notification handlers test-suite hls-cabal-gild-plugin-tests import: defaults, pedantic, test-defaults, warnings - if !flag(cabalgild) || !flag(cabal) || impl(ghc > 9.11) + if !flag(cabalgild) || !flag(cabal) || (impl(ghc > 9.11) && !flag(ignore-plugins-ghc-bounds)) buildable: False type: exitcode-stdio-1.0 hs-source-dirs: plugins/hls-cabal-gild-plugin/test @@ -580,13 +580,13 @@ flag rename manual: True common rename - if flag(rename) && impl(ghc < 9.11) + if flag(rename) && (impl(ghc < 9.11) || flag(ignore-plugins-ghc-bounds)) build-depends: haskell-language-server:hls-rename-plugin cpp-options: -Dhls_rename library hls-rename-plugin import: defaults, pedantic, warnings - if !flag(rename) || impl(ghc > 9.11) + if !flag(rename) || (impl(ghc > 9.11) && !flag(ignore-plugins-ghc-bounds)) buildable: False exposed-modules: Ide.Plugin.Rename hs-source-dirs: plugins/hls-rename-plugin/src @@ -610,7 +610,7 @@ library hls-rename-plugin test-suite hls-rename-plugin-tests import: defaults, pedantic, test-defaults, warnings - if !flag(rename) || impl(ghc > 9.11) + if !flag(rename) || (impl(ghc > 9.11) && !flag(ignore-plugins-ghc-bounds)) buildable: False type: exitcode-stdio-1.0 hs-source-dirs: plugins/hls-rename-plugin/test @@ -636,13 +636,13 @@ flag retrie manual: True common retrie - if flag(retrie) && impl(ghc < 9.10) + if flag(retrie) && (impl(ghc < 9.10) || flag(ignore-plugins-ghc-bounds)) build-depends: haskell-language-server:hls-retrie-plugin cpp-options: -Dhls_retrie library hls-retrie-plugin import: defaults, pedantic, warnings - if !(flag(retrie) && impl(ghc < 9.10)) + if !(flag(retrie) && (impl(ghc < 9.10) || flag(ignore-plugins-ghc-bounds))) buildable: False exposed-modules: Ide.Plugin.Retrie hs-source-dirs: plugins/hls-retrie-plugin/src @@ -673,7 +673,7 @@ library hls-retrie-plugin test-suite hls-retrie-plugin-tests import: defaults, pedantic, test-defaults, warnings - if !(flag(retrie) && impl(ghc < 9.10)) + if !(flag(retrie) && (impl(ghc < 9.10) || flag(ignore-plugins-ghc-bounds))) buildable: False type: exitcode-stdio-1.0 hs-source-dirs: plugins/hls-retrie-plugin/test @@ -703,14 +703,14 @@ flag hlint manual: True common hlint - if flag(hlint) && impl(ghc < 9.10) + if flag(hlint) && (impl(ghc < 9.10) || flag(ignore-plugins-ghc-bounds)) build-depends: haskell-language-server:hls-hlint-plugin cpp-options: -Dhls_hlint library hls-hlint-plugin import: defaults, pedantic, warnings -- https://github.com/ndmitchell/hlint/pull/1594 - if !(flag(hlint)) || impl(ghc > 9.10) + if !(flag(hlint)) || (impl(ghc > 9.10) && !flag(ignore-plugins-ghc-bounds)) buildable: False exposed-modules: Ide.Plugin.Hlint hs-source-dirs: plugins/hls-hlint-plugin/src @@ -753,7 +753,7 @@ library hls-hlint-plugin test-suite hls-hlint-plugin-tests import: defaults, pedantic, test-defaults, warnings - if (!flag(hlint)) || impl(ghc > 9.10) + if (!flag(hlint)) || (impl(ghc > 9.10) && !flag(ignore-plugins-ghc-bounds)) buildable: False type: exitcode-stdio-1.0 hs-source-dirs: plugins/hls-hlint-plugin/test @@ -782,13 +782,13 @@ flag stan manual: True common stan - if flag(stan) && impl(ghc < 9.11) + if flag(stan) && (impl(ghc < 9.11) || flag(ignore-plugins-ghc-bounds)) build-depends: haskell-language-server:hls-stan-plugin cpp-options: -Dhls_stan library hls-stan-plugin import: defaults, pedantic, warnings - if !flag(stan) || impl(ghc > 9.11) + if !flag(stan) || (impl(ghc > 9.11) && !flag(ignore-plugins-ghc-bounds)) buildable: False exposed-modules: Ide.Plugin.Stan hs-source-dirs: plugins/hls-stan-plugin/src @@ -813,7 +813,7 @@ library hls-stan-plugin test-suite hls-stan-plugin-tests import: defaults, pedantic, test-defaults, warnings - if !flag(stan) || impl(ghc > 9.11) + if !flag(stan) || (impl(ghc > 9.11) && !flag(ignore-plugins-ghc-bounds)) buildable: False type: exitcode-stdio-1.0 hs-source-dirs: plugins/hls-stan-plugin/test @@ -932,13 +932,13 @@ flag splice manual: True common splice - if flag(splice) && impl(ghc < 9.10) + if flag(splice) && (impl(ghc < 9.10) || flag(ignore-plugins-ghc-bounds)) build-depends: haskell-language-server:hls-splice-plugin cpp-options: -Dhls_splice library hls-splice-plugin import: defaults, pedantic, warnings - if !(flag(splice) && impl(ghc < 9.10)) + if !(flag(splice) && (impl(ghc < 9.10) || flag(ignore-plugins-ghc-bounds))) buildable: False exposed-modules: Ide.Plugin.Splice @@ -966,7 +966,7 @@ library hls-splice-plugin test-suite hls-splice-plugin-tests import: defaults, pedantic, test-defaults, warnings - if !(flag(splice) && impl(ghc < 9.10)) + if !(flag(splice) && (impl(ghc < 9.10) || flag(ignore-plugins-ghc-bounds))) buildable: False type: exitcode-stdio-1.0 hs-source-dirs: plugins/hls-splice-plugin/test @@ -1208,13 +1208,13 @@ flag gadt manual: True common gadt - if flag(gadt) && impl(ghc < 9.11) + if flag(gadt) && (impl(ghc < 9.11) || flag(ignore-plugins-ghc-bounds)) build-depends: haskell-language-server:hls-gadt-plugin cpp-options: -Dhls_gadt library hls-gadt-plugin import: defaults, pedantic, warnings - if !flag(gadt) || impl(ghc > 9.11) + if !flag(gadt) || (impl(ghc > 9.11) && !flag(ignore-plugins-ghc-bounds)) buildable: False exposed-modules: Ide.Plugin.GADT other-modules: Ide.Plugin.GHC @@ -1238,7 +1238,7 @@ library hls-gadt-plugin test-suite hls-gadt-plugin-tests import: defaults, pedantic, test-defaults, warnings - if !flag(gadt) || impl(ghc > 9.11) + if !flag(gadt) || (impl(ghc > 9.11) && !flag(ignore-plugins-ghc-bounds)) buildable: False type: exitcode-stdio-1.0 hs-source-dirs: plugins/hls-gadt-plugin/test @@ -1400,14 +1400,14 @@ flag floskell manual: True common floskell - if flag(floskell) && impl(ghc < 9.10) + if flag(floskell) && (impl(ghc < 9.10) || flag(ignore-plugins-ghc-bounds)) build-depends: haskell-language-server:hls-floskell-plugin cpp-options: -Dhls_floskell library hls-floskell-plugin import: defaults, pedantic, warnings -- https://github.com/ennocramer/floskell/pull/82 - if !(flag(floskell) && impl(ghc < 9.10)) + if !(flag(floskell) && (impl(ghc < 9.10) || flag(ignore-plugins-ghc-bounds))) buildable: False exposed-modules: Ide.Plugin.Floskell hs-source-dirs: plugins/hls-floskell-plugin/src @@ -1422,7 +1422,7 @@ library hls-floskell-plugin test-suite hls-floskell-plugin-tests import: defaults, pedantic, test-defaults, warnings - if !(flag(floskell) && impl(ghc < 9.10)) + if !(flag(floskell) && (impl(ghc < 9.10) || flag(ignore-plugins-ghc-bounds))) buildable: False type: exitcode-stdio-1.0 hs-source-dirs: plugins/hls-floskell-plugin/test @@ -1442,13 +1442,13 @@ flag fourmolu manual: True common fourmolu - if flag(fourmolu) && impl(ghc < 9.11) + if flag(fourmolu) && (impl(ghc < 9.11) || flag(ignore-plugins-ghc-bounds)) build-depends: haskell-language-server:hls-fourmolu-plugin cpp-options: -Dhls_fourmolu library hls-fourmolu-plugin import: defaults, pedantic, warnings - if !flag(fourmolu) || impl(ghc > 9.11) + if !flag(fourmolu) || (impl(ghc > 9.11) && !flag(ignore-plugins-ghc-bounds)) buildable: False exposed-modules: Ide.Plugin.Fourmolu hs-source-dirs: plugins/hls-fourmolu-plugin/src @@ -1468,7 +1468,7 @@ library hls-fourmolu-plugin test-suite hls-fourmolu-plugin-tests import: defaults, pedantic, test-defaults, warnings - if !flag(fourmolu) || impl(ghc > 9.11) + if !flag(fourmolu) || (impl(ghc > 9.11) && !flag(ignore-plugins-ghc-bounds)) buildable: False type: exitcode-stdio-1.0 hs-source-dirs: plugins/hls-fourmolu-plugin/test @@ -1496,13 +1496,13 @@ flag ormolu manual: True common ormolu - if flag(ormolu) && impl(ghc < 9.11) + if flag(ormolu) && (impl(ghc < 9.11) || flag(ignore-plugins-ghc-bounds)) build-depends: haskell-language-server:hls-ormolu-plugin cpp-options: -Dhls_ormolu library hls-ormolu-plugin import: defaults, pedantic, warnings - if !flag(ormolu) || impl(ghc > 9.11) + if !flag(ormolu) || (impl(ghc > 9.11) && !flag(ignore-plugins-ghc-bounds)) buildable: False exposed-modules: Ide.Plugin.Ormolu hs-source-dirs: plugins/hls-ormolu-plugin/src @@ -1522,7 +1522,7 @@ library hls-ormolu-plugin test-suite hls-ormolu-plugin-tests import: defaults, pedantic, test-defaults, warnings - if !flag(ormolu) || impl(ghc > 9.11) + if !flag(ormolu) || (impl(ghc > 9.11) && !flag(ignore-plugins-ghc-bounds)) buildable: False type: exitcode-stdio-1.0 hs-source-dirs: plugins/hls-ormolu-plugin/test @@ -1551,14 +1551,14 @@ flag stylishHaskell manual: True common stylishHaskell - if flag(stylishHaskell) && impl(ghc < 9.10) + if flag(stylishHaskell) && (impl(ghc < 9.10) || flag(ignore-plugins-ghc-bounds)) build-depends: haskell-language-server:hls-stylish-haskell-plugin cpp-options: -Dhls_stylishHaskell library hls-stylish-haskell-plugin import: defaults, pedantic, warnings -- https://github.com/haskell/stylish-haskell/issues/479 - if !(flag(stylishHaskell) && impl(ghc < 9.10)) + if !(flag(stylishHaskell) && (impl(ghc < 9.10) || flag(ignore-plugins-ghc-bounds))) buildable: False exposed-modules: Ide.Plugin.StylishHaskell hs-source-dirs: plugins/hls-stylish-haskell-plugin/src @@ -1576,7 +1576,7 @@ library hls-stylish-haskell-plugin test-suite hls-stylish-haskell-plugin-tests import: defaults, pedantic, test-defaults, warnings - if !(flag(stylishHaskell) && impl(ghc < 9.10)) + if !(flag(stylishHaskell) && (impl(ghc < 9.10) || flag(ignore-plugins-ghc-bounds))) buildable: False type: exitcode-stdio-1.0 hs-source-dirs: plugins/hls-stylish-haskell-plugin/test @@ -1596,13 +1596,13 @@ flag refactor manual: True common refactor - if flag(refactor) && impl(ghc < 9.11) + if flag(refactor) && (impl(ghc < 9.11) || flag(ignore-plugins-ghc-bounds)) build-depends: haskell-language-server:hls-refactor-plugin cpp-options: -Dhls_refactor library hls-refactor-plugin import: defaults, pedantic, warnings - if !flag(refactor) || impl(ghc > 9.11) + if !flag(refactor) || (impl(ghc > 9.11) && !flag(ignore-plugins-ghc-bounds)) buildable: False exposed-modules: Development.IDE.GHC.ExactPrint Development.IDE.GHC.Compat.ExactPrint @@ -1661,7 +1661,7 @@ library hls-refactor-plugin test-suite hls-refactor-plugin-tests import: defaults, pedantic, test-defaults, warnings - if !flag(refactor) || impl(ghc > 9.11) + if !flag(refactor) || (impl(ghc > 9.11) && !flag(ignore-plugins-ghc-bounds)) buildable: False type: exitcode-stdio-1.0 hs-source-dirs: plugins/hls-refactor-plugin/test @@ -2007,11 +2007,11 @@ test-suite func-test if flag(eval) cpp-options: -Dhls_eval -- formatters - if flag(floskell) && impl(ghc < 9.10) + if flag(floskell) && (impl(ghc < 9.10) || flag(ignore-plugins-ghc-bounds)) cpp-options: -Dhls_floskell - if flag(fourmolu) && impl(ghc < 9.11) + if flag(fourmolu) && (impl(ghc < 9.11) || flag(ignore-plugins-ghc-bounds)) cpp-options: -Dhls_fourmolu - if flag(ormolu) && impl(ghc < 9.11) + if flag(ormolu) && (impl(ghc < 9.11) || flag(ignore-plugins-ghc-bounds)) cpp-options: -Dhls_ormolu test-suite wrapper-test diff --git a/plugins/hls-cabal-plugin/src/Ide/Plugin/Cabal/Completion/Data.hs b/plugins/hls-cabal-plugin/src/Ide/Plugin/Cabal/Completion/Data.hs index c27568d692..a8872b38d5 100644 --- a/plugins/hls-cabal-plugin/src/Ide/Plugin/Cabal/Completion/Data.hs +++ b/plugins/hls-cabal-plugin/src/Ide/Plugin/Cabal/Completion/Data.hs @@ -71,12 +71,12 @@ cabalKeywords = stanzaKeywordMap :: Map StanzaType (Map KeyWordName Completer) stanzaKeywordMap = Map.fromList - [ ("library", libraryFields <> libExecTestBenchCommons), - ("executable", executableFields <> libExecTestBenchCommons), - ("test-suite", testSuiteFields <> libExecTestBenchCommons), - ("benchmark", benchmarkFields <> libExecTestBenchCommons), - ("foreign-library", foreignLibraryFields <> libExecTestBenchCommons), - ("common", libExecTestBenchCommons), + [ ("library", libraryFields <> libExecTestBenchCommons "library"), + ("executable", executableFields <> libExecTestBenchCommons "executable"), + ("test-suite", testSuiteFields <> libExecTestBenchCommons "test-suite"), + ("benchmark", benchmarkFields <> libExecTestBenchCommons "benchmark"), + ("foreign-library", foreignLibraryFields <> libExecTestBenchCommons "benchmark"), + ("common", libExecTestBenchCommons "library"), ("flag", flagFields), ("source-repository", sourceRepositoryFields) ] @@ -91,6 +91,7 @@ libraryFields = ("reexported-modules:", noopCompleter), ("signatures:", noopCompleter), ("other-modules:", modulesCompleter sourceDirsExtractionLibrary) + ] executableFields :: Map KeyWordName Completer @@ -162,8 +163,20 @@ flagFields = ("lib-version-linux:", noopCompleter) ] -libExecTestBenchCommons :: Map KeyWordName Completer -libExecTestBenchCommons = +libExecTestBenchCommons :: StanzaType -> Map KeyWordName Completer +libExecTestBenchCommons stanza = + Map.insert "autogen-modules:" (modulesCompleter extractor) $ + Map.insert "autogen-includes:" filePathCompleter baseBenchCommons + where + extractor = case stanza of + "library" -> sourceDirsExtractionLibrary + "executable" -> sourceDirsExtractionExecutable + "test-suite" -> sourceDirsExtractionTestSuite + "benchmark" -> sourceDirsExtractionBenchmark + _ -> sourceDirsExtractionLibrary + +baseBenchCommons :: Map KeyWordName Completer +baseBenchCommons = Map.fromList [ ("import:", importCompleter), ("build-depends:", noopCompleter), diff --git a/plugins/hls-cabal-plugin/test/Completer.hs b/plugins/hls-cabal-plugin/test/Completer.hs index 6b1f772af0..af1ce2de4e 100644 --- a/plugins/hls-cabal-plugin/test/Completer.hs +++ b/plugins/hls-cabal-plugin/test/Completer.hs @@ -40,9 +40,32 @@ completerTests = completionHelperTests, filePathExposedModulesTests, exposedModuleCompleterTests, - importCompleterTests + importCompleterTests, + autogenModulesCompletionTests ] +autogenModulesCompletionTests :: TestTree +autogenModulesCompletionTests = + testGroup + "Autogen modules completion" + [ checkCompletion "library" (Position 4 4) ["autogen-modules:", "autogen-includes:"] + , checkCompletion "executable" (Position 8 4) ["autogen-modules:"] + , checkCompletion "test-suite" (Position 13 4) ["autogen-modules:", "autogen-includes:"] + , checkCompletion "benchmark" (Position 18 4) ["autogen-modules:", "autogen-includes:"] + ] + where + checkCompletion :: String -> Position -> [T.Text] -> TestTree + checkCompletion name pos expectedLabels = + runCabalTestCaseSession ("Completes autogen fields in " ++ name ++ " stanza") "" $ do + doc <- openDoc "completions/autogen-completions.cabal" "cabal" + completions <- getCompletions doc pos + liftIO $ mapM_ (\label -> + assertBool (T.unpack label ++ " should be in completions") $ + any (\c -> T.isInfixOf label (c ^. L.label)) completions + ) expectedLabels + + + basicCompleterTests :: TestTree basicCompleterTests = testGroup diff --git a/plugins/hls-cabal-plugin/test/testdata/completions/autogen-completions.cabal b/plugins/hls-cabal-plugin/test/testdata/completions/autogen-completions.cabal new file mode 100644 index 0000000000..ec0bad9484 --- /dev/null +++ b/plugins/hls-cabal-plugin/test/testdata/completions/autogen-completions.cabal @@ -0,0 +1,19 @@ +cabal-version: 3.2 +name: test-project + +library + autogen + +executable exe + main-is: Main.hs + autogen + +test-suite test + type: exitcode-stdio-1.0 + main-is: Test.hs + autogen + +benchmark bench + type: exitcode-stdio-1.0 + main-is: Bench.hs + autogen diff --git a/plugins/hls-module-name-plugin/src/Ide/Plugin/ModuleName.hs b/plugins/hls-module-name-plugin/src/Ide/Plugin/ModuleName.hs index 5dc053f47d..0122a0b5c2 100644 --- a/plugins/hls-module-name-plugin/src/Ide/Plugin/ModuleName.hs +++ b/plugins/hls-module-name-plugin/src/Ide/Plugin/ModuleName.hs @@ -150,7 +150,7 @@ pathModuleNames recorder state normFilePath filePath -- TODO, this can be avoid if the filePath is already absolute, -- we can avoid the toAbsolute call in the future. -- see Note [Root Directory] - let mdlPath = (toAbsolute $ rootDir state) filePath + let mdlPath = normalise $ (toAbsolute $ rootDir state) filePath logWith recorder Debug (AbsoluteFilePath mdlPath) let suffixes = mapMaybe (`stripPrefix` mdlPath) paths