Skip to content

Commit c696970

Browse files
authored
Merge branch 'master' into importsfix
2 parents 400baf4 + d7a745e commit c696970

File tree

81 files changed

+1102
-149
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+1102
-149
lines changed

.github/workflows/test.yml

+4
Original file line numberDiff line numberDiff line change
@@ -208,3 +208,7 @@ jobs:
208208
- if: ${{ needs.pre_job.outputs.should_skip != 'true' && matrix.test}}
209209
name: Test hls-call-hierarchy-plugin test suite
210210
run: cabal test hls-call-hierarchy-plugin --test-options="-j1 --rerun-update" || cabal test hls-call-hierarchy-plugin --test-options="-j1 --rerun" || LSP_TEST_LOG_COLOR=0 LSP_TEST_LOG_MESSAGES=true LSP_TEST_LOG_STDERR=true cabal test hls-call-hierarchy-plugin --test-options="-j1 --rerun"
211+
212+
- if: ${{ needs.pre_job.outputs.should_skip != 'true' && matrix.test}}
213+
name: Test hls-rename-plugin test suite
214+
run: cabal test hls-rename-plugin --test-options="-j1 --rerun-update" || cabal test hls-rename-plugin --test-options="-j1 --rerun" || LSP_TEST_LOG_COLOR=0 LSP_TEST_LOG_MESSAGES=true LSP_TEST_LOG_STDERR=true cabal test hls-rename-plugin --test-options="-j1 --rerun"

cabal-ghc901.project

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ packages:
1515
./plugins/hls-explicit-imports-plugin
1616
./plugins/hls-refine-imports-plugin
1717
./plugins/hls-hlint-plugin
18+
./plugins/hls-rename-plugin
1819
./plugins/hls-retrie-plugin
1920
./plugins/hls-haddock-comments-plugin
2021
-- ./plugins/hls-splice-plugin

cabal.project

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ packages:
1515
./plugins/hls-explicit-imports-plugin
1616
./plugins/hls-refine-imports-plugin
1717
./plugins/hls-hlint-plugin
18+
./plugins/hls-rename-plugin
1819
./plugins/hls-retrie-plugin
1920
./plugins/hls-haddock-comments-plugin
2021
./plugins/hls-splice-plugin

exe/Plugins.hs

+7
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ import Ide.Plugin.ExplicitImports as ExplicitImports
3737
import Ide.Plugin.RefineImports as RefineImports
3838
#endif
3939

40+
#if rename
41+
import Ide.Plugin.Rename as Rename
42+
#endif
43+
4044
#if retrie
4145
import Ide.Plugin.Retrie as Retrie
4246
#endif
@@ -115,6 +119,9 @@ idePlugins includeExamples = pluginDescToIdePlugins allPlugins
115119
#if stylishHaskell
116120
StylishHaskell.descriptor "stylish-haskell" :
117121
#endif
122+
#if rename
123+
Rename.descriptor "rename" :
124+
#endif
118125
#if retrie
119126
Retrie.descriptor "retrie" :
120127
#endif

ghcide/bench/lib/Experiments.hs

+9-6
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,10 @@ experiments =
7474
isJust <$> getHover doc (fromJust identifierP),
7575
---------------------------------------------------------------------------------------
7676
bench "edit" $ \docs -> do
77-
forM_ docs $ \DocumentPositions{..} ->
77+
forM_ docs $ \DocumentPositions{..} -> do
7878
changeDoc doc [charEdit stringLiteralP]
79-
-- wait for a fresh build start
80-
waitForProgressStart
79+
-- wait for a fresh build start
80+
waitForProgressStart
8181
-- wait for the build to be finished
8282
waitForProgressDone
8383
return True,
@@ -121,8 +121,9 @@ experiments =
121121
( \docs -> do
122122
unless (any (isJust . identifierP) docs) $
123123
error "None of the example modules is suitable for this experiment"
124-
forM_ docs $ \DocumentPositions{..} ->
124+
forM_ docs $ \DocumentPositions{..} -> do
125125
forM_ identifierP $ \p -> changeDoc doc [charEdit p]
126+
waitForProgressStart
126127
waitForProgressDone
127128
)
128129
( \docs -> not . null . catMaybes <$> forM docs (\DocumentPositions{..} ->
@@ -139,8 +140,9 @@ experiments =
139140
forM_ identifierP $ \p -> changeDoc doc [charEdit p]
140141
)
141142
( \docs -> do
142-
forM_ docs $ \DocumentPositions{..} ->
143+
forM_ docs $ \DocumentPositions{..} -> do
143144
changeDoc doc [charEdit stringLiteralP]
145+
waitForProgressStart
144146
waitForProgressDone
145147
not . null . catMaybes <$> forM docs (\DocumentPositions{..} -> do
146148
forM identifierP $ \p ->
@@ -160,8 +162,9 @@ experiments =
160162
liftIO $ appendFile (fromJust $ uriToFilePath hieYamlUri) "##\n"
161163
sendNotification SWorkspaceDidChangeWatchedFiles $ DidChangeWatchedFilesParams $
162164
List [ FileEvent hieYamlUri FcChanged ]
163-
forM_ docs $ \DocumentPositions{..} ->
165+
forM_ docs $ \DocumentPositions{..} -> do
164166
changeDoc doc [charEdit stringLiteralP]
167+
waitForProgressStart
165168
waitForProgressDone
166169
not . null . catMaybes <$> forM docs (\DocumentPositions{..} -> do
167170
forM identifierP $ \p ->

ghcide/exe/Arguments.hs

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ arguments :: IdePlugins IdeState -> Parser Arguments
3131
arguments plugins = Arguments
3232
<$> optional (strOption $ long "cwd" <> metavar "DIR" <> help "Change to this directory")
3333
<*> switch (long "version" <> help "Show ghcide and GHC versions")
34-
<*> optional (strOption $ long "shake-profiling" <> metavar "DIR" <> help "Dump profiling reports to this directory")
34+
<*> optional (strOption $ long "shake-profiling" <> metavar "DIR" <> help "Dump profiling reports to this directory (env var: GHCIDE_BUILD_PROFILING)")
3535
<*> switch (long "ot-memory-profiling" <> help "Record OpenTelemetry info to the eventlog. Needs the -l RTS flag to have an effect")
3636
<*> switch (long "test" <> help "Enable additional lsp messages used by the testsuite")
3737
<*> switch (long "test-no-kick" <> help "Disable kick. Useful for testing cancellation")
3838
<*> option auto (short 'j' <> help "Number of threads (0: automatic)" <> metavar "NUM" <> value 0 <> showDefault)
39-
<*> switch (long "verbose" <> help "Include internal events in logging output")
39+
<*> switch (short 'd' <> long "verbose" <> help "Include internal events in logging output")
4040
<*> (commandP plugins <|> lspCommand <|> checkCommand)
4141
where
4242
checkCommand = Check <$> many (argument str (metavar "FILES/DIRS..."))

ghcide/session-loader/Development/IDE/Session.hs

+1-2
Original file line numberDiff line numberDiff line change
@@ -501,9 +501,8 @@ cradleToOptsAndLibDir :: Show a => Cradle a -> FilePath
501501
-> IO (Either [CradleError] (ComponentOptions, FilePath))
502502
cradleToOptsAndLibDir cradle file = do
503503
-- Start off by getting the session options
504-
let showLine s = hPutStrLn stderr ("> " ++ s)
505504
hPutStrLn stderr $ "Output from setting up the cradle " <> show cradle
506-
cradleRes <- runCradle (cradleOptsProg cradle) showLine file
505+
cradleRes <- HieBios.getCompilerOptions file cradle
507506
case cradleRes of
508507
CradleSuccess r -> do
509508
-- Now get the GHC lib dir

ghcide/src/Development/IDE/Core/Service.hs

+8-6
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ module Development.IDE.Core.Service(
1212
getIdeOptions, getIdeOptionsIO,
1313
IdeState, initialise, shutdown,
1414
runAction,
15-
writeProfile,
1615
getDiagnostics,
1716
ideLogger,
1817
updatePositionMapping,
1918
) where
2019

20+
import Control.Applicative ((<|>))
2121
import Development.IDE.Core.Debouncer
2222
import Development.IDE.Core.FileExists (fileExistsRules)
2323
import Development.IDE.Core.OfInterest
@@ -30,6 +30,7 @@ import qualified Language.LSP.Types as LSP
3030

3131
import Control.Monad
3232
import Development.IDE.Core.Shake
33+
import System.Environment (lookupEnv)
3334

3435

3536
------------------------------------------------------------
@@ -46,13 +47,17 @@ initialise :: Config
4647
-> HieDb
4748
-> IndexQueue
4849
-> IO IdeState
49-
initialise defaultConfig mainRule lspEnv logger debouncer options vfs hiedb hiedbChan =
50+
initialise defaultConfig mainRule lspEnv logger debouncer options vfs hiedb hiedbChan = do
51+
shakeProfiling <- do
52+
let fromConf = optShakeProfiling options
53+
fromEnv <- lookupEnv "GHCIDE_BUILD_PROFILING"
54+
return $ fromConf <|> fromEnv
5055
shakeOpen
5156
lspEnv
5257
defaultConfig
5358
logger
5459
debouncer
55-
(optShakeProfiling options)
60+
shakeProfiling
5661
(optReportProgress options)
5762
(optTesting options)
5863
hiedb
@@ -65,9 +70,6 @@ initialise defaultConfig mainRule lspEnv logger debouncer options vfs hiedb hied
6570
fileExistsRules lspEnv vfs
6671
mainRule
6772

68-
writeProfile :: IdeState -> FilePath -> IO ()
69-
writeProfile = shakeProfile
70-
7173
-- | Shutdown the Compiler Service.
7274
shutdown :: IdeState -> IO ()
7375
shutdown = shakeShut

ghcide/src/Development/IDE/Core/Shake.hs

+1-4
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ module Development.IDE.Core.Shake(
3131
GetModificationTime(GetModificationTime, GetModificationTime_, missingFileDiagnostics),
3232
shakeOpen, shakeShut,
3333
shakeEnqueue,
34-
shakeProfile,
3534
newSession,
3635
use, useNoFile, uses, useWithStaleFast, useWithStaleFast', delayedAction,
3736
FastResult(..),
@@ -550,14 +549,12 @@ shakeSessionInit IdeState{..} = do
550549
initSession <- newSession shakeExtras shakeDb []
551550
putMVar shakeSession initSession
552551

553-
shakeProfile :: IdeState -> FilePath -> IO ()
554-
shakeProfile IdeState{..} = shakeProfileDatabase shakeDb
555-
556552
shakeShut :: IdeState -> IO ()
557553
shakeShut IdeState{..} = withMVar shakeSession $ \runner -> do
558554
-- Shake gets unhappy if you try to close when there is a running
559555
-- request so we first abort that.
560556
void $ cancelShakeSession runner
557+
void $ shakeDatabaseProfile shakeDb
561558
shakeClose
562559
progressStop $ progress shakeExtras
563560

ghcide/src/Development/IDE/Plugin/CodeAction.hs

+8-7
Original file line numberDiff line numberDiff line change
@@ -1529,20 +1529,21 @@ rangesForBindingImport :: ImportDecl GhcPs -> String -> [Range]
15291529
rangesForBindingImport ImportDecl{ideclHiding = Just (False, L _ lies)} b =
15301530
concatMap (mapMaybe srcSpanToRange . rangesForBinding' b') lies
15311531
where
1532-
b' = modifyBinding b
1532+
b' = wrapOperatorInParens b
15331533
rangesForBindingImport _ _ = []
15341534

1535-
modifyBinding :: String -> String
1536-
modifyBinding = wrapOperatorInParens . unqualify
1537-
where
1538-
wrapOperatorInParens x = if isAlpha (head x) then x else "(" <> x <> ")"
1539-
unqualify x = snd $ breakOnEnd "." x
1535+
wrapOperatorInParens :: String -> String
1536+
wrapOperatorInParens x =
1537+
case uncons x of
1538+
Just (h, _t) -> if isAlpha h then x else "(" <> x <> ")"
1539+
Nothing -> mempty
15401540

15411541
smallerRangesForBindingExport :: [LIE GhcPs] -> String -> [Range]
15421542
smallerRangesForBindingExport lies b =
15431543
concatMap (mapMaybe srcSpanToRange . ranges') lies
15441544
where
1545-
b' = modifyBinding b
1545+
unqualify = snd . breakOnEnd "."
1546+
b' = wrapOperatorInParens . unqualify $ b
15461547
ranges' (L _ (IEThingWith _ thing _ inners labels))
15471548
| showSDocUnsafe (ppr thing) == b' = []
15481549
| otherwise =

ghcide/src/Development/IDE/Spans/AtPoint.hs

+14-3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ module Development.IDE.Spans.AtPoint (
1616
, computeTypeReferences
1717
, FOIReferences(..)
1818
, defRowToSymbolInfo
19+
, getAstNamesAtPoint
20+
, toCurrentLocation
21+
, rowToLoc
1922
) where
2023

2124
import Development.IDE.GHC.Error
@@ -90,18 +93,26 @@ foiReferencesAtPoint file pos (FOIReferences asts) =
9093
case HM.lookup file asts of
9194
Nothing -> ([],[],[])
9295
Just (HAR _ hf _ _ _,mapping) ->
93-
let posFile = fromMaybe pos $ fromCurrentPosition mapping pos
94-
names = concat $ pointCommand hf posFile (rights . M.keys . getNodeIds)
96+
let names = getAstNamesAtPoint hf pos mapping
9597
adjustedLocs = HM.foldr go [] asts
9698
go (HAR _ _ rf tr _, mapping) xs = refs ++ typerefs ++ xs
9799
where
98100
refs = mapMaybe (toCurrentLocation mapping . realSrcSpanToLocation . fst)
99101
$ concat $ mapMaybe (\n -> M.lookup (Right n) rf) names
100102
typerefs = mapMaybe (toCurrentLocation mapping . realSrcSpanToLocation)
101103
$ concat $ mapMaybe (`M.lookup` tr) names
102-
toCurrentLocation mapping (Location uri range) = Location uri <$> toCurrentRange mapping range
103104
in (names, adjustedLocs,map fromNormalizedFilePath $ HM.keys asts)
104105

106+
getAstNamesAtPoint :: HieASTs a -> Position -> PositionMapping -> [Name]
107+
getAstNamesAtPoint hf pos mapping =
108+
concat $ pointCommand hf posFile (rights . M.keys . getNodeIds)
109+
where
110+
posFile = fromMaybe pos $ fromCurrentPosition mapping pos
111+
112+
toCurrentLocation :: PositionMapping -> Location -> Maybe Location
113+
toCurrentLocation mapping (Location uri range) =
114+
Location uri <$> toCurrentRange mapping range
115+
105116
referencesAtPoint
106117
:: MonadIO m
107118
=> HieDb

ghcide/test/exe/Main.hs

+39
Original file line numberDiff line numberDiff line change
@@ -1197,6 +1197,33 @@ removeImportTests = testGroup "remove import actions"
11971197
, "type T = K.Type"
11981198
]
11991199
liftIO $ expectedContentAfterAction @=? contentAfterAction
1200+
, testSession "remove unused operators whose name ends with '.'" $ do
1201+
let contentA = T.unlines
1202+
[ "module ModuleA where"
1203+
, "(@.) = 0 -- Must have an operator whose name ends with '.'"
1204+
, "a = 1 -- .. but also something else"
1205+
]
1206+
_docA <- createDoc "ModuleA.hs" "haskell" contentA
1207+
let contentB = T.unlines
1208+
[ "{-# OPTIONS_GHC -Wunused-imports #-}"
1209+
, "module ModuleB where"
1210+
, "import ModuleA (a, (@.))"
1211+
, "x = a -- Must use something from module A, but not (@.)"
1212+
]
1213+
docB <- createDoc "ModuleB.hs" "haskell" contentB
1214+
_ <- waitForDiagnostics
1215+
[InR action@CodeAction { _title = actionTitle }, _]
1216+
<- getCodeActions docB (Range (Position 2 0) (Position 2 5))
1217+
liftIO $ "Remove @. from import" @=? actionTitle
1218+
executeCodeAction action
1219+
contentAfterAction <- documentContents docB
1220+
let expectedContentAfterAction = T.unlines
1221+
[ "{-# OPTIONS_GHC -Wunused-imports #-}"
1222+
, "module ModuleB where"
1223+
, "import ModuleA (a)"
1224+
, "x = a -- Must use something from module A, but not (@.)"
1225+
]
1226+
liftIO $ expectedContentAfterAction @=? contentAfterAction
12001227
]
12011228

12021229
extendImportTests :: TestTree
@@ -3358,6 +3385,18 @@ removeExportTests = testGroup "remove export actions"
33583385
, "import qualified Data.List as M"
33593386
, "a :: ()"
33603387
, "a = ()"])
3388+
, testSession "qualified re-export ending in '.'" $ template
3389+
(T.unlines
3390+
[ "module A ((M.@.),a) where"
3391+
, "import qualified Data.List as M"
3392+
, "a :: ()"
3393+
, "a = ()"])
3394+
"Remove ‘M.@.’ from export"
3395+
(Just $ T.unlines
3396+
[ "module A (a) where"
3397+
, "import qualified Data.List as M"
3398+
, "a :: ()"
3399+
, "a = ()"])
33613400
, testSession "export module" $ template
33623401
(T.unlines
33633402
[ "module A (module B) where"

haskell-language-server.cabal

+13-1
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,11 @@ flag refineImports
131131
default: True
132132
manual: True
133133

134+
flag rename
135+
description: Enable rename plugin
136+
default: False
137+
manual: True
138+
134139
flag retrie
135140
description: Enable retrie plugin
136141
default: True
@@ -223,6 +228,11 @@ common refineImports
223228
build-depends: hls-refine-imports-plugin ^>=1.0.0.0
224229
cpp-options: -DrefineImports
225230

231+
common rename
232+
if flag(rename) || flag(all-plugins)
233+
build-depends: hls-rename-plugin ^>= 1.0.0.0
234+
cpp-options: -Drename
235+
226236
common retrie
227237
if flag(retrie) || flag(all-plugins)
228238
build-depends: hls-retrie-plugin ^>=1.0.0.1
@@ -290,6 +300,7 @@ executable haskell-language-server
290300
, eval
291301
, importLens
292302
, refineImports
303+
, rename
293304
, retrie
294305
, tactic
295306
, hlint
@@ -424,7 +435,6 @@ test-suite func-test
424435
Highlight
425436
Progress
426437
Reference
427-
Rename
428438
Symbol
429439
TypeDefinition
430440
Test.Hls.Command
@@ -447,6 +457,8 @@ test-suite func-test
447457
cpp-options: -Deval
448458
if flag(importLens) || flag(all-plugins)
449459
cpp-options: -DimportLens
460+
if flag(rename) || flag(all-plugins)
461+
cpp-options: -Drename
450462
if flag(retrie) || flag(all-plugins)
451463
cpp-options: -Dretrie
452464
if flag(tactic) || flag(all-plugins)

0 commit comments

Comments
 (0)