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

Cleanup cabal files, ghc compat code, fix ghc warnings #4222

Merged
merged 9 commits into from
May 12, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 3 additions & 17 deletions ghcide/ghcide.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ homepage:
https://github.com/haskell/haskell-language-server/tree/master/ghcide#readme

bug-reports: https://github.com/haskell/haskell-language-server/issues
tested-with: GHC ==9.8.2 || ==9.6.4 || ==9.4.8 || ==9.2.8
tested-with: GHC ==9.8.2 || ==9.6.5 || ==9.4.8 || ==9.2.8
extra-source-files:
CHANGELOG.md
README.md
Expand Down Expand Up @@ -98,7 +98,6 @@ library
, prettyprinter-ansi-terminal
, random
, regex-tdfa >=1.3.1.0
, row-types
, safe-exceptions
, sorted-list
, sqlite-simple
Expand Down Expand Up @@ -272,25 +271,12 @@ library ghcide-test-utils
visibility: public
default-language: GHC2021

hs-source-dirs: test/src test/cabal
hs-source-dirs: test/cabal
exposed-modules:
Development.IDE.Test.Runfiles

build-depends:
aeson,
base > 4.9 && < 5,
containers,
data-default,
directory,
extra,
filepath,
ghcide,
lsp-types,
hls-plugin-api,
lens,
lsp-test ^>= 0.17,
tasty-hunit >= 0.10,
text,
base > 4.9 && < 5

default-extensions:
LambdaCase
Expand Down
6 changes: 2 additions & 4 deletions ghcide/session-loader/Development/IDE/Session.hs
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@
import Data.Time.Clock
import Data.Version
import Development.IDE.Core.RuleTypes
import Development.IDE.Core.Shake hiding (Log, Priority,
knownTargets, withHieDb)
import Development.IDE.Core.Shake hiding (Log, knownTargets,
withHieDb)
import qualified Development.IDE.GHC.Compat as Compat
import Development.IDE.GHC.Compat.Core hiding (Target,
TargetFile, TargetModule,
Expand All @@ -70,7 +70,6 @@
import Development.IDE.Types.Options
import GHC.Check
import qualified HIE.Bios as HieBios
import qualified HIE.Bios.Cradle as HieBios
import HIE.Bios.Environment hiding (getCacheDir)
import HIE.Bios.Types hiding (Log)
import qualified HIE.Bios.Types as HieBios
Expand Down Expand Up @@ -125,7 +124,6 @@
import GHC.Data.Bag
import GHC.Driver.Env (hsc_all_home_unit_ids)
import GHC.Driver.Errors.Types
import GHC.Driver.Make (checkHomeUnitsClosed)
import GHC.Types.Error (errMsgDiagnostic,
singleMessage)
import GHC.Unit.State
Expand Down Expand Up @@ -673,7 +671,7 @@
InstallationMismatch{..} ->
return (([renderPackageSetupException cfp GhcVersionMismatch{..}], Nothing),[])
InstallationChecked _compileTime _ghcLibCheck -> do
atomicModifyIORef' cradle_files (\xs -> (cfp:xs,()))

Check warning on line 674 in ghcide/session-loader/Development/IDE/Session.hs

View workflow job for this annotation

GitHub Actions / Hlint check run

Warning in loadSessionWithOptions in module Development.IDE.Session: Use atomicModifyIORef'_ ▫︎ Found: "atomicModifyIORef' cradle_files (\\ xs -> (cfp : xs, ()))" ▫︎ Perhaps: "atomicModifyIORef'_ cradle_files ((:) cfp)"
session (hieYaml, toNormalizedFilePath' cfp, opts, libDir)
-- Failure case, either a cradle error or the none cradle
Left err -> do
Expand Down
5 changes: 1 addition & 4 deletions ghcide/src/Development/IDE/Core/FileStore.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ module Development.IDE.Core.FileStore(
Log(..)
) where

import Control.Concurrent.STM.Stats (STM, atomically,
modifyTVar')
import Control.Concurrent.STM.Stats (STM, atomically)
import Control.Concurrent.STM.TQueue (writeTQueue)
import Control.Exception
import Control.Monad.Extra
Expand All @@ -32,10 +31,8 @@ import qualified Data.ByteString as BS
import qualified Data.ByteString.Lazy as LBS
import qualified Data.HashMap.Strict as HashMap
import Data.IORef
import Data.List (foldl')
import qualified Data.Text as T
import qualified Data.Text as Text
import qualified Data.Text.Utf16.Rope as Rope
import Data.Time
import Data.Time.Clock.POSIX
import Development.IDE.Core.FileUtils
Expand Down
1 change: 0 additions & 1 deletion ghcide/src/Development/IDE/Core/OfInterest.hs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import Control.Monad.IO.Class
import Data.HashMap.Strict (HashMap)
import qualified Data.HashMap.Strict as HashMap
import Data.Proxy
import qualified Data.Text as T
import Development.IDE.Graph

import Control.Concurrent.STM.Stats (atomically,
Expand Down
1 change: 0 additions & 1 deletion ghcide/src/Development/IDE/Core/PositionMapping.hs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import Control.Monad
import Data.Algorithm.Diff
import Data.Bifunctor
import Data.List
import Data.Row
import qualified Data.Text as T
import qualified Data.Vector.Unboxed as V
import qualified Language.LSP.Protocol.Lens as L
Expand Down
4 changes: 0 additions & 4 deletions ghcide/src/Development/IDE/Core/Rules.hs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@
) where

import Control.Applicative
import Control.Concurrent.Async (concurrently)
import Control.Concurrent.STM.Stats (atomically)
import Control.Concurrent.STM.TVar
import Control.Concurrent.Strict
Expand Down Expand Up @@ -90,10 +89,8 @@
import qualified Data.Map as M
import Data.Maybe
import Data.Proxy
import qualified Data.Set as Set
import qualified Data.Text as T
import qualified Data.Text.Encoding as T
import qualified Data.Text.Utf16.Rope as Rope
import Data.Time (UTCTime (..))
import Data.Time.Clock.POSIX (posixSecondsToUTCTime)
import Data.Tuple.Extra
Expand Down Expand Up @@ -123,7 +120,6 @@
import qualified Development.IDE.GHC.Compat as Compat hiding
(nest,
vcat)
import Development.IDE.GHC.Compat.Env
import qualified Development.IDE.GHC.Compat.Util as Util
import Development.IDE.GHC.Error
import Development.IDE.GHC.Util hiding
Expand Down Expand Up @@ -823,7 +819,7 @@
{ source_version = ver
, old_value = m_old
, get_file_version = use GetModificationTime_{missingFileDiagnostics = False}
, get_linkable_hashes = \fs -> map (snd . fromJust . hirCoreFp) <$> uses_ GetModIface fs

Check warning on line 822 in ghcide/src/Development/IDE/Core/Rules.hs

View workflow job for this annotation

GitHub Actions / Hlint check run

Suggestion in getModIfaceFromDiskRule in module Development.IDE.Core.Rules: Use fmap ▫︎ Found: "\\ fs -> map (snd . fromJust . hirCoreFp) <$> uses_ GetModIface fs" ▫︎ Perhaps: "fmap (map (snd . fromJust . hirCoreFp)) . uses_ GetModIface"
, regenerate = regenerateHiFile session f ms
}
r <- loadInterface (hscEnv session) ms linkableType recompInfo
Expand Down Expand Up @@ -1095,7 +1091,7 @@
-- thus bump its modification time, forcing this rule to be rerun every time.
exists <- liftIO $ doesFileExist obj_file
mobj_time <- liftIO $
if exists

Check warning on line 1094 in ghcide/src/Development/IDE/Core/Rules.hs

View workflow job for this annotation

GitHub Actions / Hlint check run

Warning in getLinkableRule in module Development.IDE.Core.Rules: Use whenMaybe ▫︎ Found: "if exists then Just <$> getModTime obj_file else pure Nothing" ▫︎ Perhaps: "whenMaybe exists (getModTime obj_file)"
then Just <$> getModTime obj_file
else pure Nothing
case mobj_time of
Expand Down
2 changes: 1 addition & 1 deletion ghcide/src/Development/IDE/Core/Shake.hs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@
import Development.IDE.Core.ProgressReporting
import Development.IDE.Core.RuleTypes
import Development.IDE.Core.Tracing
import Development.IDE.GHC.Compat (NameCache,

Check warning on line 126 in ghcide/src/Development/IDE/Core/Shake.hs

View workflow job for this annotation

GitHub Actions / Hlint check run

Warning in module Development.IDE.Core.Shake: Use fewer imports ▫︎ Found: "import Development.IDE.GHC.Compat\n ( NameCache, NameCacheUpdater(..), initNameCache, knownKeyNames )\nimport Development.IDE.GHC.Compat\n ( mkSplitUniqSupply, upNameCache )\n" ▫︎ Perhaps: "import Development.IDE.GHC.Compat\n ( NameCache,\n NameCacheUpdater(..),\n initNameCache,\n knownKeyNames,\n mkSplitUniqSupply,\n upNameCache )\n"
NameCacheUpdater (..),
initNameCache,
knownKeyNames)
Expand Down Expand Up @@ -707,7 +707,7 @@

-- | Must be called in the 'Initialized' handler and only once
shakeSessionInit :: Recorder (WithPriority Log) -> IdeState -> IO ()
shakeSessionInit recorder ide@IdeState{..} = do
shakeSessionInit recorder IdeState{..} = do
-- Take a snapshot of the VFS - it should be empty as we've received no notifications
-- till now, but it can't hurt to be in sync with the `lsp` library.
vfs <- vfsSnapshot (lspEnv shakeExtras)
Expand Down
41 changes: 27 additions & 14 deletions ghcide/src/Development/IDE/GHC/Orphans.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,34 +11,36 @@ import Development.IDE.GHC.Compat
import Development.IDE.GHC.Util

import Control.DeepSeq
import Control.Monad.Trans.Reader (ReaderT (..))
import Control.Monad.Trans.Reader (ReaderT (..))
import Data.Aeson
import Data.Hashable
import Data.String (IsString (fromString))
import Data.Text (unpack)

-- See Note [Guidelines For Using CPP In GHCIDE Import Statements]
import Data.String (IsString (fromString))
import Data.Text (unpack)

import GHC.ByteCode.Types
import GHC.Data.Bag
import GHC.Data.FastString
import qualified GHC.Data.StringBuffer as SB
import qualified GHC.Data.StringBuffer as SB
import GHC.Types.SrcLoc

-- See Note [Guidelines For Using CPP In GHCIDE Import Statements]
#if !MIN_VERSION_ghc(9,3,0)
import GHC (ModuleGraph)
import GHC.Types.Unique (getKey)
import GHC (ModuleGraph)
import GHC.Types.Unique (getKey)
#endif

import Data.Bifunctor (Bifunctor (..))
import Data.Bifunctor (Bifunctor (..))
import GHC.Parser.Annotation
import GHC.Unit.Module.Location (ModLocation (..))

#if MIN_VERSION_ghc(9,3,0)
import GHC.Types.PkgQual

#endif

#if MIN_VERSION_ghc(9,5,0)
import GHC.Unit.Home.ModInfo
import GHC.Unit.Module.WholeCoreBindings
#endif

-- Orphan instance for Shake.hs
Expand All @@ -56,11 +58,22 @@ instance NFData SafeHaskellMode where rnf = rwhnf
instance Show Linkable where show = unpack . printOutputable
instance NFData Linkable where rnf (LM a b c) = rnf a `seq` rnf b `seq` rnf c
instance NFData Unlinked where
rnf (DotO f) = rnf f
rnf (DotA f) = rnf f
rnf (DotDLL f) = rnf f
rnf (BCOs a b) = seqCompiledByteCode a `seq` liftRnf rwhnf b
rnf _ = error "rnf: not implemented for Unlinked"
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Completing this NFData implementation for more recent GHCs

rnf (DotO f) = rnf f
rnf (DotA f) = rnf f
rnf (DotDLL f) = rnf f
rnf (BCOs a b) = seqCompiledByteCode a `seq` liftRnf rwhnf b
#if MIN_VERSION_ghc(9,5,0)
rnf (CoreBindings wcb) = rnf wcb
rnf (LoadedBCOs us) = rnf us

instance NFData WholeCoreBindings where
rnf (WholeCoreBindings bs m ml) = rnf bs `seq` rnf m `seq` rnf ml

instance NFData ModLocation where
rnf (ModLocation mf f1 f2 f3 f4 f5) = rnf mf `seq` rnf f1 `seq` rnf f2 `seq` rnf f3 `seq` rnf f4 `seq` rnf f5

#endif

instance Show PackageFlag where show = unpack . printOutputable
instance Show InteractiveImport where show = unpack . printOutputable
instance Show PackageName where show = unpack . printOutputable
Expand Down
2 changes: 1 addition & 1 deletion ghcide/src/Development/IDE/LSP/HoverDefinition.hs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import Data.Maybe (fromMaybe)
import Development.IDE.Core.Actions
import qualified Development.IDE.Core.Rules as Shake
import Development.IDE.Core.Shake (IdeAction, IdeState (..),
ideLogger, runIdeAction)
runIdeAction)
import Development.IDE.Types.Location
import Ide.Logger
import Ide.Plugin.Error
Expand Down
2 changes: 1 addition & 1 deletion ghcide/src/Development/IDE/LSP/LanguageServer.hs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import UnliftIO.Exception
import qualified Colog.Core as Colog
import Control.Monad.IO.Unlift (MonadUnliftIO)
import Development.IDE.Core.IdeConfiguration
import Development.IDE.Core.Shake hiding (Log, Priority)
import Development.IDE.Core.Shake hiding (Log)
import Development.IDE.Core.Tracing
import qualified Development.IDE.Session as Session
import Development.IDE.Types.Shake (WithHieDb)
Expand Down
2 changes: 1 addition & 1 deletion ghcide/src/Development/IDE/LSP/Notifications.hs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import qualified Development.IDE.Core.FileStore as FileStore
import Development.IDE.Core.IdeConfiguration
import Development.IDE.Core.OfInterest hiding (Log, LogShake)
import Development.IDE.Core.Service hiding (Log, LogShake)
import Development.IDE.Core.Shake hiding (Log, Priority)
import Development.IDE.Core.Shake hiding (Log)
import qualified Development.IDE.Core.Shake as Shake
import Development.IDE.Types.Location
import Ide.Logger
Expand Down
8 changes: 3 additions & 5 deletions ghcide/src/Development/IDE/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ import Data.Maybe (catMaybes, isJust)
import qualified Data.Text as T
import Development.IDE (Action,
Priority (Debug, Error),
Rules, emptyFilePath,
hDuplicateTo')
Rules, hDuplicateTo')
import Development.IDE.Core.Debouncer (Debouncer,
newAsyncDebouncer)
import Development.IDE.Core.FileStore (isWatchSupported,
Expand Down Expand Up @@ -88,10 +87,9 @@ import Development.IDE.Types.Options (IdeGhcSession,
defaultIdeOptions,
optModifyDynFlags,
optTesting)
import Development.IDE.Types.Shake (WithHieDb, toKey,
import Development.IDE.Types.Shake (WithHieDb,
toNoFileKey)
import GHC.Conc (atomically,
getNumProcessors)
import GHC.Conc (getNumProcessors)
import GHC.IO.Encoding (setLocaleEncoding)
import GHC.IO.Handle (hDuplicate)
import HIE.Bios.Cradle (findCradle)
Expand Down
1 change: 0 additions & 1 deletion ghcide/src/Development/IDE/Plugin/Completions/Logic.hs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import Data.Generics
import Data.List.Extra as List hiding
(stripPrefix)
import qualified Data.Map as Map
import Data.Row
import Prelude hiding (mod)

import Data.Maybe (fromMaybe, isJust,
Expand Down
2 changes: 1 addition & 1 deletion ghcide/src/Development/IDE/Plugin/HLS/GhcIde.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module Development.IDE.Plugin.HLS.GhcIde
descriptors
, Log(..)
) where
import Control.Monad.IO.Class

import Development.IDE
import qualified Development.IDE.LSP.HoverDefinition as Hover
import qualified Development.IDE.LSP.Notifications as Notifications
Expand Down
1 change: 0 additions & 1 deletion ghcide/src/Development/IDE/Spans/AtPoint.hs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ import Data.List (isSuffixOf)
import Data.List.Extra (dropEnd1, nubOrd)

import Data.Version (showVersion)
import Development.IDE.GHC.Compat (getSourceNodeIds)
import Development.IDE.Types.Shake (WithHieDb)
import HieDb hiding (pointCommand,
withHieDb)
Expand Down
2 changes: 1 addition & 1 deletion ghcide/src/Development/IDE/Types/Shake.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module Development.IDE.Types.Shake
Value (..),
ValueWithDiagnostics (..),
Values,
Key (..),
Key,
BadDependency (..),
ShakeValue(..),
currentValue,
Expand Down
11 changes: 2 additions & 9 deletions ghcide/test/exe/FindDefinitionAndHoverTests.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,12 @@ import qualified Language.LSP.Protocol.Lens as L
import Language.LSP.Test
import System.Info.Extra (isWindows)

import Control.Lens ((^.))
import Test.Tasty
import Test.Tasty.HUnit
-- import TestUtils
import Config
import Debug.Trace (traceM)
import Development.IDE (readFileUtf8)
import Control.Lens ((^.))
import Development.IDE.Test (expectDiagnostics,
standardizeQuotes)
import System.Directory (copyFile)
import System.FilePath ((</>))
import Test.Hls
import Test.Hls.FileSystem (copy, copyDir, file, toAbsFp)
import Test.Hls.FileSystem (copyDir)
import Text.Regex.TDFA ((=~))

tests :: TestTree
Expand Down
3 changes: 1 addition & 2 deletions ghcide/test/exe/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ module Main (main) where
-- import Test.QuickCheck.Instances ()
import Data.Function ((&))
import qualified HieDbRetry
import Ide.Logger (LoggingColumn (DataColumn, PriorityColumn),
Pretty (pretty),
import Ide.Logger (Pretty (pretty),
Priority (Debug),
WithPriority (WithPriority, priority),
cfilter, cmapWithPrio,
Expand Down
9 changes: 2 additions & 7 deletions ghcide/test/exe/TestUtils.hs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@

{-# LANGUAGE GADTs #-}
{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE GADTs #-}

module TestUtils where

Expand All @@ -11,16 +10,12 @@ import Control.Lens ((.~))
import qualified Control.Lens as Lens
import qualified Control.Lens.Extras as Lens
import Control.Monad
import Control.Monad.IO.Class (liftIO)
import Data.Foldable
import Data.Function ((&))
import Data.Maybe
import qualified Data.Text as T
import Development.IDE.GHC.Compat (GhcVersion (..), ghcVersion)
import Development.IDE.GHC.Util
import qualified Development.IDE.Main as IDE
import Development.IDE.Test (canonicalizeUri,
configureCheckProject,
import Development.IDE.Test (configureCheckProject,
expectNoMoreDiagnostics)
import Development.IDE.Test.Runfiles
import Development.IDE.Types.Location
Expand Down
Loading
Loading