diff --git a/exe/Main.hs b/exe/Main.hs index ee46a7cbcf..16f99a44e0 100644 --- a/exe/Main.hs +++ b/exe/Main.hs @@ -13,7 +13,7 @@ import Data.Function ((&)) import Data.Functor ((<&>)) import Data.Maybe (catMaybes) import Data.Text (Text) -import Development.IDE.Types.Logger (Doc, Priority (Error, Info), +import Ide.Logger (Doc, Priority (Error, Info), Recorder, WithPriority (WithPriority, priority), cfilter, cmapWithPrio, @@ -21,7 +21,7 @@ import Development.IDE.Types.Logger (Doc, Priority (Error, Info), layoutPretty, logWith, makeDefaultStderrRecorder, renderStrict, withFileRecorder) -import qualified Development.IDE.Types.Logger as Logger +import qualified Ide.Logger as Logger import qualified HlsPlugins as Plugins import Ide.Arguments (Arguments (..), GhcideArguments (..), diff --git a/exe/Wrapper.hs b/exe/Wrapper.hs index 6bebc98923..32f7327e56 100644 --- a/exe/Wrapper.hs +++ b/exe/Wrapper.hs @@ -45,14 +45,14 @@ import qualified Data.Text as T import qualified Data.Text.IO as T import Development.IDE.LSP.LanguageServer (runLanguageServer) import qualified Development.IDE.Main as Main -import Development.IDE.Types.Logger (Doc, Logger (Logger), +import GHC.Stack.Types (emptyCallStack) +import Ide.Logger (Doc, Logger (Logger), Pretty (pretty), Recorder (logger_), WithPriority (WithPriority), cmapWithPrio, makeDefaultStderrRecorder, toCologActionWithPrio) -import GHC.Stack.Types (emptyCallStack) import Ide.Plugin.Config (Config) import Ide.Types (IdePlugins (IdePlugins)) import Language.LSP.Protocol.Message (Method (Method_Initialize), diff --git a/ghcide/exe/Main.hs b/ghcide/exe/Main.hs index ec72d277b6..0c6b1dd0f9 100644 --- a/ghcide/exe/Main.hs +++ b/ghcide/exe/Main.hs @@ -22,7 +22,9 @@ import qualified Development.IDE.Main as IDEMain import qualified Development.IDE.Monitoring.EKG as EKG import qualified Development.IDE.Monitoring.OpenTelemetry as OpenTelemetry import qualified Development.IDE.Plugin.HLS.GhcIde as GhcIde -import Development.IDE.Types.Logger (Logger (Logger), +import Development.IDE.Types.Options +import GHC.Stack (emptyCallStack) +import Ide.Logger (Logger (Logger), LoggingColumn (DataColumn, PriorityColumn), Pretty (pretty), Priority (Debug, Error, Info), @@ -33,9 +35,7 @@ import Development.IDE.Types.Logger (Logger (Logger), layoutPretty, makeDefaultStderrRecorder, renderStrict) -import qualified Development.IDE.Types.Logger as Logger -import Development.IDE.Types.Options -import GHC.Stack (emptyCallStack) +import qualified Ide.Logger as Logger import Ide.Plugin.Config (Config (checkParents, checkProject)) import Ide.PluginUtils (pluginDescToIdePlugins) import Ide.Types (PluginDescriptor (pluginNotificationHandlers), diff --git a/ghcide/ghcide.cabal b/ghcide/ghcide.cabal index 9ba17e756a..8fbd855be2 100644 --- a/ghcide/ghcide.cabal +++ b/ghcide/ghcide.cabal @@ -197,7 +197,6 @@ library Development.IDE.Types.HscEnvEq Development.IDE.Types.KnownTargets Development.IDE.Types.Location - Development.IDE.Types.Logger Development.IDE.Types.Monitoring Development.IDE.Monitoring.OpenTelemetry Development.IDE.Types.Options diff --git a/ghcide/session-loader/Development/IDE/Session.hs b/ghcide/session-loader/Development/IDE/Session.hs index cfc9796c33..afcac00308 100644 --- a/ghcide/session-loader/Development/IDE/Session.hs +++ b/ghcide/session-loader/Development/IDE/Session.hs @@ -65,13 +65,6 @@ import Development.IDE.Types.Exports import Development.IDE.Types.HscEnvEq (HscEnvEq, newHscEnvEq, newHscEnvEqPreserveImportPaths) import Development.IDE.Types.Location -import Development.IDE.Types.Logger (Pretty (pretty), - Priority (Debug, Error, Info, Warning), - Recorder, WithPriority, - cmapWithPrio, logWith, - nest, - toCologActionWithPrio, - vcat, viaShow, (<+>)) import Development.IDE.Types.Options import GHC.Check import qualified HIE.Bios as HieBios @@ -79,6 +72,13 @@ import HIE.Bios.Environment hiding (getCacheDir) import HIE.Bios.Types hiding (Log) import qualified HIE.Bios.Types as HieBios import Hie.Implicit.Cradle (loadImplicitHieCradle) +import Ide.Logger (Pretty (pretty), + Priority (Debug, Error, Info, Warning), + Recorder, WithPriority, + cmapWithPrio, logWith, + nest, + toCologActionWithPrio, + vcat, viaShow, (<+>)) import Language.LSP.Protocol.Message import Language.LSP.Server import System.Directory diff --git a/ghcide/src/Development/IDE.hs b/ghcide/src/Development/IDE.hs index 503f0104f8..8aa3b8c815 100644 --- a/ghcide/src/Development/IDE.hs +++ b/ghcide/src/Development/IDE.hs @@ -55,4 +55,4 @@ import Development.IDE.Types.HscEnvEq as X (HscEnvEq (..), hscEnv, hscEnvWithImportPaths) import Development.IDE.Types.Location as X -import Development.IDE.Types.Logger as X +import Ide.Logger as X diff --git a/ghcide/src/Development/IDE/Core/FileExists.hs b/ghcide/src/Development/IDE/Core/FileExists.hs index 9a1caecd88..b7e568d0d6 100644 --- a/ghcide/src/Development/IDE/Core/FileExists.hs +++ b/ghcide/src/Development/IDE/Core/FileExists.hs @@ -27,11 +27,11 @@ import Development.IDE.Core.Shake hiding (Log) import qualified Development.IDE.Core.Shake as Shake import Development.IDE.Graph import Development.IDE.Types.Location -import Development.IDE.Types.Logger (Pretty (pretty), - Recorder, WithPriority, - cmapWithPrio) import Development.IDE.Types.Options import qualified Focus +import Ide.Logger (Pretty (pretty), + Recorder, WithPriority, + cmapWithPrio) import Ide.Plugin.Config (Config) import Language.LSP.Protocol.Types import Language.LSP.Server hiding (getVirtualFile) diff --git a/ghcide/src/Development/IDE/Core/FileStore.hs b/ghcide/src/Development/IDE/Core/FileStore.hs index 89d50432cf..229aaecb96 100644 --- a/ghcide/src/Development/IDE/Core/FileStore.hs +++ b/ghcide/src/Development/IDE/Core/FileStore.hs @@ -54,7 +54,7 @@ import qualified System.Directory as Dir #else #endif -import qualified Development.IDE.Types.Logger as L +import qualified Ide.Logger as L import Data.Aeson (ToJSON (toJSON)) import qualified Data.Binary as B @@ -63,7 +63,7 @@ import Data.List (foldl') import qualified Data.Text as Text import Development.IDE.Core.IdeConfiguration (isWorkspaceFile) import qualified Development.IDE.Core.Shake as Shake -import Development.IDE.Types.Logger (Pretty (pretty), +import Ide.Logger (Pretty (pretty), Priority (Info), Recorder, WithPriority, diff --git a/ghcide/src/Development/IDE/Core/OfInterest.hs b/ghcide/src/Development/IDE/Core/OfInterest.hs index ddb919a424..17858544c2 100644 --- a/ghcide/src/Development/IDE/Core/OfInterest.hs +++ b/ghcide/src/Development/IDE/Core/OfInterest.hs @@ -40,13 +40,13 @@ import qualified Development.IDE.Core.Shake as Shake import Development.IDE.Plugin.Completions.Types import Development.IDE.Types.Exports import Development.IDE.Types.Location -import Development.IDE.Types.Logger (Pretty (pretty), +import Development.IDE.Types.Options (IdeTesting (..)) +import GHC.TypeLits (KnownSymbol) +import Ide.Logger (Pretty (pretty), Recorder, WithPriority, cmapWithPrio, logDebug) -import Development.IDE.Types.Options (IdeTesting (..)) -import GHC.TypeLits (KnownSymbol) import qualified Language.LSP.Protocol.Message as LSP import qualified Language.LSP.Server as LSP diff --git a/ghcide/src/Development/IDE/Core/Rules.hs b/ghcide/src/Development/IDE/Core/Rules.hs index 109259df7b..10a7b9c362 100644 --- a/ghcide/src/Development/IDE/Core/Rules.hs +++ b/ghcide/src/Development/IDE/Core/Rules.hs @@ -153,9 +153,9 @@ import Control.Concurrent.STM.Stats (atomically) import Language.LSP.Server (LspT) import System.Info.Extra (isWindows) import HIE.Bios.Ghc.Gap (hostIsDynamic) -import Development.IDE.Types.Logger (Recorder, logWith, cmapWithPrio, WithPriority, Pretty (pretty), (<+>), nest, vcat) +import Ide.Logger (Recorder, logWith, cmapWithPrio, WithPriority, Pretty (pretty), (<+>), nest, vcat) import qualified Development.IDE.Core.Shake as Shake -import qualified Development.IDE.Types.Logger as Logger +import qualified Ide.Logger as Logger import qualified Development.IDE.Types.Shake as Shake import Development.IDE.GHC.CoreFile import Data.Time.Clock.POSIX (posixSecondsToUTCTime) diff --git a/ghcide/src/Development/IDE/Core/Service.hs b/ghcide/src/Development/IDE/Core/Service.hs index 3e61ee582e..e88dd341ab 100644 --- a/ghcide/src/Development/IDE/Core/Service.hs +++ b/ghcide/src/Development/IDE/Core/Service.hs @@ -23,13 +23,13 @@ import Development.IDE.Core.Debouncer import Development.IDE.Core.FileExists (fileExistsRules) import Development.IDE.Core.OfInterest hiding (Log, LogShake) import Development.IDE.Graph -import Development.IDE.Types.Logger as Logger (Logger, +import Development.IDE.Types.Options (IdeOptions (..)) +import Ide.Logger as Logger (Logger, Pretty (pretty), Priority (Debug), Recorder, WithPriority, cmapWithPrio) -import Development.IDE.Types.Options (IdeOptions (..)) import Ide.Plugin.Config import qualified Language.LSP.Protocol.Types as LSP import qualified Language.LSP.Server as LSP diff --git a/ghcide/src/Development/IDE/Core/Shake.hs b/ghcide/src/Development/IDE/Core/Shake.hs index 4ba1090087..b66d499562 100644 --- a/ghcide/src/Development/IDE/Core/Shake.hs +++ b/ghcide/src/Development/IDE/Core/Shake.hs @@ -152,8 +152,8 @@ import Development.IDE.Types.Exports import qualified Development.IDE.Types.Exports as ExportsMap import Development.IDE.Types.KnownTargets import Development.IDE.Types.Location -import Development.IDE.Types.Logger hiding (Priority) -import qualified Development.IDE.Types.Logger as Logger +import Ide.Logger hiding (Priority) +import qualified Ide.Logger as Logger import Development.IDE.Types.Monitoring (Monitoring (..)) import Development.IDE.Types.Options import Development.IDE.Types.Shake diff --git a/ghcide/src/Development/IDE/Core/Tracing.hs b/ghcide/src/Development/IDE/Core/Tracing.hs index ce4e3b6bc3..ee87c18727 100644 --- a/ghcide/src/Development/IDE/Core/Tracing.hs +++ b/ghcide/src/Development/IDE/Core/Tracing.hs @@ -29,7 +29,7 @@ import Development.IDE.Graph.Rule import Development.IDE.Types.Diagnostics (FileDiagnostic, showDiagnostics) import Development.IDE.Types.Location (Uri (..)) -import Development.IDE.Types.Logger (Logger (Logger)) +import Ide.Logger (Logger (Logger)) import Ide.Types (PluginId (..)) import Language.LSP.Protocol.Types (NormalizedFilePath, fromNormalizedFilePath) diff --git a/ghcide/src/Development/IDE/LSP/HoverDefinition.hs b/ghcide/src/Development/IDE/LSP/HoverDefinition.hs index fdd51a9014..7ad2021dc2 100644 --- a/ghcide/src/Development/IDE/LSP/HoverDefinition.hs +++ b/ghcide/src/Development/IDE/LSP/HoverDefinition.hs @@ -21,7 +21,7 @@ import Development.IDE.Core.Actions import Development.IDE.Core.Rules import Development.IDE.Core.Shake import Development.IDE.Types.Location -import Development.IDE.Types.Logger +import Ide.Logger import Language.LSP.Protocol.Message import Language.LSP.Protocol.Types import qualified Language.LSP.Server as LSP diff --git a/ghcide/src/Development/IDE/LSP/LanguageServer.hs b/ghcide/src/Development/IDE/LSP/LanguageServer.hs index 5e3a8800b7..80d7d1b7bf 100644 --- a/ghcide/src/Development/IDE/LSP/LanguageServer.hs +++ b/ghcide/src/Development/IDE/LSP/LanguageServer.hs @@ -41,9 +41,9 @@ import Development.IDE.Core.IdeConfiguration import Development.IDE.Core.Shake hiding (Log, Priority) import Development.IDE.Core.Tracing import qualified Development.IDE.Session as Session -import Development.IDE.Types.Logger -import qualified Development.IDE.Types.Logger as Logger import Development.IDE.Types.Shake (WithHieDb) +import Ide.Logger +import qualified Ide.Logger as Logger import Language.LSP.Server (LanguageContextEnv, LspServerLog, type (<~>)) diff --git a/ghcide/src/Development/IDE/LSP/Notifications.hs b/ghcide/src/Development/IDE/LSP/Notifications.hs index 80b956904d..6674bd4b86 100644 --- a/ghcide/src/Development/IDE/LSP/Notifications.hs +++ b/ghcide/src/Development/IDE/LSP/Notifications.hs @@ -37,8 +37,8 @@ import Development.IDE.Core.Service hiding (Log, LogShake) import Development.IDE.Core.Shake hiding (Log, Priority) import qualified Development.IDE.Core.Shake as Shake import Development.IDE.Types.Location -import Development.IDE.Types.Logger import Development.IDE.Types.Shake (toKey) +import Ide.Logger import Ide.Types import Numeric.Natural diff --git a/ghcide/src/Development/IDE/Main.hs b/ghcide/src/Development/IDE/Main.hs index a7b124a96a..b440b4c2ff 100644 --- a/ghcide/src/Development/IDE/Main.hs +++ b/ghcide/src/Development/IDE/Main.hs @@ -77,7 +77,7 @@ import Development.IDE.Session (SessionLoadingOptions import qualified Development.IDE.Session as Session import Development.IDE.Types.Location (NormalizedUri, toNormalizedFilePath') -import Development.IDE.Types.Logger (Logger, +import Ide.Logger (Logger, Pretty (pretty), Priority (Info, Warning), Recorder, diff --git a/ghcide/src/Development/IDE/Main/HeapStats.hs b/ghcide/src/Development/IDE/Main/HeapStats.hs index a1c0b9f3d7..ac1af8f28e 100644 --- a/ghcide/src/Development/IDE/Main/HeapStats.hs +++ b/ghcide/src/Development/IDE/Main/HeapStats.hs @@ -6,11 +6,11 @@ import Control.Concurrent import Control.Concurrent.Async import Control.Monad import Data.Word -import Development.IDE.Types.Logger (Pretty (pretty), Priority (Info), - Recorder, WithPriority, hsep, - logWith, (<+>)) import GHC.Stats -import Text.Printf (printf) +import Ide.Logger (Pretty (pretty), Priority (Info), + Recorder, WithPriority, hsep, + logWith, (<+>)) +import Text.Printf (printf) data Log = LogHeapStatsPeriod !Int diff --git a/ghcide/src/Development/IDE/Monitoring/EKG.hs b/ghcide/src/Development/IDE/Monitoring/EKG.hs index 2999285442..e4d9f6d0ae 100644 --- a/ghcide/src/Development/IDE/Monitoring/EKG.hs +++ b/ghcide/src/Development/IDE/Monitoring/EKG.hs @@ -1,14 +1,14 @@ {-# LANGUAGE CPP #-} module Development.IDE.Monitoring.EKG(monitoring) where -import Development.IDE.Types.Logger (Logger) import Development.IDE.Types.Monitoring (Monitoring (..)) +import Ide.Logger (Logger) #ifdef MONITORING_EKG import Control.Concurrent (killThread) import Control.Concurrent.Async (async, waitCatch) import Control.Monad (forM_) import Data.Text (pack) -import Development.IDE.Types.Logger (logInfo) +import Ide.Logger (logInfo) import qualified System.Metrics as Monitoring import qualified System.Remote.Monitoring.Wai as Monitoring diff --git a/ghcide/src/Development/IDE/Plugin/Completions.hs b/ghcide/src/Development/IDE/Plugin/Completions.hs index 4f6b8cfa97..e1ed48806b 100644 --- a/ghcide/src/Development/IDE/Plugin/Completions.hs +++ b/ghcide/src/Development/IDE/Plugin/Completions.hs @@ -36,7 +36,7 @@ import Development.IDE.Types.HscEnvEq (HscEnvEq (envPackageE hscEnv) import qualified Development.IDE.Types.KnownTargets as KT import Development.IDE.Types.Location -import Development.IDE.Types.Logger (Pretty (pretty), +import Ide.Logger (Pretty (pretty), Recorder, WithPriority, cmapWithPrio) diff --git a/ghcide/src/Development/IDE/Plugin/HLS.hs b/ghcide/src/Development/IDE/Plugin/HLS.hs index 5f3ca5882f..755517375c 100644 --- a/ghcide/src/Development/IDE/Plugin/HLS.hs +++ b/ghcide/src/Development/IDE/Plugin/HLS.hs @@ -32,7 +32,7 @@ import Development.IDE.Graph (Rules) import Development.IDE.LSP.Server import Development.IDE.Plugin import qualified Development.IDE.Plugin as P -import Development.IDE.Types.Logger hiding (Error) +import Ide.Logger hiding (Error) import Ide.Plugin.Config import Ide.PluginUtils (getClientConfig) import Ide.Types as HLS diff --git a/ghcide/src/Development/IDE/Plugin/TypeLenses.hs b/ghcide/src/Development/IDE/Plugin/TypeLenses.hs index 0056fb0f7b..c5fa7e0893 100644 --- a/ghcide/src/Development/IDE/Plugin/TypeLenses.hs +++ b/ghcide/src/Development/IDE/Plugin/TypeLenses.hs @@ -46,10 +46,10 @@ import Development.IDE.Graph.Classes import Development.IDE.Spans.LocalBindings (Bindings, getFuzzyScope) import Development.IDE.Types.Location (Position (Position, _character, _line), Range (Range, _end, _start)) -import Development.IDE.Types.Logger (Pretty (pretty), +import GHC.Generics (Generic) +import Ide.Logger (Pretty (pretty), Recorder, WithPriority, cmapWithPrio) -import GHC.Generics (Generic) import Ide.Plugin.Properties import Ide.PluginUtils import Ide.Types (CommandFunction, diff --git a/ghcide/src/Development/IDE/Types/Action.hs b/ghcide/src/Development/IDE/Types/Action.hs index 462bdc901b..0aedd1d0da 100644 --- a/ghcide/src/Development/IDE/Types/Action.hs +++ b/ghcide/src/Development/IDE/Types/Action.hs @@ -11,12 +11,12 @@ module Development.IDE.Types.Action where import Control.Concurrent.STM -import Data.Hashable (Hashable (..)) -import Data.HashSet (HashSet) -import qualified Data.HashSet as Set -import Data.Unique (Unique) -import Development.IDE.Graph (Action) -import Development.IDE.Types.Logger +import Data.Hashable (Hashable (..)) +import Data.HashSet (HashSet) +import qualified Data.HashSet as Set +import Data.Unique (Unique) +import Development.IDE.Graph (Action) +import Ide.Logger import Numeric.Natural data DelayedAction a = DelayedAction diff --git a/ghcide/test/exe/HieDbRetry.hs b/ghcide/test/exe/HieDbRetry.hs index c51c8bbebc..b84715c1b8 100644 --- a/ghcide/test/exe/HieDbRetry.hs +++ b/ghcide/test/exe/HieDbRetry.hs @@ -1,22 +1,21 @@ {-# LANGUAGE MultiWayIf #-} module HieDbRetry (tests) where -import Control.Concurrent.Extra (Var, modifyVar, newVar, readVar, - withVar) -import Control.Exception (ErrorCall (ErrorCall), evaluate, - throwIO, tryJust) -import Control.Monad.IO.Class (MonadIO (liftIO)) -import Data.Tuple.Extra (dupe) -import qualified Database.SQLite.Simple as SQLite -import Development.IDE.Session (retryOnException, - retryOnSqliteBusy) -import qualified Development.IDE.Session as Session -import Development.IDE.Types.Logger (Recorder (Recorder, logger_), - WithPriority (WithPriority, payload), - cmapWithPrio) -import qualified System.Random as Random -import Test.Tasty (TestTree, testGroup) -import Test.Tasty.HUnit (assertFailure, testCase, (@?=)) +import Control.Concurrent.Extra (Var, modifyVar, newVar, readVar, + withVar) +import Control.Exception (ErrorCall (ErrorCall), evaluate, + throwIO, tryJust) +import Control.Monad.IO.Class (MonadIO (liftIO)) +import Data.Tuple.Extra (dupe) +import qualified Database.SQLite.Simple as SQLite +import Development.IDE.Session (retryOnException, retryOnSqliteBusy) +import qualified Development.IDE.Session as Session +import Ide.Logger (Recorder (Recorder, logger_), + WithPriority (WithPriority, payload), + cmapWithPrio) +import qualified System.Random as Random +import Test.Tasty (TestTree, testGroup) +import Test.Tasty.HUnit (assertFailure, testCase, (@?=)) data Log = LogSession Session.Log diff --git a/ghcide/test/exe/Main.hs b/ghcide/test/exe/Main.hs index 208871a933..91fa90bf00 100644 --- a/ghcide/test/exe/Main.hs +++ b/ghcide/test/exe/Main.hs @@ -130,7 +130,7 @@ import qualified Development.IDE.Plugin.HLS.GhcIde as Ghcide import Development.IDE.Plugin.Test (TestRequest (BlockSeconds), WaitForIdeRuleResult (..), blockCommandId) -import Development.IDE.Types.Logger (Logger (Logger), +import Ide.Logger (Logger (Logger), LoggingColumn (DataColumn, PriorityColumn), Pretty (pretty), Priority (Debug), diff --git a/hls-plugin-api/hls-plugin-api.cabal b/hls-plugin-api/hls-plugin-api.cabal index 4a4c370f5d..e5250eee27 100644 --- a/hls-plugin-api/hls-plugin-api.cabal +++ b/hls-plugin-api/hls-plugin-api.cabal @@ -41,11 +41,13 @@ library Ide.Plugin.Resolve Ide.PluginUtils Ide.Types + Ide.Logger hs-source-dirs: src build-depends: , aeson , base >=4.12 && <5 + , co-log-core , containers , data-default , dependent-map @@ -62,10 +64,14 @@ library , lsp ^>=2.0.0.0 , opentelemetry >=0.4 , optparse-applicative + , prettyprinter , regex-tdfa >=1.3.1.0 , row-types + , stm , text + , time , transformers + , unliftio , unordered-containers , megaparsec > 9 diff --git a/ghcide/src/Development/IDE/Types/Logger.hs b/hls-plugin-api/src/Ide/Logger.hs similarity index 97% rename from ghcide/src/Development/IDE/Types/Logger.hs rename to hls-plugin-api/src/Ide/Logger.hs index aec4fa3c0a..aab41f4e73 100644 --- a/ghcide/src/Development/IDE/Types/Logger.hs +++ b/hls-plugin-api/src/Ide/Logger.hs @@ -1,11 +1,18 @@ -- Copyright (c) 2019 The DAML Authors. All rights reserved. -- SPDX-License-Identifier: Apache-2.0 -{-# LANGUAGE RankNTypes #-} +{-# LANGUAGE DeriveFunctor #-} +{-# LANGUAGE LambdaCase #-} +{-# LANGUAGE NamedFieldPuns #-} +{-# LANGUAGE OverloadedStrings #-} +{-# LANGUAGE RankNTypes #-} +{-# LANGUAGE RecordWildCards #-} +{-# LANGUAGE ScopedTypeVariables #-} + -- | This is a compatibility module that abstracts over the -- concrete choice of logging framework so users can plug in whatever -- framework they want to. -module Development.IDE.Types.Logger +module Ide.Logger ( Priority(..) , Logger(..) , Recorder(..) @@ -65,8 +72,7 @@ import Prettyprinter.Render.Text (renderStrict) import System.IO (Handle, IOMode (AppendMode), hClose, hFlush, openFile, stderr) -import UnliftIO (MonadUnliftIO, displayException, - finally, try) +import UnliftIO (MonadUnliftIO, finally, try) data Priority -- Don't change the ordering of this type or you will mess up the Ord diff --git a/hls-plugin-api/src/Ide/Plugin/Resolve.hs b/hls-plugin-api/src/Ide/Plugin/Resolve.hs index 9f5ab76014..73e79a3c14 100644 --- a/hls-plugin-api/src/Ide/Plugin/Resolve.hs +++ b/hls-plugin-api/src/Ide/Plugin/Resolve.hs @@ -1,10 +1,11 @@ {-# LANGUAGE DeriveGeneric #-} {-# LANGUAGE DisambiguateRecordFields #-} +{-# LANGUAGE LambdaCase #-} +{-# LANGUAGE NamedFieldPuns #-} {-# LANGUAGE OverloadedLabels #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE RankNTypes #-} {-# LANGUAGE ScopedTypeVariables #-} - module Ide.Plugin.Resolve (mkCodeActionHandlerWithResolve, mkCodeActionWithResolveAndCommand) where @@ -19,6 +20,7 @@ import Data.Maybe (catMaybes) import Data.Row ((.!)) import qualified Data.Text as T import GHC.Generics (Generic) +import Ide.Logger import Ide.Types import qualified Language.LSP.Protocol.Lens as L import Language.LSP.Protocol.Message @@ -29,6 +31,16 @@ import Language.LSP.Server (LspM, LspT, sendRequest, withIndefiniteProgress) +data Log + = DoesNotSupportResolve T.Text + | ApplyWorkspaceEditFailed ResponseError +instance Pretty Log where + pretty = \case + DoesNotSupportResolve fallback-> + "Client does not support resolve," <+> pretty fallback + ApplyWorkspaceEditFailed err -> + "ApplyWorkspaceEditFailed:" <+> viaShow err + -- |When provided with both a codeAction provider and an affiliated codeAction -- resolve provider, this function creates a handler that automatically uses -- your resolve provider to fill out you original codeAction if the client doesn't @@ -36,38 +48,41 @@ import Language.LSP.Server (LspM, LspT, -- the client supports resolve and act accordingly in your own providers. mkCodeActionHandlerWithResolve :: forall ideState a. (A.FromJSON a) => - (ideState -> PluginId -> CodeActionParams -> LspM Config (Either ResponseError ([Command |? CodeAction] |? Null))) + Recorder (WithPriority Log) + -> (ideState -> PluginId -> CodeActionParams -> LspM Config (Either ResponseError ([Command |? CodeAction] |? Null))) -> (ideState -> PluginId -> CodeAction -> Uri -> a -> LspM Config (Either ResponseError CodeAction)) -> PluginHandlers ideState -mkCodeActionHandlerWithResolve codeActionMethod codeResolveMethod = - let newCodeActionMethod ideState pid params = runExceptT $ - do codeActionReturn <- ExceptT $ codeActionMethod ideState pid params - caps <- lift getClientCapabilities - case codeActionReturn of - r@(InR Null) -> pure r - (InL ls) | -- If the client supports resolve, we will wrap the resolve data in a owned - -- resolve data type to allow the server to know who to send the resolve request to - supportsCodeActionResolve caps -> pure $ InL ls - --This is the actual part where we call resolveCodeAction which fills in the edit data for the client - | otherwise -> InL <$> traverse (resolveCodeAction (params ^. L.textDocument . L.uri) ideState pid) ls - in (mkPluginHandler SMethod_TextDocumentCodeAction newCodeActionMethod - <> mkResolveHandler SMethod_CodeActionResolve codeResolveMethod) - where - dropData :: CodeAction -> CodeAction +mkCodeActionHandlerWithResolve recorder codeActionMethod codeResolveMethod = + let newCodeActionMethod ideState pid params = runExceptT $ + do codeActionReturn <- ExceptT $ codeActionMethod ideState pid params + caps <- lift getClientCapabilities + case codeActionReturn of + r@(InR Null) -> pure r + (InL ls) | -- We don't need to do anything if the client supports + -- resolve + supportsCodeActionResolve caps -> pure $ InL ls + --This is the actual part where we call resolveCodeAction which fills in the edit data for the client + | otherwise -> do + logWith recorder Debug (DoesNotSupportResolve "filling in the code action") + InL <$> traverse (resolveCodeAction (params ^. L.textDocument . L.uri) ideState pid) ls + in (mkPluginHandler SMethod_TextDocumentCodeAction newCodeActionMethod + <> mkResolveHandler SMethod_CodeActionResolve codeResolveMethod) + where dropData :: CodeAction -> CodeAction dropData ca = ca & L.data_ .~ Nothing resolveCodeAction :: Uri -> ideState -> PluginId -> (Command |? CodeAction) -> ExceptT ResponseError (LspT Config IO) (Command |? CodeAction) resolveCodeAction _uri _ideState _plId c@(InL _) = pure c resolveCodeAction uri ideState pid (InR codeAction@CodeAction{_data_=Just value}) = do - case A.fromJSON value of - A.Error err -> throwE $ parseError (Just value) (T.pack err) - A.Success innerValueDecoded -> do - resolveResult <- ExceptT $ codeResolveMethod ideState pid codeAction uri innerValueDecoded - case resolveResult of - CodeAction {_edit = Just _ } -> do - pure $ InR $ dropData resolveResult - _ -> throwE $ invalidParamsError "Returned CodeAction has no data field" + case A.fromJSON value of + A.Error err -> throwE $ parseError (Just value) (T.pack err) + A.Success innerValueDecoded -> do + resolveResult <- ExceptT $ codeResolveMethod ideState pid codeAction uri innerValueDecoded + case resolveResult of + CodeAction {_edit = Just _ } -> do + pure $ InR $ dropData resolveResult + _ -> throwE $ invalidParamsError "Returned CodeAction has no data field" resolveCodeAction _ _ _ (InR CodeAction{_data_=Nothing}) = throwE $ invalidParamsError "CodeAction has no data field" + -- |When provided with both a codeAction provider with a data field and a resolve -- provider, this function creates a handler that creates a command that uses -- your resolve if the client doesn't have code action resolve support. This means @@ -77,26 +92,28 @@ mkCodeActionHandlerWithResolve codeActionMethod codeResolveMethod = -- either in the original code action or in the resolve will be ignored. mkCodeActionWithResolveAndCommand :: forall ideState a. (A.FromJSON a) => - PluginId + Recorder (WithPriority Log) + -> PluginId -> (ideState -> PluginId -> CodeActionParams -> LspM Config (Either ResponseError ([Command |? CodeAction] |? Null))) -> (ideState -> PluginId -> CodeAction -> Uri -> a -> LspM Config (Either ResponseError CodeAction)) -> ([PluginCommand ideState], PluginHandlers ideState) -mkCodeActionWithResolveAndCommand plId codeActionMethod codeResolveMethod = - let newCodeActionMethod ideState pid params = runExceptT $ - do codeActionReturn <- ExceptT $ codeActionMethod ideState pid params - caps <- lift getClientCapabilities - case codeActionReturn of - r@(InR Null) -> pure r - (InL ls) | -- If the client supports resolve, we will wrap the resolve data in a owned - -- resolve data type to allow the server to know who to send the resolve request to - supportsCodeActionResolve caps -> - pure $ InL ls - -- If they do not we will drop the data field, in addition we will populate the command - -- field with our command to execute the resolve, with the whole code action as it's argument. - | otherwise -> pure $ InL $ moveDataToCommand (params ^. L.textDocument . L.uri) <$> ls - in ([PluginCommand "codeActionResolve" "Executes resolve for code action" (executeResolveCmd codeResolveMethod)], - mkPluginHandler SMethod_TextDocumentCodeAction newCodeActionMethod - <> mkResolveHandler SMethod_CodeActionResolve codeResolveMethod) +mkCodeActionWithResolveAndCommand recorder plId codeActionMethod codeResolveMethod = + let newCodeActionMethod ideState pid params = runExceptT $ + do codeActionReturn <- ExceptT $ codeActionMethod ideState pid params + caps <- lift getClientCapabilities + case codeActionReturn of + r@(InR Null) -> pure r + (InL ls) | -- We don't need to do anything if the client supports + -- resolve + supportsCodeActionResolve caps -> pure $ InL ls + -- If they do not we will drop the data field, in addition we will populate the command + -- field with our command to execute the resolve, with the whole code action as it's argument. + | otherwise -> do + logWith recorder Debug (DoesNotSupportResolve "rewriting the code action to use commands") + pure $ InL $ moveDataToCommand (params ^. L.textDocument . L.uri) <$> ls + in ([PluginCommand "codeActionResolve" "Executes resolve for code action" (executeResolveCmd codeResolveMethod)], + mkPluginHandler SMethod_TextDocumentCodeAction newCodeActionMethod + <> mkResolveHandler SMethod_CodeActionResolve codeResolveMethod) where moveDataToCommand :: Uri -> Command |? CodeAction -> Command |? CodeAction moveDataToCommand uri ca = let dat = A.toJSON . wrapWithURI uri <$> ca ^? _R -- We need to take the whole codeAction @@ -113,28 +130,29 @@ mkCodeActionWithResolveAndCommand plId codeActionMethod codeResolveMethod = codeAction & L.data_ .~ (A.toJSON .WithURI uri <$> data_) where data_ = codeAction ^? L.data_ . _Just executeResolveCmd :: (ideState -> PluginId -> CodeAction -> Uri -> a -> LspM Config (Either ResponseError CodeAction))-> CommandFunction ideState CodeAction - executeResolveCmd resolveProvider ideState ca@CodeAction{_data_=Just value} = do - withIndefiniteProgress "Applying edits for code action..." Cancellable $ do + executeResolveCmd resolveProvider ideState ca@CodeAction{_data_=Just value} = do + withIndefiniteProgress "Applying edits for code action..." Cancellable $ runExceptT $ do case A.fromJSON value of - A.Error err -> pure $ Left $ parseError (Just value) (T.pack err) + A.Error err -> throwE $ parseError (Just value) (T.pack err) A.Success (WithURI uri innerValue) -> do case A.fromJSON innerValue of - A.Error err -> pure $ Left $ parseError (Just value) (T.pack err) + A.Error err -> throwE $ parseError (Just value) (T.pack err) A.Success innerValueDecoded -> do - resolveResult <- resolveProvider ideState plId ca uri innerValueDecoded + resolveResult <- ExceptT $ resolveProvider ideState plId ca uri innerValueDecoded case resolveResult of - Right ca2@CodeAction {_edit = Just wedits } | diffCodeActions ca ca2 == ["edit"] -> do - _ <- sendRequest SMethod_WorkspaceApplyEdit (ApplyWorkspaceEditParams Nothing wedits) (\_ -> pure ()) - pure $ Right $ InR Null - Right ca2@CodeAction {_edit = Just _ } -> - pure $ Left $ - internalError $ + ca2@CodeAction {_edit = Just wedits } | diffCodeActions ca ca2 == ["edit"] -> do + _ <- ExceptT $ Right <$> sendRequest SMethod_WorkspaceApplyEdit (ApplyWorkspaceEditParams Nothing wedits) handleWEditCallback + pure $ InR Null + ca2@CodeAction {_edit = Just _ } -> + throwE $ internalError $ "The resolve provider unexpectedly returned a code action with the following differing fields: " <> (T.pack $ show $ diffCodeActions ca ca2) - Right _ -> pure $ Left $ internalError "The resolve provider unexpectedly returned a result with no data field" - Left err -> pure $ Left err - executeResolveCmd _ _ CodeAction{_data_= value} = pure $ Left $ invalidParamsError ("The code action to resolve has an illegal data field: " <> (T.pack $ show value)) - + _ -> throwE $ internalError "The resolve provider unexpectedly returned a result with no data field" + executeResolveCmd _ _ CodeAction{_data_= value} = runExceptT $ throwE $ invalidParamsError ("The code action to resolve has an illegal data field: " <> (T.pack $ show value)) + handleWEditCallback (Left err ) = do + logWith recorder Warning (ApplyWorkspaceEditFailed err) + pure () + handleWEditCallback _ = pure () -- TODO: Remove once provided by lsp-types -- |Compares two CodeActions and returns a list of fields that are not equal diff --git a/hls-test-utils/src/Test/Hls.hs b/hls-test-utils/src/Test/Hls.hs index 97c0e03fe1..1805a61d82 100644 --- a/hls-test-utils/src/Test/Hls.hs +++ b/hls-test-utils/src/Test/Hls.hs @@ -84,17 +84,17 @@ import qualified Development.IDE.Main as IDEMain import Development.IDE.Plugin.Test (TestRequest (GetBuildKeysBuilt, WaitForIdeRule, WaitForShakeQueue), WaitForIdeRuleResult (ideResultSuccess)) import qualified Development.IDE.Plugin.Test as Test -import Development.IDE.Types.Logger (Doc, Logger (Logger), +import Development.IDE.Types.Options +import GHC.IO.Handle +import GHC.Stack (emptyCallStack) +import GHC.TypeLits +import Ide.Logger (Doc, Logger (Logger), Pretty (pretty), Priority (Debug), Recorder (Recorder, logger_), WithPriority (WithPriority, priority), cfilter, cmapWithPrio, makeDefaultStderrRecorder) -import Development.IDE.Types.Options -import GHC.IO.Handle -import GHC.Stack (emptyCallStack) -import GHC.TypeLits import Ide.Types import Language.LSP.Protocol.Capabilities import Language.LSP.Protocol.Message diff --git a/plugins/hls-alternate-number-format-plugin/src/Ide/Plugin/AlternateNumberFormat.hs b/plugins/hls-alternate-number-format-plugin/src/Ide/Plugin/AlternateNumberFormat.hs index e64c626227..cd1dddbb0c 100644 --- a/plugins/hls-alternate-number-format-plugin/src/Ide/Plugin/AlternateNumberFormat.hs +++ b/plugins/hls-alternate-number-format-plugin/src/Ide/Plugin/AlternateNumberFormat.hs @@ -20,8 +20,8 @@ import Development.IDE.GHC.Util (getExtensions) import Development.IDE.Graph.Classes (Hashable, NFData, rnf) import Development.IDE.Spans.Pragmas (NextPragmaInfo, getFirstPragma, insertNewPragma) -import Development.IDE.Types.Logger as Logger import GHC.Generics (Generic) +import Ide.Logger as Logger import Ide.Plugin.Conversion (AlternateFormat, ExtensionNeeded (NeedsExtension, NoExtension), alternateFormat) diff --git a/plugins/hls-code-range-plugin/hls-code-range-plugin.cabal b/plugins/hls-code-range-plugin/hls-code-range-plugin.cabal index 1e2dfeccad..5a9a858053 100644 --- a/plugins/hls-code-range-plugin/hls-code-range-plugin.cabal +++ b/plugins/hls-code-range-plugin/hls-code-range-plugin.cabal @@ -64,6 +64,7 @@ test-suite tests , filepath , ghcide == 2.1.0.0 , hls-code-range-plugin + , hls-plugin-api , hls-test-utils == 2.1.0.0 , lens , lsp diff --git a/plugins/hls-code-range-plugin/src/Ide/Plugin/CodeRange.hs b/plugins/hls-code-range-plugin/src/Ide/Plugin/CodeRange.hs index 57a40f8411..c7413e1e9a 100644 --- a/plugins/hls-code-range-plugin/src/Ide/Plugin/CodeRange.hs +++ b/plugins/hls-code-range-plugin/src/Ide/Plugin/CodeRange.hs @@ -35,7 +35,7 @@ import Development.IDE (Action, IdeAction, import Development.IDE.Core.PositionMapping (PositionMapping, fromCurrentPosition, toCurrentRange) -import Development.IDE.Types.Logger (Pretty (..), +import Ide.Logger (Pretty (..), Priority (Warning), logWith) import Ide.Plugin.CodeRange.Rules (CodeRange (..), diff --git a/plugins/hls-code-range-plugin/test/Main.hs b/plugins/hls-code-range-plugin/test/Main.hs index a1948ce51a..1b78ba74e8 100644 --- a/plugins/hls-code-range-plugin/test/Main.hs +++ b/plugins/hls-code-range-plugin/test/Main.hs @@ -6,7 +6,7 @@ import Control.Lens hiding (List, (<.>)) import Data.ByteString.Lazy (ByteString) import qualified Data.ByteString.Lazy.Char8 as LBSChar8 import Data.String (fromString) -import Development.IDE.Types.Logger (Priority (Debug), +import Ide.Logger (Priority (Debug), Recorder (Recorder), WithPriority (WithPriority), makeDefaultStderrRecorder, diff --git a/plugins/hls-eval-plugin/src/Ide/Plugin/Eval.hs b/plugins/hls-eval-plugin/src/Ide/Plugin/Eval.hs index f5e9ec6b1d..5084e9750f 100644 --- a/plugins/hls-eval-plugin/src/Ide/Plugin/Eval.hs +++ b/plugins/hls-eval-plugin/src/Ide/Plugin/Eval.hs @@ -12,7 +12,7 @@ module Ide.Plugin.Eval ( ) where import Development.IDE (IdeState) -import Development.IDE.Types.Logger (Pretty (pretty), Recorder, +import Ide.Logger (Pretty (pretty), Recorder, WithPriority, cmapWithPrio) import qualified Ide.Plugin.Eval.CodeLens as CL import Ide.Plugin.Eval.Config diff --git a/plugins/hls-eval-plugin/src/Ide/Plugin/Eval/Rules.hs b/plugins/hls-eval-plugin/src/Ide/Plugin/Eval/Rules.hs index 4413850398..323e3384ec 100644 --- a/plugins/hls-eval-plugin/src/Ide/Plugin/Eval/Rules.hs +++ b/plugins/hls-eval-plugin/src/Ide/Plugin/Eval/Rules.hs @@ -38,7 +38,7 @@ import Development.IDE.GHC.Compat import qualified Development.IDE.GHC.Compat as SrcLoc import qualified Development.IDE.GHC.Compat.Util as FastString import Development.IDE.Graph (alwaysRerun) -import Development.IDE.Types.Logger (Pretty (pretty), +import Ide.Logger (Pretty (pretty), Recorder, WithPriority, cmapWithPrio) #if MIN_VERSION_ghc(9,2,0) diff --git a/plugins/hls-explicit-imports-plugin/src/Ide/Plugin/ExplicitImports.hs b/plugins/hls-explicit-imports-plugin/src/Ide/Plugin/ExplicitImports.hs index 5a3e47bf5e..cc9927291e 100644 --- a/plugins/hls-explicit-imports-plugin/src/Ide/Plugin/ExplicitImports.hs +++ b/plugins/hls-explicit-imports-plugin/src/Ide/Plugin/ExplicitImports.hs @@ -1,14 +1,14 @@ -{-# LANGUAGE CPP #-} -{-# LANGUAGE DeriveAnyClass #-} -{-# LANGUAGE DeriveGeneric #-} -{-# LANGUAGE DerivingStrategies #-} -{-# LANGUAGE LambdaCase #-} -{-# LANGUAGE NamedFieldPuns #-} -{-# LANGUAGE OverloadedStrings #-} -{-# LANGUAGE RecordWildCards #-} -{-# LANGUAGE TypeFamilies #-} -{-# LANGUAGE ViewPatterns #-} - +{-# LANGUAGE CPP #-} +{-# LANGUAGE DeriveAnyClass #-} +{-# LANGUAGE DeriveGeneric #-} +{-# LANGUAGE DerivingStrategies #-} +{-# LANGUAGE ExistentialQuantification #-} +{-# LANGUAGE LambdaCase #-} +{-# LANGUAGE NamedFieldPuns #-} +{-# LANGUAGE OverloadedStrings #-} +{-# LANGUAGE RecordWildCards #-} +{-# LANGUAGE TypeFamilies #-} +{-# LANGUAGE ViewPatterns #-} module Ide.Plugin.ExplicitImports ( descriptor , descriptorForModules @@ -61,12 +61,14 @@ importCommandId = "ImportLensCommand" data Log = LogShake Shake.Log | LogWAEResponseError ResponseError - deriving Show + | forall a. (Pretty a) => LogResolve a + instance Pretty Log where pretty = \case LogShake logMsg -> pretty logMsg LogWAEResponseError rspErr -> "RequestWorkspaceApplyEdit Failed with " <+> viaShow rspErr + LogResolve msg -> pretty msg -- | The "main" function of a plugin descriptor :: Recorder (WithPriority Log) -> PluginId -> PluginDescriptor IdeState @@ -81,7 +83,9 @@ descriptorForModules -> PluginId -> PluginDescriptor IdeState descriptorForModules recorder modFilter plId = - (defaultPluginDescriptor plId) + let resolveRecorder = cmapWithPrio LogResolve recorder + codeActionHandlers = mkCodeActionHandlerWithResolve resolveRecorder (codeActionProvider recorder) (codeActionResolveProvider recorder) + in (defaultPluginDescriptor plId) { -- This plugin provides a command handler pluginCommands = [PluginCommand importCommandId "Explicit import command" (runImportCommand recorder)], @@ -92,7 +96,7 @@ descriptorForModules recorder modFilter plId = mkPluginHandler SMethod_TextDocumentCodeLens (lensProvider recorder) <> mkResolveHandler SMethod_CodeLensResolve (lensResolveProvider recorder) -- This plugin provides code actions - <> mkCodeActionHandlerWithResolve (codeActionProvider recorder) (codeActionResolveProvider recorder) + <> codeActionHandlers } diff --git a/plugins/hls-explicit-record-fields-plugin/src/Ide/Plugin/ExplicitFields.hs b/plugins/hls-explicit-record-fields-plugin/src/Ide/Plugin/ExplicitFields.hs index d5d30de168..faca4a20d5 100644 --- a/plugins/hls-explicit-record-fields-plugin/src/Ide/Plugin/ExplicitFields.hs +++ b/plugins/hls-explicit-record-fields-plugin/src/Ide/Plugin/ExplicitFields.hs @@ -57,9 +57,9 @@ import Development.IDE.Graph.Classes (Hashable, NFData (rnf)) import Development.IDE.Spans.Pragmas (NextPragmaInfo (..), getFirstPragma, insertNewPragma) -import Development.IDE.Types.Logger (Priority (..), cmapWithPrio, - logWith, (<+>)) import GHC.Generics (Generic) +import Ide.Logger (Priority (..), cmapWithPrio, + logWith, (<+>)) import Ide.Plugin.RangeMap (RangeMap) import qualified Ide.Plugin.RangeMap as RangeMap import Ide.PluginUtils (getNormalizedFilePath, diff --git a/plugins/hls-hlint-plugin/src/Ide/Plugin/Hlint.hs b/plugins/hls-hlint-plugin/src/Ide/Plugin/Hlint.hs index 62f2e08094..ee59553ab3 100644 --- a/plugins/hls-hlint-plugin/src/Ide/Plugin/Hlint.hs +++ b/plugins/hls-hlint-plugin/src/Ide/Plugin/Hlint.hs @@ -1,23 +1,24 @@ -{-# LANGUAGE CPP #-} -{-# LANGUAGE DeriveAnyClass #-} -{-# LANGUAGE DeriveGeneric #-} -{-# LANGUAGE DuplicateRecordFields #-} -{-# LANGUAGE FlexibleContexts #-} -{-# LANGUAGE FlexibleInstances #-} -{-# LANGUAGE LambdaCase #-} -{-# LANGUAGE MultiWayIf #-} -{-# LANGUAGE NamedFieldPuns #-} -{-# LANGUAGE OverloadedLabels #-} -{-# LANGUAGE OverloadedStrings #-} -{-# LANGUAGE PackageImports #-} -{-# LANGUAGE PatternSynonyms #-} -{-# LANGUAGE RecordWildCards #-} -{-# LANGUAGE ScopedTypeVariables #-} -{-# LANGUAGE StrictData #-} -{-# LANGUAGE TupleSections #-} -{-# LANGUAGE TypeApplications #-} -{-# LANGUAGE TypeFamilies #-} -{-# LANGUAGE ViewPatterns #-} +{-# LANGUAGE CPP #-} +{-# LANGUAGE DeriveAnyClass #-} +{-# LANGUAGE DeriveGeneric #-} +{-# LANGUAGE DuplicateRecordFields #-} +{-# LANGUAGE ExistentialQuantification #-} +{-# LANGUAGE FlexibleContexts #-} +{-# LANGUAGE FlexibleInstances #-} +{-# LANGUAGE LambdaCase #-} +{-# LANGUAGE MultiWayIf #-} +{-# LANGUAGE NamedFieldPuns #-} +{-# LANGUAGE OverloadedLabels #-} +{-# LANGUAGE OverloadedStrings #-} +{-# LANGUAGE PackageImports #-} +{-# LANGUAGE PatternSynonyms #-} +{-# LANGUAGE RecordWildCards #-} +{-# LANGUAGE ScopedTypeVariables #-} +{-# LANGUAGE StrictData #-} +{-# LANGUAGE TupleSections #-} +{-# LANGUAGE TypeApplications #-} +{-# LANGUAGE TypeFamilies #-} +{-# LANGUAGE ViewPatterns #-} {-# OPTIONS_GHC -Wno-orphans #-} -- On 9.4 we get a new redundant constraint warning, but deleting the @@ -153,7 +154,7 @@ data Log | LogGeneratedIdeas NormalizedFilePath [[Refact.Refactoring Refact.SrcSpan]] | LogGetIdeas NormalizedFilePath | LogUsingExtensions NormalizedFilePath [String] -- Extension is only imported conditionally, so we just stringify them - deriving Show + | forall a. (Pretty a) => LogResolve a instance Pretty Log where pretty = \case @@ -162,6 +163,7 @@ instance Pretty Log where LogGeneratedIdeas fp ideas -> "Generated hlint ideas for for" <+> viaShow fp <> ":" <+> viaShow ideas LogUsingExtensions fp exts -> "Using extensions for " <+> viaShow fp <> ":" <+> pretty exts LogGetIdeas fp -> "Getting hlint ideas for " <+> viaShow fp + LogResolve msg -> pretty msg #ifdef HLINT_ON_GHC_LIB -- Reimplementing this, since the one in Development.IDE.GHC.Compat isn't for ghc-lib @@ -187,7 +189,8 @@ fromStrictMaybe Strict.Nothing = Nothing descriptor :: Recorder (WithPriority Log) -> PluginId -> PluginDescriptor IdeState descriptor recorder plId = - let (pluginCommands, pluginHandlers) = mkCodeActionWithResolveAndCommand plId codeActionProvider (resolveProvider recorder) + let resolveRecorder = cmapWithPrio LogResolve recorder + (pluginCommands, pluginHandlers) = mkCodeActionWithResolveAndCommand resolveRecorder plId codeActionProvider (resolveProvider recorder) in (defaultPluginDescriptor plId) { pluginRules = rules recorder plId , pluginCommands = pluginCommands diff --git a/plugins/hls-module-name-plugin/src/Ide/Plugin/ModuleName.hs b/plugins/hls-module-name-plugin/src/Ide/Plugin/ModuleName.hs index eab0c67a9c..76a003d1ef 100644 --- a/plugins/hls-module-name-plugin/src/Ide/Plugin/ModuleName.hs +++ b/plugins/hls-module-name-plugin/src/Ide/Plugin/ModuleName.hs @@ -51,7 +51,7 @@ import Development.IDE.GHC.Compat (GenLocated (L), locA, moduleNameString, pattern RealSrcSpan, pm_parsed_source, unLoc) -import Development.IDE.Types.Logger (Pretty (..)) +import Ide.Logger (Pretty (..)) import Ide.Types import Language.LSP.Protocol.Message import Language.LSP.Protocol.Types diff --git a/plugins/hls-overloaded-record-dot-plugin/hls-overloaded-record-dot-plugin.cabal b/plugins/hls-overloaded-record-dot-plugin/hls-overloaded-record-dot-plugin.cabal index 12884290a0..2ccf3af986 100644 --- a/plugins/hls-overloaded-record-dot-plugin/hls-overloaded-record-dot-plugin.cabal +++ b/plugins/hls-overloaded-record-dot-plugin/hls-overloaded-record-dot-plugin.cabal @@ -62,6 +62,7 @@ test-suite tests , ghcide , text , hls-overloaded-record-dot-plugin + , hls-plugin-api , lens , lsp-test , lsp-types diff --git a/plugins/hls-overloaded-record-dot-plugin/src/Ide/Plugin/OverloadedRecordDot.hs b/plugins/hls-overloaded-record-dot-plugin/src/Ide/Plugin/OverloadedRecordDot.hs index 174358e79e..89ca4e73c9 100644 --- a/plugins/hls-overloaded-record-dot-plugin/src/Ide/Plugin/OverloadedRecordDot.hs +++ b/plugins/hls-overloaded-record-dot-plugin/src/Ide/Plugin/OverloadedRecordDot.hs @@ -70,10 +70,10 @@ import Development.IDE.Graph.Classes (Hashable, NFData (rnf)) import Development.IDE.Spans.Pragmas (NextPragmaInfo (..), getFirstPragma, insertNewPragma) -import Development.IDE.Types.Logger (Priority (..), +import GHC.Generics (Generic) +import Ide.Logger (Priority (..), cmapWithPrio, logWith, (<+>)) -import GHC.Generics (Generic) import Ide.Plugin.RangeMap (RangeMap) import qualified Ide.Plugin.RangeMap as RangeMap import Ide.Plugin.Resolve (mkCodeActionHandlerWithResolve) @@ -100,16 +100,19 @@ import Language.LSP.Protocol.Types (CodeAction (..), normalizedFilePathToUri, type (|?) (..)) import Language.LSP.Server (getClientCapabilities) + data Log = LogShake Shake.Log | LogCollectedRecordSelectors [RecordSelectorExpr] | LogTextEdits [TextEdit] + | forall a. (Pretty a) => LogResolve a instance Pretty Log where pretty = \case LogShake shakeLog -> pretty shakeLog LogCollectedRecordSelectors recs -> "Collected record selectors:" <+> pretty recs + LogResolve msg -> pretty msg data CollectRecordSelectors = CollectRecordSelectors deriving (Eq, Show, Generic) @@ -168,7 +171,9 @@ instance FromJSON ORDResolveData descriptor :: Recorder (WithPriority Log) -> PluginId -> PluginDescriptor IdeState -descriptor recorder plId = let pluginHandler = mkCodeActionHandlerWithResolve codeActionProvider resolveProvider +descriptor recorder plId = + let resolveRecorder = cmapWithPrio LogResolve recorder + pluginHandler = mkCodeActionHandlerWithResolve resolveRecorder codeActionProvider resolveProvider in (defaultPluginDescriptor plId) { pluginHandlers = pluginHandler , pluginRules = collectRecSelsRule recorder diff --git a/plugins/hls-overloaded-record-dot-plugin/test/Main.hs b/plugins/hls-overloaded-record-dot-plugin/test/Main.hs index 6015eedcba..25bfb583b1 100644 --- a/plugins/hls-overloaded-record-dot-plugin/test/Main.hs +++ b/plugins/hls-overloaded-record-dot-plugin/test/Main.hs @@ -13,7 +13,7 @@ import Data.Row import qualified Data.Text as T import qualified Data.Text.Lazy as TL import qualified Data.Text.Lazy.Encoding as TL -import Development.IDE.Types.Logger (Doc, Logger (Logger), +import Ide.Logger (Doc, Logger (Logger), Pretty (pretty), Priority (Debug), Recorder (Recorder, logger_), diff --git a/plugins/hls-refactor-plugin/src/Development/IDE/GHC/ExactPrint.hs b/plugins/hls-refactor-plugin/src/Development/IDE/GHC/ExactPrint.hs index 661f7dbcce..0521e08751 100644 --- a/plugins/hls-refactor-plugin/src/Development/IDE/GHC/ExactPrint.hs +++ b/plugins/hls-refactor-plugin/src/Development/IDE/GHC/ExactPrint.hs @@ -81,7 +81,7 @@ import Development.IDE.GHC.Compat.ExactPrint import Development.IDE.Graph (RuleResult, Rules) import Development.IDE.Graph.Classes import Development.IDE.Types.Location -import Development.IDE.Types.Logger (Pretty (pretty), +import Ide.Logger (Pretty (pretty), Recorder, WithPriority, cmapWithPrio) diff --git a/plugins/hls-refactor-plugin/src/Development/IDE/Plugin/CodeAction.hs b/plugins/hls-refactor-plugin/src/Development/IDE/Plugin/CodeAction.hs index 727a959620..aef45e552b 100644 --- a/plugins/hls-refactor-plugin/src/Development/IDE/Plugin/CodeAction.hs +++ b/plugins/hls-refactor-plugin/src/Development/IDE/Plugin/CodeAction.hs @@ -64,11 +64,11 @@ import Development.IDE.Plugin.Plugins.ImportUtils import Development.IDE.Plugin.TypeLenses (suggestSignature) import Development.IDE.Types.Exports import Development.IDE.Types.Location -import Development.IDE.Types.Logger hiding - (group) import Development.IDE.Types.Options import GHC.Exts (fromList) import qualified GHC.LanguageExtensions as Lang +import Ide.Logger hiding + (group) #if MIN_VERSION_ghc(9,4,0) import GHC.Parser.Annotation (TokenLocation (..)) #endif diff --git a/plugins/hls-refine-imports-plugin/src/Ide/Plugin/RefineImports.hs b/plugins/hls-refine-imports-plugin/src/Ide/Plugin/RefineImports.hs index e7dc3e0142..1e8732c0e3 100644 --- a/plugins/hls-refine-imports-plugin/src/Ide/Plugin/RefineImports.hs +++ b/plugins/hls-refine-imports-plugin/src/Ide/Plugin/RefineImports.hs @@ -43,7 +43,7 @@ import Development.IDE.GHC.Compat tcg_exports, unLoc) -} import qualified Development.IDE.Core.Shake as Shake import Development.IDE.Graph.Classes -import qualified Development.IDE.Types.Logger as Logger +import qualified Ide.Logger as Logger import GHC.Generics (Generic) import Ide.Plugin.ExplicitImports (extractMinimalImports, within) diff --git a/plugins/hls-tactics-plugin/new/src/Wingman/LanguageServer.hs b/plugins/hls-tactics-plugin/new/src/Wingman/LanguageServer.hs index c382082ed0..044061d579 100644 --- a/plugins/hls-tactics-plugin/new/src/Wingman/LanguageServer.hs +++ b/plugins/hls-tactics-plugin/new/src/Wingman/LanguageServer.hs @@ -64,7 +64,7 @@ import Wingman.Judgements.Theta import Wingman.Range import Wingman.StaticPlugin (pattern WingmanMetaprogram, pattern MetaprogramSyntax) import Wingman.Types -import Development.IDE.Types.Logger (Recorder, cmapWithPrio, WithPriority, Pretty (pretty)) +import Ide.Logger (Recorder, cmapWithPrio, WithPriority, Pretty (pretty)) import qualified Development.IDE.Core.Shake as Shake diff --git a/plugins/hls-tactics-plugin/new/src/Wingman/Plugin.hs b/plugins/hls-tactics-plugin/new/src/Wingman/Plugin.hs index bbde652ae9..f8b62cde72 100644 --- a/plugins/hls-tactics-plugin/new/src/Wingman/Plugin.hs +++ b/plugins/hls-tactics-plugin/new/src/Wingman/Plugin.hs @@ -15,7 +15,7 @@ import Wingman.LanguageServer hiding (Log) import qualified Wingman.LanguageServer as WingmanLanguageServer import Wingman.LanguageServer.Metaprogram (hoverProvider) import Wingman.StaticPlugin -import Development.IDE.Types.Logger (Recorder, cmapWithPrio, WithPriority, Pretty (pretty)) +import Ide.Logger (Recorder, cmapWithPrio, WithPriority, Pretty (pretty)) data Log = LogWingmanLanguageServer WingmanLanguageServer.Log diff --git a/plugins/hls-tactics-plugin/old/src/Wingman/LanguageServer.hs b/plugins/hls-tactics-plugin/old/src/Wingman/LanguageServer.hs index 478bf8ecf6..fde8705d55 100644 --- a/plugins/hls-tactics-plugin/old/src/Wingman/LanguageServer.hs +++ b/plugins/hls-tactics-plugin/old/src/Wingman/LanguageServer.hs @@ -60,7 +60,7 @@ import Wingman.Judgements.Theta import Wingman.Range import Wingman.StaticPlugin (pattern WingmanMetaprogram, pattern MetaprogramSyntax) import Wingman.Types -import Development.IDE.Types.Logger (Recorder, cmapWithPrio, WithPriority, Pretty (pretty)) +import Ide.Logger (Recorder, cmapWithPrio, WithPriority, Pretty (pretty)) import qualified Development.IDE.Core.Shake as Shake diff --git a/plugins/hls-tactics-plugin/old/src/Wingman/Plugin.hs b/plugins/hls-tactics-plugin/old/src/Wingman/Plugin.hs index 5b6cc89150..c8e6c2ae4f 100644 --- a/plugins/hls-tactics-plugin/old/src/Wingman/Plugin.hs +++ b/plugins/hls-tactics-plugin/old/src/Wingman/Plugin.hs @@ -15,7 +15,7 @@ import Wingman.LanguageServer hiding (Log) import qualified Wingman.LanguageServer as WingmanLanguageServer import Wingman.LanguageServer.Metaprogram (hoverProvider) import Wingman.StaticPlugin -import Development.IDE.Types.Logger (Recorder, cmapWithPrio, WithPriority, Pretty (pretty)) +import Ide.Logger (Recorder, cmapWithPrio, WithPriority, Pretty (pretty)) data Log = LogWingmanLanguageServer WingmanLanguageServer.Log diff --git a/src/HlsPlugins.hs b/src/HlsPlugins.hs index 00bb29a630..22008d2a4a 100644 --- a/src/HlsPlugins.hs +++ b/src/HlsPlugins.hs @@ -3,7 +3,7 @@ {-# LANGUAGE OverloadedStrings #-} module HlsPlugins where -import Development.IDE.Types.Logger (Pretty (pretty), Recorder, +import Ide.Logger (Pretty (pretty), Recorder, WithPriority, cmapWithPrio) import Ide.PluginUtils (pluginDescToIdePlugins) import Ide.Types (IdePlugins, diff --git a/src/Ide/Arguments.hs b/src/Ide/Arguments.hs index d8be0d69f7..6af7551adf 100644 --- a/src/Ide/Arguments.hs +++ b/src/Ide/Arguments.hs @@ -20,8 +20,8 @@ module Ide.Arguments import Data.Version import Development.IDE (IdeState) import Development.IDE.Main (Command (..), commandP) -import Development.IDE.Types.Logger (Priority (..)) import GitHash (giHash, tGitInfoCwdTry) +import Ide.Logger (Priority (..)) import Ide.Types (IdePlugins) import Options.Applicative import Paths_haskell_language_server diff --git a/src/Ide/Main.hs b/src/Ide/Main.hs index ecfd944b71..b6ee489d7c 100644 --- a/src/Ide/Main.hs +++ b/src/Ide/Main.hs @@ -24,13 +24,13 @@ import Development.IDE.Core.Tracing (withTelemetryLogger) import Development.IDE.Main (isLSP) import qualified Development.IDE.Main as IDEMain import qualified Development.IDE.Session as Session -import Development.IDE.Types.Logger as G import qualified Development.IDE.Types.Options as Ghcide import GHC.Stack (emptyCallStack) import qualified HIE.Bios.Environment as HieBios -import qualified HIE.Bios.Types as HieBios import HIE.Bios.Types hiding (Log) +import qualified HIE.Bios.Types as HieBios import Ide.Arguments +import Ide.Logger as G import Ide.Plugin.ConfigUtils (pluginsToDefaultConfig, pluginsToVSCodeExtensionSchema) import Ide.Types (IdePlugins, PluginId (PluginId),