From fa9c8744e25cea2f58c3b8fff6e2766d7d2bc378 Mon Sep 17 00:00:00 2001 From: Patrick Date: Mon, 11 Mar 2024 18:06:07 +0800 Subject: [PATCH 1/3] improve logging in semantic tokens rule --- .../src/Ide/Plugin/SemanticTokens/Internal.hs | 10 ++++++---- .../src/Ide/Plugin/SemanticTokens/Types.hs | 4 +++- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/plugins/hls-semantic-tokens-plugin/src/Ide/Plugin/SemanticTokens/Internal.hs b/plugins/hls-semantic-tokens-plugin/src/Ide/Plugin/SemanticTokens/Internal.hs index 1be1b523b6..aaa7da3054 100644 --- a/plugins/hls-semantic-tokens-plugin/src/Ide/Plugin/SemanticTokens/Internal.hs +++ b/plugins/hls-semantic-tokens-plugin/src/Ide/Plugin/SemanticTokens/Internal.hs @@ -16,6 +16,7 @@ import Control.Concurrent.STM (stateTVar) import Control.Concurrent.STM.Stats (atomically) import Control.Lens ((^.)) import Control.Monad.Except (ExceptT, liftEither, + mapError, withExceptT) import Control.Monad.IO.Class (MonadIO (..)) import Control.Monad.Trans (lift) @@ -34,8 +35,8 @@ import Development.IDE (Action, cmapWithPrio, define, fromNormalizedFilePath, hieKind, use_) -import Development.IDE.Core.PluginUtils (runActionE, - useWithStaleE) +import Development.IDE.Core.PluginUtils (runActionE, useE, + useMT, useWithStaleE) import Development.IDE.Core.Rules (toIdeResult) import Development.IDE.Core.RuleTypes (DocAndTyThingMap (..)) import Development.IDE.Core.Shake (ShakeExtras (..), @@ -124,8 +125,9 @@ semanticTokensFullDelta recorder state pid param = do getSemanticTokensRule :: Recorder (WithPriority SemanticLog) -> Rules () getSemanticTokensRule recorder = define (cmapWithPrio LogShake recorder) $ \GetSemanticTokens nfp -> handleError recorder $ do - (HAR {..}) <- lift $ use_ GetHieAst nfp - (DKMap {getTyThingMap}, _) <- lift $ useWithStale_ GetDocMap nfp + (HAR {..}) <- use_ GetHieAst nfp + (HAR {..}) <- withExceptT LogPluginError $ useE GetHieAst nfp + (DKMap {getTyThingMap}, _) <- withExceptT LogPluginError $ useWithStaleE GetDocMap nfp ast <- handleMaybe (LogNoAST $ show nfp) $ getAsts hieAst M.!? (HiePath . mkFastString . fromNormalizedFilePath) nfp virtualFile <- handleMaybeM LogNoVF $ getVirtualFile nfp let hsFinder = idSemantic getTyThingMap (hieKindFunMasksKind hieKind) refMap diff --git a/plugins/hls-semantic-tokens-plugin/src/Ide/Plugin/SemanticTokens/Types.hs b/plugins/hls-semantic-tokens-plugin/src/Ide/Plugin/SemanticTokens/Types.hs index d7cf2a2b50..cd22d27020 100644 --- a/plugins/hls-semantic-tokens-plugin/src/Ide/Plugin/SemanticTokens/Types.hs +++ b/plugins/hls-semantic-tokens-plugin/src/Ide/Plugin/SemanticTokens/Types.hs @@ -19,6 +19,7 @@ import GHC.Generics (Generic) import Language.LSP.Protocol.Types -- import template haskell import Data.Text (Text) +import Ide.Plugin.Error (PluginError) import Language.Haskell.TH.Syntax (Lift) @@ -137,12 +138,12 @@ data HieFunMaskKind kind where data SemanticLog = LogShake Shake.Log + | LogPluginError PluginError | LogNoAST FilePath | LogConfig SemanticTokensConfig | LogMsg String | LogNoVF | LogSemanticTokensDeltaMisMatch Text (Maybe Text) - deriving (Show) instance Pretty SemanticLog where pretty theLog = case theLog of @@ -154,6 +155,7 @@ instance Pretty SemanticLog where LogSemanticTokensDeltaMisMatch previousIdFromRequest previousIdFromCache -> "SemanticTokensDeltaMisMatch: previousIdFromRequest: " <> pretty previousIdFromRequest <> " previousIdFromCache: " <> pretty previousIdFromCache + LogPluginError err -> "SemanticTokensPluginError: " <> pretty err type SemanticTokenId = Text From ebc060658a1afc584048713e6249cf1ef71edaa2 Mon Sep 17 00:00:00 2001 From: Patrick Date: Mon, 11 Mar 2024 18:12:31 +0800 Subject: [PATCH 2/3] remove redudent import --- .../src/Ide/Plugin/SemanticTokens/Internal.hs | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/plugins/hls-semantic-tokens-plugin/src/Ide/Plugin/SemanticTokens/Internal.hs b/plugins/hls-semantic-tokens-plugin/src/Ide/Plugin/SemanticTokens/Internal.hs index aaa7da3054..d1fc1dcd14 100644 --- a/plugins/hls-semantic-tokens-plugin/src/Ide/Plugin/SemanticTokens/Internal.hs +++ b/plugins/hls-semantic-tokens-plugin/src/Ide/Plugin/SemanticTokens/Internal.hs @@ -16,7 +16,6 @@ import Control.Concurrent.STM (stateTVar) import Control.Concurrent.STM.Stats (atomically) import Control.Lens ((^.)) import Control.Monad.Except (ExceptT, liftEither, - mapError, withExceptT) import Control.Monad.IO.Class (MonadIO (..)) import Control.Monad.Trans (lift) @@ -34,15 +33,14 @@ import Development.IDE (Action, WithPriority, cmapWithPrio, define, fromNormalizedFilePath, - hieKind, use_) + hieKind) import Development.IDE.Core.PluginUtils (runActionE, useE, - useMT, useWithStaleE) + useWithStaleE) import Development.IDE.Core.Rules (toIdeResult) import Development.IDE.Core.RuleTypes (DocAndTyThingMap (..)) import Development.IDE.Core.Shake (ShakeExtras (..), getShakeExtras, - getVirtualFile, - useWithStale_) + getVirtualFile) import Development.IDE.GHC.Compat hiding (Warning) import Development.IDE.GHC.Compat.Util (mkFastString) import Ide.Logger (logWith) @@ -125,7 +123,6 @@ semanticTokensFullDelta recorder state pid param = do getSemanticTokensRule :: Recorder (WithPriority SemanticLog) -> Rules () getSemanticTokensRule recorder = define (cmapWithPrio LogShake recorder) $ \GetSemanticTokens nfp -> handleError recorder $ do - (HAR {..}) <- use_ GetHieAst nfp (HAR {..}) <- withExceptT LogPluginError $ useE GetHieAst nfp (DKMap {getTyThingMap}, _) <- withExceptT LogPluginError $ useWithStaleE GetDocMap nfp ast <- handleMaybe (LogNoAST $ show nfp) $ getAsts hieAst M.!? (HiePath . mkFastString . fromNormalizedFilePath) nfp From e686a4d5c6c256288822402862a15f7cd58ae4c3 Mon Sep 17 00:00:00 2001 From: Patrick Date: Mon, 11 Mar 2024 18:30:39 +0800 Subject: [PATCH 3/3] refine LogDependencyError --- .../src/Ide/Plugin/SemanticTokens/Internal.hs | 4 ++-- .../src/Ide/Plugin/SemanticTokens/Types.hs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/hls-semantic-tokens-plugin/src/Ide/Plugin/SemanticTokens/Internal.hs b/plugins/hls-semantic-tokens-plugin/src/Ide/Plugin/SemanticTokens/Internal.hs index d1fc1dcd14..b8b07e667f 100644 --- a/plugins/hls-semantic-tokens-plugin/src/Ide/Plugin/SemanticTokens/Internal.hs +++ b/plugins/hls-semantic-tokens-plugin/src/Ide/Plugin/SemanticTokens/Internal.hs @@ -123,8 +123,8 @@ semanticTokensFullDelta recorder state pid param = do getSemanticTokensRule :: Recorder (WithPriority SemanticLog) -> Rules () getSemanticTokensRule recorder = define (cmapWithPrio LogShake recorder) $ \GetSemanticTokens nfp -> handleError recorder $ do - (HAR {..}) <- withExceptT LogPluginError $ useE GetHieAst nfp - (DKMap {getTyThingMap}, _) <- withExceptT LogPluginError $ useWithStaleE GetDocMap nfp + (HAR {..}) <- withExceptT LogDependencyError $ useE GetHieAst nfp + (DKMap {getTyThingMap}, _) <- withExceptT LogDependencyError $ useWithStaleE GetDocMap nfp ast <- handleMaybe (LogNoAST $ show nfp) $ getAsts hieAst M.!? (HiePath . mkFastString . fromNormalizedFilePath) nfp virtualFile <- handleMaybeM LogNoVF $ getVirtualFile nfp let hsFinder = idSemantic getTyThingMap (hieKindFunMasksKind hieKind) refMap diff --git a/plugins/hls-semantic-tokens-plugin/src/Ide/Plugin/SemanticTokens/Types.hs b/plugins/hls-semantic-tokens-plugin/src/Ide/Plugin/SemanticTokens/Types.hs index cd22d27020..cda4fda6e6 100644 --- a/plugins/hls-semantic-tokens-plugin/src/Ide/Plugin/SemanticTokens/Types.hs +++ b/plugins/hls-semantic-tokens-plugin/src/Ide/Plugin/SemanticTokens/Types.hs @@ -138,7 +138,7 @@ data HieFunMaskKind kind where data SemanticLog = LogShake Shake.Log - | LogPluginError PluginError + | LogDependencyError PluginError | LogNoAST FilePath | LogConfig SemanticTokensConfig | LogMsg String @@ -155,7 +155,7 @@ instance Pretty SemanticLog where LogSemanticTokensDeltaMisMatch previousIdFromRequest previousIdFromCache -> "SemanticTokensDeltaMisMatch: previousIdFromRequest: " <> pretty previousIdFromRequest <> " previousIdFromCache: " <> pretty previousIdFromCache - LogPluginError err -> "SemanticTokensPluginError: " <> pretty err + LogDependencyError err -> "SemanticTokens' dependency error: " <> pretty err type SemanticTokenId = Text