Skip to content

Commit 19d1bc5

Browse files
committed
Fix redundant import actions for names starting with _
1 parent ae6f707 commit 19d1bc5

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

Diff for: ghcide/src/Development/IDE/Plugin/CodeAction.hs

+7-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ import Control.Arrow (second,
2424
import Control.Concurrent.STM.Stats (atomically)
2525
import Control.Monad (guard, join)
2626
import Control.Monad.IO.Class
27+
#if !MIN_VERSION_ghc(9,0,0)
28+
import Ctype (is_ident)
29+
#endif
2730
import Data.Char
2831
import qualified Data.DList as DL
2932
import Data.Function
@@ -57,6 +60,9 @@ import Development.IDE.Types.Exports
5760
import Development.IDE.Types.Location
5861
import Development.IDE.Types.Options
5962
import qualified GHC.LanguageExtensions as Lang
63+
#if MIN_VERSION_ghc(9,0,0)
64+
import GHC.Parser.CharClass (is_ident)
65+
#endif
6066
import Ide.PluginUtils (subRange)
6167
import Ide.Types
6268
import qualified Language.LSP.Server as LSP
@@ -1525,7 +1531,7 @@ rangesForBindingImport _ _ = []
15251531
wrapOperatorInParens :: String -> String
15261532
wrapOperatorInParens x =
15271533
case uncons x of
1528-
Just (h, _t) -> if isAlpha h then x else "(" <> x <> ")"
1534+
Just (h, _t) -> if is_ident h then x else "(" <> x <> ")"
15291535
Nothing -> mempty
15301536

15311537
smallerRangesForBindingExport :: [LIE GhcPs] -> String -> [Range]

Diff for: ghcide/test/exe/Main.hs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1276,19 +1276,20 @@ removeImportTests = testGroup "remove import actions"
12761276
, "stuffB :: Integer"
12771277
, "stuffB = 123"
12781278
, "stuffC = ()"
1279+
, "_stuffD = '_'"
12791280
]
12801281
_docA <- createDoc "ModuleA.hs" "haskell" contentA
12811282
let contentB = T.unlines
12821283
[ "{-# OPTIONS_GHC -Wunused-imports #-}"
12831284
, "module ModuleB where"
1284-
, "import ModuleA (stuffA, stuffB, stuffC, stuffA)"
1285+
, "import ModuleA (stuffA, stuffB, _stuffD, stuffC, stuffA)"
12851286
, "main = print stuffB"
12861287
]
12871288
docB <- createDoc "ModuleB.hs" "haskell" contentB
12881289
_ <- waitForDiagnostics
12891290
[InR action@CodeAction { _title = actionTitle }, _]
12901291
<- getCodeActions docB (Range (Position 2 0) (Position 2 5))
1291-
liftIO $ "Remove stuffA, stuffC from import" @=? actionTitle
1292+
liftIO $ "Remove _stuffD, stuffA, stuffC from import" @=? actionTitle
12921293
executeCodeAction action
12931294
contentAfterAction <- documentContents docB
12941295
let expectedContentAfterAction = T.unlines

0 commit comments

Comments
 (0)