1414{-# LANGUAGE TemplateHaskell #-}
1515{-# LANGUAGE TypeFamilies #-}
1616{-# LANGUAGE UnicodeSyntax #-}
17- {-# LANGUAGE ViewPatterns #-}
1817
1918-- |
2019-- This module provides the core functionality of the plugin.
@@ -33,7 +32,6 @@ import Data.Data (Data (..))
3332import Data.List
3433import qualified Data.Map.Strict as M
3534import Data.Maybe
36- import Data.Semigroup (First (.. ))
3735import Data.Text (Text )
3836import qualified Data.Text as T
3937import Development.IDE (Action ,
@@ -51,6 +49,7 @@ import Development.IDE (Action,
5149 useWithStale )
5250import Development.IDE.Core.PluginUtils (runActionE , useE ,
5351 useWithStaleE )
52+ import Development.IDE.Core.PositionMapping
5453import Development.IDE.Core.Rules (toIdeResult )
5554import Development.IDE.Core.RuleTypes (DocAndTyThingMap (.. ))
5655import Development.IDE.Core.Shake (ShakeExtras (.. ),
@@ -99,16 +98,16 @@ computeSemanticTokens recorder pid _ nfp = do
9998 logWith recorder Debug (LogConfig config)
10099 semanticId <- lift getAndIncreaseSemanticTokensId
101100
102- (sortOn fst -> tokenList, First mapping) <- do
101+ tokenList <- sortOn fst <$> do
103102 rangesyntacticTypes <- lift $ useWithStale GetSyntacticTokens nfp
104103 rangesemanticTypes <- lift $ useWithStale GetSemanticTokens nfp
105- let mk w u (toks, mapping) = ( map (fmap w) $ u toks, First mapping)
104+ let mk w u (toks, mapping) = map (\ (ran, tok) -> (toCurrentRange mapping ran, w tok)) $ u toks
106105 maybeToExceptT (PluginRuleFailed " no syntactic nor semantic tokens" ) $ hoistMaybe $
107106 (mk HsSyntacticTokenType rangeSyntacticList <$> rangesyntacticTypes)
108107 <> (mk HsSemanticTokenType rangeSemanticList <$> rangesemanticTypes)
109108
110109 -- NOTE: rangeSemanticsSemanticTokens actually assumes that the tokesn are in order. that means they have to be sorted by position
111- withExceptT PluginInternalError $ liftEither $ rangeSemanticsSemanticTokens semanticId config mapping tokenList
110+ withExceptT PluginInternalError $ liftEither $ rangeSemanticsSemanticTokens semanticId config tokenList
112111
113112semanticTokensFull :: Recorder (WithPriority SemanticLog ) -> PluginMethodHandler IdeState 'Method_TextDocumentSemanticTokensFull
114113semanticTokensFull recorder state pid param = runActionE " SemanticTokens.semanticTokensFull" state computeSemanticTokensFull
@@ -166,9 +165,7 @@ getSyntacticTokensRule :: Recorder (WithPriority SemanticLog) -> Rules ()
166165getSyntacticTokensRule recorder =
167166 define (cmapWithPrio LogShake recorder) $ \ GetSyntacticTokens nfp -> handleError recorder $ do
168167 (parsedModule, _) <- withExceptT LogDependencyError $ useWithStaleE GetParsedModuleWithComments nfp
169- let tokList = computeRangeHsSyntacticTokenTypeList parsedModule
170- logWith recorder Debug $ LogSyntacticTokens tokList
171- pure tokList
168+ pure $ computeRangeHsSyntacticTokenTypeList parsedModule
172169
173170astTraversalWith :: forall b r . Data b => b -> (forall a . Data a => a -> [r ]) -> [r ]
174171astTraversalWith ast f = mconcat $ flip gmapQ ast \ y -> f y <> astTraversalWith y f
0 commit comments