Skip to content

Commit

Permalink
improve logging in semantic tokens rule (#4135)
Browse files Browse the repository at this point in the history
* improve logging in semantic tokens rule
  • Loading branch information
soulomoon authored Mar 11, 2024
1 parent 16912cc commit bd7c9ba
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,14 @@ import Development.IDE (Action,
WithPriority,
cmapWithPrio, define,
fromNormalizedFilePath,
hieKind, use_)
import Development.IDE.Core.PluginUtils (runActionE,
hieKind)
import Development.IDE.Core.PluginUtils (runActionE, useE,
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)
Expand Down Expand Up @@ -124,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 {..}) <- lift $ use_ GetHieAst nfp
(DKMap {getTyThingMap}, _) <- lift $ useWithStale_ 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down Expand Up @@ -137,12 +138,12 @@ data HieFunMaskKind kind where

data SemanticLog
= LogShake Shake.Log
| LogDependencyError PluginError
| LogNoAST FilePath
| LogConfig SemanticTokensConfig
| LogMsg String
| LogNoVF
| LogSemanticTokensDeltaMisMatch Text (Maybe Text)
deriving (Show)

instance Pretty SemanticLog where
pretty theLog = case theLog of
Expand All @@ -154,6 +155,7 @@ instance Pretty SemanticLog where
LogSemanticTokensDeltaMisMatch previousIdFromRequest previousIdFromCache
-> "SemanticTokensDeltaMisMatch: previousIdFromRequest: " <> pretty previousIdFromRequest
<> " previousIdFromCache: " <> pretty previousIdFromCache
LogDependencyError err -> "SemanticTokens' dependency error: " <> pretty err


type SemanticTokenId = Text

0 comments on commit bd7c9ba

Please sign in to comment.