Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Change Type Family Export pattern #2643

Merged
merged 3 commits into from
Jan 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions ghcide/src/Development/IDE/Plugin/CodeAction.hs
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ suggestDeleteUnusedBinding
isSameName :: IdP GhcPs -> String -> Bool
isSameName x name = showSDocUnsafe (ppr x) == name

data ExportsAs = ExportName | ExportPattern | ExportAll
data ExportsAs = ExportName | ExportPattern | ExportFamily | ExportAll
deriving (Eq)

getLocatedRange :: Located a -> Maybe Range
Expand Down Expand Up @@ -602,6 +602,7 @@ suggestExportUnusedTopBinding srcOpt ParsedModule{pm_parsed_source = L _ HsModul
printExport :: ExportsAs -> T.Text -> T.Text
printExport ExportName x = parenthesizeIfNeeds False x
printExport ExportPattern x = "pattern " <> x
printExport ExportFamily x = parenthesizeIfNeeds True x
printExport ExportAll x = parenthesizeIfNeeds True x <> "(..)"

isTopLevel :: Range -> Bool
Expand All @@ -613,7 +614,7 @@ suggestExportUnusedTopBinding srcOpt ParsedModule{pm_parsed_source = L _ HsModul
exportsAs (TyClD _ SynDecl{tcdLName}) = Just (ExportName, reLoc tcdLName)
exportsAs (TyClD _ DataDecl{tcdLName}) = Just (ExportAll, reLoc tcdLName)
exportsAs (TyClD _ ClassDecl{tcdLName}) = Just (ExportAll, reLoc tcdLName)
exportsAs (TyClD _ FamDecl{tcdFam}) = Just (ExportAll, reLoc $ fdLName tcdFam)
exportsAs (TyClD _ FamDecl{tcdFam}) = Just (ExportFamily, reLoc $ fdLName tcdFam)
exportsAs _ = Nothing

suggestAddTypeAnnotationToSatisfyContraints :: Maybe T.Text -> Diagnostic -> [(T.Text, [TextEdit])]
Expand Down
23 changes: 13 additions & 10 deletions ghcide/test/exe/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ module Main (main) where

import Control.Applicative.Combinators
import Control.Concurrent
import Control.Exception (bracket_, catch, finally)
import Control.Exception (bracket_, catch,
finally)
import qualified Control.Lens as Lens
import Control.Monad
import Control.Monad.IO.Class (MonadIO, liftIO)
Expand All @@ -44,22 +45,23 @@ import Development.IDE.Plugin.TypeLenses (typeLensCommandId)
import Development.IDE.Spans.Common
import Development.IDE.Test (Cursor,
canonicalizeUri,
configureCheckProject,
diagnostic,
expectCurrentDiagnostics,
expectDiagnostics,
expectDiagnosticsWithTags,
expectMessages,
expectNoMoreDiagnostics,
flushMessages,
standardizeQuotes,
getInterfaceFilesDir,
waitForAction,
getStoredKeys,
waitForTypecheck, waitForGC, configureCheckProject)
standardizeQuotes,
waitForAction,
waitForGC,
waitForTypecheck)
import Development.IDE.Test.Runfiles
import qualified Development.IDE.Types.Diagnostics as Diagnostics
import Development.IDE.Types.Location
import qualified Language.LSP.Types.Lens as Lens (label)
import Development.Shake (getDirectoryFilesIO)
import qualified Experiments as Bench
import Ide.Plugin.Config
Expand All @@ -70,6 +72,7 @@ import Language.LSP.Types hiding
SemanticTokensEdit (_start),
mkRange)
import Language.LSP.Types.Capabilities
import qualified Language.LSP.Types.Lens as Lens (label)
import qualified Language.LSP.Types.Lens as Lsp (diagnostics,
message,
params)
Expand All @@ -82,15 +85,15 @@ import System.Exit (ExitCode (ExitSuccess
import System.FilePath
import System.IO.Extra hiding (withTempDir)
import qualified System.IO.Extra
import System.Info.Extra (isWindows, isMac)
import System.Info.Extra (isMac, isWindows)
import System.Mem (performGC)
import System.Process.Extra (CreateProcess (cwd),
createPipe, proc,
readCreateProcessWithExitCode)
import Test.QuickCheck
-- import Test.QuickCheck.Instances ()
import Control.Concurrent.Async
import Control.Lens ((^.), to)
import Control.Lens (to, (^.))
import Control.Monad.Extra (whenJust)
import Data.IORef
import Data.IORef.Extra (atomicModifyIORef_)
Expand All @@ -102,6 +105,7 @@ import qualified Development.IDE.Plugin.HLS.GhcIde as Ghcide
import Development.IDE.Plugin.Test (TestRequest (BlockSeconds),
WaitForIdeRuleResult (..),
blockCommandId)
import qualified HieDbRetry
import Ide.PluginUtils (pluginDescToIdePlugins)
import Ide.Types
import qualified Language.LSP.Types as LSP
Expand All @@ -115,7 +119,6 @@ import Test.Tasty.Ingredients.Rerun
import Test.Tasty.QuickCheck
import Text.Printf (printf)
import Text.Regex.TDFA ((=~))
import qualified HieDbRetry

-- | Wait for the next progress begin step
waitForProgressBegin :: Session ()
Expand Down Expand Up @@ -3466,7 +3469,7 @@ exportUnusedTests = testGroup "export unused actions"
(Just $ T.unlines
[ "{-# OPTIONS_GHC -Wunused-top-binds #-}"
, "{-# LANGUAGE TypeFamilies #-}"
, "module A (Foo(..)) where"
, "module A (Foo) where"
, "type family Foo p"])
, testSession "unused typeclass" $ template
(T.unlines
Expand Down Expand Up @@ -3527,7 +3530,7 @@ exportUnusedTests = testGroup "export unused actions"
[ "{-# OPTIONS_GHC -Wunused-top-binds #-}"
, "{-# LANGUAGE TypeFamilies #-}"
, "{-# LANGUAGE TypeOperators #-}"
, "module A (type (:<)(..)) where"
, "module A (type (:<)) where"
, "type family (:<)"])
, testSession "typeclass operator" $ template
(T.unlines
Expand Down