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 all 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
21 changes: 8 additions & 13 deletions ghcide/session-loader/Development/IDE/Session.hs
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,19 @@
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.CmdLine
import Development.IDE.GHC.Compat.Core hiding (Target,
TargetFile, TargetModule,
Var, Warning, getOptions)
import qualified Development.IDE.GHC.Compat.Core as GHC
import Development.IDE.GHC.Compat.Env hiding (Logger)
import Development.IDE.GHC.Compat.Units (UnitId)
import qualified Development.IDE.GHC.Compat.Util as Compat
import Development.IDE.GHC.Util
import Development.IDE.Graph (Action)
import qualified Development.IDE.Session.Implicit as GhcIde
import Development.IDE.Session.VersionCheck
import Development.IDE.Types.Diagnostics
import Development.IDE.Types.Exports
Expand All @@ -69,8 +70,8 @@
import Development.IDE.Types.Location
import Development.IDE.Types.Options
import GHC.Check
import GHC.ResponseFile
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 @@ -113,27 +114,21 @@
import qualified System.Random as Random
import System.Random (RandomGen)

import qualified Development.IDE.Session.Implicit as GhcIde

import Development.IDE.GHC.Compat.CmdLine


-- See Note [Guidelines For Using CPP In GHCIDE Import Statements]

#if MIN_VERSION_ghc(9,3,0)
import qualified Data.Set as OS
import qualified Development.IDE.GHC.Compat.Util as Compat
import GHC.Data.Graph.Directed

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
#endif

import GHC.Data.Graph.Directed
import GHC.ResponseFile

data Log
= LogSettingInitialDynFlags
| LogGetInitialGhcLibDirDefaultCradleFail !CradleError !FilePath !(Maybe FilePath) !(Cradle Void)
Expand Down Expand Up @@ -673,7 +668,7 @@
InstallationMismatch{..} ->
return (([renderPackageSetupException cfp GhcVersionMismatch{..}], Nothing),[])
InstallationChecked _compileTime _ghcLibCheck -> do
atomicModifyIORef' cradle_files (\xs -> (cfp:xs,()))

Check warning on line 671 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
52 changes: 19 additions & 33 deletions ghcide/src/Development/IDE/Core/Compile.hs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
-- Copyright (c) 2019 The DAML Authors. All rights reserved.
-- SPDX-License-Identifier: Apache-2.0

{-# LANGUAGE CPP #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE CPP #-}
{-# LANGUAGE GADTs #-}

-- | Based on https://ghc.haskell.org/trac/ghc/wiki/Commentary/Compiler/API.
-- Given a list of paths to find libraries, and a file to compile, produce a list of 'CoreModule' values.
Expand Down Expand Up @@ -38,17 +38,14 @@
, shareUsages
) where

import Prelude hiding (mod)
import Control.Monad.IO.Class
import Control.Concurrent.Extra
import Control.Concurrent.STM.Stats hiding (orElse)
import Control.DeepSeq (NFData (..), force,
rnf)
import Control.DeepSeq (NFData (..), force, rnf)
import Control.Exception (evaluate)
import Control.Exception.Safe
import Control.Lens hiding (List, (<.>), pre)
import Control.Monad.Except
import Control.Lens hiding (List, pre, (<.>))
import Control.Monad.Extra
import Control.Monad.IO.Class
import Control.Monad.Trans.Except
import qualified Control.Monad.Trans.State.Strict as S
import Data.Aeson (toJSON)
Expand All @@ -65,14 +62,14 @@
import Data.IORef
import Data.List.Extra
import qualified Data.Map.Strict as Map
import Data.Proxy (Proxy(Proxy))
import Data.Maybe
import Data.Proxy (Proxy (Proxy))
import qualified Data.Text as T
import Data.Time (UTCTime (..))
import Data.Tuple.Extra (dupe)
import Data.Unique as Unique
import Debug.Trace
import Development.IDE.Core.FileStore (resetInterfaceStore)

Check warning on line 72 in ghcide/src/Development/IDE/Core/Compile.hs

View workflow job for this annotation

GitHub Actions / Hlint check run

Warning in module Development.IDE.Core.Compile: Use fewer imports ▫︎ Found: "import Development.IDE.Core.FileStore ( resetInterfaceStore )\nimport Development.IDE.Core.FileStore ( shareFilePath )\n" ▫︎ Perhaps: "import Development.IDE.Core.FileStore\n ( resetInterfaceStore, shareFilePath )\n"
import Development.IDE.Core.Preprocessor
import Development.IDE.Core.RuleTypes
import Development.IDE.Core.Shake
Expand All @@ -97,33 +94,26 @@
import qualified GHC.LanguageExtensions as LangExt
import GHC.Serialized
import HieDb hiding (withHieDb)
import qualified Language.LSP.Protocol.Message as LSP
import Language.LSP.Protocol.Types (DiagnosticTag (..))
import qualified Language.LSP.Protocol.Types as LSP
import qualified Language.LSP.Server as LSP
import Language.LSP.Protocol.Types (DiagnosticTag (..))
import qualified Language.LSP.Protocol.Types as LSP
import qualified Language.LSP.Protocol.Message as LSP
import Prelude hiding (mod)
import System.Directory
import System.FilePath
import System.IO.Extra (fixIO, newTempFileWithin)

-- See Note [Guidelines For Using CPP In GHCIDE Import Statements]

import GHC.Tc.Gen.Splice



import qualified GHC as G

#if !MIN_VERSION_ghc(9,3,0)
import GHC (ModuleGraph)
#endif

import GHC.Tc.Gen.Splice
import GHC.Types.ForeignStubs
import GHC.Types.HpcInfo
import GHC.Types.TypeEnv

-- See Note [Guidelines For Using CPP In GHCIDE Import Statements]

#if !MIN_VERSION_ghc(9,3,0)
import Data.Map (Map)
import GHC (GhcException (..))
import GHC.Unit.Module.Graph (ModuleGraph)
import Unsafe.Coerce
#endif

Expand All @@ -132,8 +122,8 @@
#endif

#if MIN_VERSION_ghc(9,5,0)
import GHC.Driver.Config.CoreToStg.Prep
import GHC.Core.Lint.Interactive
import GHC.Driver.Config.CoreToStg.Prep
#endif

#if MIN_VERSION_ghc(9,7,0)
Expand Down Expand Up @@ -482,11 +472,7 @@
tcGblEnv = tmrTypechecked tcm
details <- makeSimpleDetails hsc_env_tmp tcGblEnv
sf <- finalSafeMode (ms_hspp_opts ms) tcGblEnv
iface' <- mkIfaceTc hsc_env_tmp sf details ms
#if MIN_VERSION_ghc(9,5,0)
Nothing
#endif
tcGblEnv
iface' <- mkIfaceTc hsc_env_tmp sf details ms Nothing tcGblEnv
let iface = iface' { mi_globals = Nothing, mi_usages = filterUsages (mi_usages iface') } -- See Note [Clearing mi_globals after generating an iface]
pure $! mkHiFileResult ms iface details (tmrRuntimeModules tcm) Nothing

Expand Down Expand Up @@ -1266,7 +1252,7 @@
PFailedWithErrorMessages msgs ->
throwE $ diagFromErrMsgs sourceParser dflags $ msgs dflags
POk pst rdr_module -> do
let (warns, errs) = renderMessages $ getPsMessages pst dflags
let (warns, errs) = renderMessages $ getPsMessages pst

-- Just because we got a `POk`, it doesn't mean there
-- weren't errors! To clarify, the GHC parser
Expand Down Expand Up @@ -1301,7 +1287,7 @@
POk pst rdr_module ->
let
hpm_annotations = mkApiAnns pst
psMessages = getPsMessages pst dflags
psMessages = getPsMessages pst
in
do
let IdePreprocessedSource preproc_warns errs parsed = customPreprocessor rdr_module
Expand All @@ -1310,7 +1296,7 @@
throwE $ diagFromStrings sourceParser DiagnosticSeverity_Error errs

let preproc_warnings = diagFromStrings sourceParser DiagnosticSeverity_Warning preproc_warns
(parsed', msgs) <- liftIO $ applyPluginsParsedResultAction env dflags ms hpm_annotations parsed psMessages
(parsed', msgs) <- liftIO $ applyPluginsParsedResultAction env ms hpm_annotations parsed psMessages
let (warns, errors) = renderMessages msgs

-- Just because we got a `POk`, it doesn't mean there
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
Loading
Loading