Skip to content

Commit

Permalink
Merge branch 'master' into stack-cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
pepeiborra authored May 1, 2022
2 parents 5c2ddd9 + e6aa0aa commit 6f06669
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 9 deletions.
3 changes: 3 additions & 0 deletions ghcide/ghcide.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ library
hie-bios ^>= 0.9.1,
implicit-hie-cradle ^>= 0.3.0.5 || ^>= 0.5,
base16-bytestring >=0.1.1 && <1.1
if impl(ghc >= 9.2)
build-depends:
ghc-exactprint >= 1.4
if os(windows)
build-depends:
Win32
Expand Down
4 changes: 0 additions & 4 deletions ghcide/src/Development/IDE/GHC/Compat/Util.hs
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,6 @@ module Development.IDE.GHC.Compat.Util (
stringToStringBuffer,
nextChar,
atEnd,
-- * Char
is_ident
) where

#if MIN_VERSION_ghc(9,0,0)
Expand All @@ -83,7 +81,6 @@ import GHC.Data.FastString
import GHC.Data.Maybe
import GHC.Data.Pair
import GHC.Data.StringBuffer
import GHC.Parser.CharClass (is_ident)
import GHC.Types.Unique
import GHC.Types.Unique.DFM
import GHC.Utils.Fingerprint
Expand All @@ -93,7 +90,6 @@ import GHC.Utils.Panic hiding (try)
#else
import Bag
import BooleanFormula
import Ctype (is_ident)
import EnumSet
import qualified Exception
import FastString
Expand Down
13 changes: 8 additions & 5 deletions ghcide/src/Development/IDE/Plugin/CodeAction.hs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ import qualified Data.Rope.UTF16 as Rope
import qualified Data.Set as S
import qualified Data.Text as T
import Data.Tuple.Extra (fst3)
import Development.IDE.Core.RuleTypes
import Development.IDE.Core.Rules
import Development.IDE.Core.RuleTypes
import Development.IDE.Core.Service
import Development.IDE.GHC.Compat
import Development.IDE.GHC.Compat.Util
Expand Down Expand Up @@ -1631,8 +1631,11 @@ rangesForBindingImport _ _ = []
wrapOperatorInParens :: String -> String
wrapOperatorInParens x =
case uncons x of
Just (h, _t) -> if is_ident h then x else "(" <> x <> ")"
Nothing -> mempty
-- see #2483 and #2859
-- common lens functions use the _ prefix, and should not be wrapped in parens
Just ('_', _t) -> x
Just (h, _t) -> if isAlpha h then x else "(" <> x <> ")"
Nothing -> mempty

smallerRangesForBindingExport :: [LIE GhcPs] -> String -> [Range]
smallerRangesForBindingExport lies b =
Expand Down Expand Up @@ -1788,8 +1791,8 @@ renderImportStyle (ImportAllConstructors p) = p <> "(..)"

-- | Used for extending import lists
unImportStyle :: ImportStyle -> (Maybe String, String)
unImportStyle (ImportTopLevel x) = (Nothing, T.unpack x)
unImportStyle (ImportViaParent x y) = (Just $ T.unpack y, T.unpack x)
unImportStyle (ImportTopLevel x) = (Nothing, T.unpack x)
unImportStyle (ImportViaParent x y) = (Just $ T.unpack y, T.unpack x)
unImportStyle (ImportAllConstructors x) = (Just $ T.unpack x, wildCardSymbol)


Expand Down
28 changes: 28 additions & 0 deletions ghcide/test/exe/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1343,6 +1343,34 @@ removeImportTests = testGroup "remove import actions"
, "main = print stuffB"
]
liftIO $ expectedContentAfterAction @=? contentAfterAction
, testSession "redundant binding - unicode regression " $ do
let contentA = T.unlines
[ "module ModuleA where"
, "data A = A"
, "ε :: Double"
, "ε = 0.5"
]
_docA <- createDoc "ModuleA.hs" "haskell" contentA
let contentB = T.unlines
[ "{-# OPTIONS_GHC -Wunused-imports #-}"
, "module ModuleB where"
, "import ModuleA (A(..), ε)"
, "a = A"
]
docB <- createDoc "ModuleB.hs" "haskell" contentB
_ <- waitForDiagnostics
[InR action@CodeAction { _title = actionTitle }, _]
<- getCodeActions docB (Range (Position 2 0) (Position 2 5))
liftIO $ "Remove ε from import" @=? actionTitle
executeCodeAction action
contentAfterAction <- documentContents docB
let expectedContentAfterAction = T.unlines
[ "{-# OPTIONS_GHC -Wunused-imports #-}"
, "module ModuleB where"
, "import ModuleA (A(..))"
, "a = A"
]
liftIO $ expectedContentAfterAction @=? contentAfterAction
, testSession "redundant operator" $ do
let contentA = T.unlines
[ "module ModuleA where"
Expand Down

0 comments on commit 6f06669

Please # to comment.