Skip to content

Commit

Permalink
Merge branch 'master' into importsfix
Browse files Browse the repository at this point in the history
  • Loading branch information
jneira authored Aug 25, 2021
2 parents 400baf4 + d7a745e commit c696970
Show file tree
Hide file tree
Showing 81 changed files with 1,102 additions and 149 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -208,3 +208,7 @@ jobs:
- if: ${{ needs.pre_job.outputs.should_skip != 'true' && matrix.test}}
name: Test hls-call-hierarchy-plugin test suite
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"

- if: ${{ needs.pre_job.outputs.should_skip != 'true' && matrix.test}}
name: Test hls-rename-plugin test suite
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"
1 change: 1 addition & 0 deletions cabal-ghc901.project
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ packages:
./plugins/hls-explicit-imports-plugin
./plugins/hls-refine-imports-plugin
./plugins/hls-hlint-plugin
./plugins/hls-rename-plugin
./plugins/hls-retrie-plugin
./plugins/hls-haddock-comments-plugin
-- ./plugins/hls-splice-plugin
Expand Down
1 change: 1 addition & 0 deletions cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ packages:
./plugins/hls-explicit-imports-plugin
./plugins/hls-refine-imports-plugin
./plugins/hls-hlint-plugin
./plugins/hls-rename-plugin
./plugins/hls-retrie-plugin
./plugins/hls-haddock-comments-plugin
./plugins/hls-splice-plugin
Expand Down
7 changes: 7 additions & 0 deletions exe/Plugins.hs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ import Ide.Plugin.ExplicitImports as ExplicitImports
import Ide.Plugin.RefineImports as RefineImports
#endif

#if rename
import Ide.Plugin.Rename as Rename
#endif

#if retrie
import Ide.Plugin.Retrie as Retrie
#endif
Expand Down Expand Up @@ -115,6 +119,9 @@ idePlugins includeExamples = pluginDescToIdePlugins allPlugins
#if stylishHaskell
StylishHaskell.descriptor "stylish-haskell" :
#endif
#if rename
Rename.descriptor "rename" :
#endif
#if retrie
Retrie.descriptor "retrie" :
#endif
Expand Down
15 changes: 9 additions & 6 deletions ghcide/bench/lib/Experiments.hs
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,10 @@ experiments =
isJust <$> getHover doc (fromJust identifierP),
---------------------------------------------------------------------------------------
bench "edit" $ \docs -> do
forM_ docs $ \DocumentPositions{..} ->
forM_ docs $ \DocumentPositions{..} -> do
changeDoc doc [charEdit stringLiteralP]
-- wait for a fresh build start
waitForProgressStart
-- wait for a fresh build start
waitForProgressStart
-- wait for the build to be finished
waitForProgressDone
return True,
Expand Down Expand Up @@ -121,8 +121,9 @@ experiments =
( \docs -> do
unless (any (isJust . identifierP) docs) $
error "None of the example modules is suitable for this experiment"
forM_ docs $ \DocumentPositions{..} ->
forM_ docs $ \DocumentPositions{..} -> do
forM_ identifierP $ \p -> changeDoc doc [charEdit p]
waitForProgressStart
waitForProgressDone
)
( \docs -> not . null . catMaybes <$> forM docs (\DocumentPositions{..} ->
Expand All @@ -139,8 +140,9 @@ experiments =
forM_ identifierP $ \p -> changeDoc doc [charEdit p]
)
( \docs -> do
forM_ docs $ \DocumentPositions{..} ->
forM_ docs $ \DocumentPositions{..} -> do
changeDoc doc [charEdit stringLiteralP]
waitForProgressStart
waitForProgressDone
not . null . catMaybes <$> forM docs (\DocumentPositions{..} -> do
forM identifierP $ \p ->
Expand All @@ -160,8 +162,9 @@ experiments =
liftIO $ appendFile (fromJust $ uriToFilePath hieYamlUri) "##\n"
sendNotification SWorkspaceDidChangeWatchedFiles $ DidChangeWatchedFilesParams $
List [ FileEvent hieYamlUri FcChanged ]
forM_ docs $ \DocumentPositions{..} ->
forM_ docs $ \DocumentPositions{..} -> do
changeDoc doc [charEdit stringLiteralP]
waitForProgressStart
waitForProgressDone
not . null . catMaybes <$> forM docs (\DocumentPositions{..} -> do
forM identifierP $ \p ->
Expand Down
4 changes: 2 additions & 2 deletions ghcide/exe/Arguments.hs
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ arguments :: IdePlugins IdeState -> Parser Arguments
arguments plugins = Arguments
<$> optional (strOption $ long "cwd" <> metavar "DIR" <> help "Change to this directory")
<*> switch (long "version" <> help "Show ghcide and GHC versions")
<*> optional (strOption $ long "shake-profiling" <> metavar "DIR" <> help "Dump profiling reports to this directory")
<*> optional (strOption $ long "shake-profiling" <> metavar "DIR" <> help "Dump profiling reports to this directory (env var: GHCIDE_BUILD_PROFILING)")
<*> switch (long "ot-memory-profiling" <> help "Record OpenTelemetry info to the eventlog. Needs the -l RTS flag to have an effect")
<*> switch (long "test" <> help "Enable additional lsp messages used by the testsuite")
<*> switch (long "test-no-kick" <> help "Disable kick. Useful for testing cancellation")
<*> option auto (short 'j' <> help "Number of threads (0: automatic)" <> metavar "NUM" <> value 0 <> showDefault)
<*> switch (long "verbose" <> help "Include internal events in logging output")
<*> switch (short 'd' <> long "verbose" <> help "Include internal events in logging output")
<*> (commandP plugins <|> lspCommand <|> checkCommand)
where
checkCommand = Check <$> many (argument str (metavar "FILES/DIRS..."))
Expand Down
3 changes: 1 addition & 2 deletions ghcide/session-loader/Development/IDE/Session.hs
Original file line number Diff line number Diff line change
Expand Up @@ -501,9 +501,8 @@ cradleToOptsAndLibDir :: Show a => Cradle a -> FilePath
-> IO (Either [CradleError] (ComponentOptions, FilePath))
cradleToOptsAndLibDir cradle file = do
-- Start off by getting the session options
let showLine s = hPutStrLn stderr ("> " ++ s)
hPutStrLn stderr $ "Output from setting up the cradle " <> show cradle
cradleRes <- runCradle (cradleOptsProg cradle) showLine file
cradleRes <- HieBios.getCompilerOptions file cradle
case cradleRes of
CradleSuccess r -> do
-- Now get the GHC lib dir
Expand Down
14 changes: 8 additions & 6 deletions ghcide/src/Development/IDE/Core/Service.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ module Development.IDE.Core.Service(
getIdeOptions, getIdeOptionsIO,
IdeState, initialise, shutdown,
runAction,
writeProfile,
getDiagnostics,
ideLogger,
updatePositionMapping,
) where

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

import Control.Monad
import Development.IDE.Core.Shake
import System.Environment (lookupEnv)


------------------------------------------------------------
Expand All @@ -46,13 +47,17 @@ initialise :: Config
-> HieDb
-> IndexQueue
-> IO IdeState
initialise defaultConfig mainRule lspEnv logger debouncer options vfs hiedb hiedbChan =
initialise defaultConfig mainRule lspEnv logger debouncer options vfs hiedb hiedbChan = do
shakeProfiling <- do
let fromConf = optShakeProfiling options
fromEnv <- lookupEnv "GHCIDE_BUILD_PROFILING"
return $ fromConf <|> fromEnv
shakeOpen
lspEnv
defaultConfig
logger
debouncer
(optShakeProfiling options)
shakeProfiling
(optReportProgress options)
(optTesting options)
hiedb
Expand All @@ -65,9 +70,6 @@ initialise defaultConfig mainRule lspEnv logger debouncer options vfs hiedb hied
fileExistsRules lspEnv vfs
mainRule

writeProfile :: IdeState -> FilePath -> IO ()
writeProfile = shakeProfile

-- | Shutdown the Compiler Service.
shutdown :: IdeState -> IO ()
shutdown = shakeShut
Expand Down
5 changes: 1 addition & 4 deletions ghcide/src/Development/IDE/Core/Shake.hs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ module Development.IDE.Core.Shake(
GetModificationTime(GetModificationTime, GetModificationTime_, missingFileDiagnostics),
shakeOpen, shakeShut,
shakeEnqueue,
shakeProfile,
newSession,
use, useNoFile, uses, useWithStaleFast, useWithStaleFast', delayedAction,
FastResult(..),
Expand Down Expand Up @@ -550,14 +549,12 @@ shakeSessionInit IdeState{..} = do
initSession <- newSession shakeExtras shakeDb []
putMVar shakeSession initSession

shakeProfile :: IdeState -> FilePath -> IO ()
shakeProfile IdeState{..} = shakeProfileDatabase shakeDb

shakeShut :: IdeState -> IO ()
shakeShut IdeState{..} = withMVar shakeSession $ \runner -> do
-- Shake gets unhappy if you try to close when there is a running
-- request so we first abort that.
void $ cancelShakeSession runner
void $ shakeDatabaseProfile shakeDb
shakeClose
progressStop $ progress shakeExtras

Expand Down
15 changes: 8 additions & 7 deletions ghcide/src/Development/IDE/Plugin/CodeAction.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1529,20 +1529,21 @@ rangesForBindingImport :: ImportDecl GhcPs -> String -> [Range]
rangesForBindingImport ImportDecl{ideclHiding = Just (False, L _ lies)} b =
concatMap (mapMaybe srcSpanToRange . rangesForBinding' b') lies
where
b' = modifyBinding b
b' = wrapOperatorInParens b
rangesForBindingImport _ _ = []

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

smallerRangesForBindingExport :: [LIE GhcPs] -> String -> [Range]
smallerRangesForBindingExport lies b =
concatMap (mapMaybe srcSpanToRange . ranges') lies
where
b' = modifyBinding b
unqualify = snd . breakOnEnd "."
b' = wrapOperatorInParens . unqualify $ b
ranges' (L _ (IEThingWith _ thing _ inners labels))
| showSDocUnsafe (ppr thing) == b' = []
| otherwise =
Expand Down
17 changes: 14 additions & 3 deletions ghcide/src/Development/IDE/Spans/AtPoint.hs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ module Development.IDE.Spans.AtPoint (
, computeTypeReferences
, FOIReferences(..)
, defRowToSymbolInfo
, getAstNamesAtPoint
, toCurrentLocation
, rowToLoc
) where

import Development.IDE.GHC.Error
Expand Down Expand Up @@ -90,18 +93,26 @@ foiReferencesAtPoint file pos (FOIReferences asts) =
case HM.lookup file asts of
Nothing -> ([],[],[])
Just (HAR _ hf _ _ _,mapping) ->
let posFile = fromMaybe pos $ fromCurrentPosition mapping pos
names = concat $ pointCommand hf posFile (rights . M.keys . getNodeIds)
let names = getAstNamesAtPoint hf pos mapping
adjustedLocs = HM.foldr go [] asts
go (HAR _ _ rf tr _, mapping) xs = refs ++ typerefs ++ xs
where
refs = mapMaybe (toCurrentLocation mapping . realSrcSpanToLocation . fst)
$ concat $ mapMaybe (\n -> M.lookup (Right n) rf) names
typerefs = mapMaybe (toCurrentLocation mapping . realSrcSpanToLocation)
$ concat $ mapMaybe (`M.lookup` tr) names
toCurrentLocation mapping (Location uri range) = Location uri <$> toCurrentRange mapping range
in (names, adjustedLocs,map fromNormalizedFilePath $ HM.keys asts)

getAstNamesAtPoint :: HieASTs a -> Position -> PositionMapping -> [Name]
getAstNamesAtPoint hf pos mapping =
concat $ pointCommand hf posFile (rights . M.keys . getNodeIds)
where
posFile = fromMaybe pos $ fromCurrentPosition mapping pos

toCurrentLocation :: PositionMapping -> Location -> Maybe Location
toCurrentLocation mapping (Location uri range) =
Location uri <$> toCurrentRange mapping range

referencesAtPoint
:: MonadIO m
=> HieDb
Expand Down
39 changes: 39 additions & 0 deletions ghcide/test/exe/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1197,6 +1197,33 @@ removeImportTests = testGroup "remove import actions"
, "type T = K.Type"
]
liftIO $ expectedContentAfterAction @=? contentAfterAction
, testSession "remove unused operators whose name ends with '.'" $ do
let contentA = T.unlines
[ "module ModuleA where"
, "(@.) = 0 -- Must have an operator whose name ends with '.'"
, "a = 1 -- .. but also something else"
]
_docA <- createDoc "ModuleA.hs" "haskell" contentA
let contentB = T.unlines
[ "{-# OPTIONS_GHC -Wunused-imports #-}"
, "module ModuleB where"
, "import ModuleA (a, (@.))"
, "x = a -- Must use something from module A, but not (@.)"
]
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)"
, "x = a -- Must use something from module A, but not (@.)"
]
liftIO $ expectedContentAfterAction @=? contentAfterAction
]

extendImportTests :: TestTree
Expand Down Expand Up @@ -3358,6 +3385,18 @@ removeExportTests = testGroup "remove export actions"
, "import qualified Data.List as M"
, "a :: ()"
, "a = ()"])
, testSession "qualified re-export ending in '.'" $ template
(T.unlines
[ "module A ((M.@.),a) where"
, "import qualified Data.List as M"
, "a :: ()"
, "a = ()"])
"Remove ‘M.@.’ from export"
(Just $ T.unlines
[ "module A (a) where"
, "import qualified Data.List as M"
, "a :: ()"
, "a = ()"])
, testSession "export module" $ template
(T.unlines
[ "module A (module B) where"
Expand Down
14 changes: 13 additions & 1 deletion haskell-language-server.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,11 @@ flag refineImports
default: True
manual: True

flag rename
description: Enable rename plugin
default: False
manual: True

flag retrie
description: Enable retrie plugin
default: True
Expand Down Expand Up @@ -223,6 +228,11 @@ common refineImports
build-depends: hls-refine-imports-plugin ^>=1.0.0.0
cpp-options: -DrefineImports

common rename
if flag(rename) || flag(all-plugins)
build-depends: hls-rename-plugin ^>= 1.0.0.0
cpp-options: -Drename

common retrie
if flag(retrie) || flag(all-plugins)
build-depends: hls-retrie-plugin ^>=1.0.0.1
Expand Down Expand Up @@ -290,6 +300,7 @@ executable haskell-language-server
, eval
, importLens
, refineImports
, rename
, retrie
, tactic
, hlint
Expand Down Expand Up @@ -424,7 +435,6 @@ test-suite func-test
Highlight
Progress
Reference
Rename
Symbol
TypeDefinition
Test.Hls.Command
Expand All @@ -447,6 +457,8 @@ test-suite func-test
cpp-options: -Deval
if flag(importLens) || flag(all-plugins)
cpp-options: -DimportLens
if flag(rename) || flag(all-plugins)
cpp-options: -Drename
if flag(retrie) || flag(all-plugins)
cpp-options: -Dretrie
if flag(tactic) || flag(all-plugins)
Expand Down
Loading

0 comments on commit c696970

Please # to comment.