14
14
{-# LANGUAGE TemplateHaskell #-}
15
15
{-# LANGUAGE TypeFamilies #-}
16
16
{-# LANGUAGE UnicodeSyntax #-}
17
- {-# LANGUAGE ViewPatterns #-}
18
17
19
18
-- |
20
19
-- This module provides the core functionality of the plugin.
@@ -33,7 +32,6 @@ import Data.Data (Data (..))
33
32
import Data.List
34
33
import qualified Data.Map.Strict as M
35
34
import Data.Maybe
36
- import Data.Semigroup (First (.. ))
37
35
import Data.Text (Text )
38
36
import qualified Data.Text as T
39
37
import Development.IDE (Action ,
@@ -51,6 +49,7 @@ import Development.IDE (Action,
51
49
useWithStale )
52
50
import Development.IDE.Core.PluginUtils (runActionE , useE ,
53
51
useWithStaleE )
52
+ import Development.IDE.Core.PositionMapping
54
53
import Development.IDE.Core.Rules (toIdeResult )
55
54
import Development.IDE.Core.RuleTypes (DocAndTyThingMap (.. ))
56
55
import Development.IDE.Core.Shake (ShakeExtras (.. ),
@@ -101,16 +100,16 @@ computeSemanticTokens recorder pid _ nfp = do
101
100
logWith recorder Debug (LogConfig config)
102
101
semanticId <- lift getAndIncreaseSemanticTokensId
103
102
104
- (sortOn fst -> tokenList, First mapping) <- do
103
+ tokenList <- sortOn fst <$> do
105
104
rangesyntacticTypes <- lift $ useWithStale GetSyntacticTokens nfp
106
105
rangesemanticTypes <- lift $ useWithStale GetSemanticTokens nfp
107
- let mk w u (toks, mapping) = ( map (fmap w) $ u toks, First mapping)
106
+ let mk w u (toks, mapping) = map (\ (ran, tok) -> (toCurrentRange mapping ran, w tok)) $ u toks
108
107
maybeToExceptT (PluginRuleFailed " no syntactic nor semantic tokens" ) $ hoistMaybe $
109
108
(mk HsSyntacticTokenType rangeSyntacticList <$> rangesyntacticTypes)
110
109
<> (mk HsSemanticTokenType rangeSemanticList <$> rangesemanticTypes)
111
110
112
111
-- NOTE: rangeSemanticsSemanticTokens actually assumes that the tokesn are in order. that means they have to be sorted by position
113
- withExceptT PluginInternalError $ liftEither $ rangeSemanticsSemanticTokens semanticId config mapping tokenList
112
+ withExceptT PluginInternalError $ liftEither $ rangeSemanticsSemanticTokens semanticId config tokenList
114
113
115
114
semanticTokensFull :: Recorder (WithPriority SemanticLog ) -> PluginMethodHandler IdeState 'Method_TextDocumentSemanticTokensFull
116
115
semanticTokensFull recorder state pid param = runActionE " SemanticTokens.semanticTokensFull" state computeSemanticTokensFull
@@ -168,9 +167,7 @@ getSyntacticTokensRule :: Recorder (WithPriority SemanticLog) -> Rules ()
168
167
getSyntacticTokensRule recorder =
169
168
define (cmapWithPrio LogShake recorder) $ \ GetSyntacticTokens nfp -> handleError recorder $ do
170
169
(parsedModule, _) <- withExceptT LogDependencyError $ useWithStaleE GetParsedModuleWithComments nfp
171
- let tokList = computeRangeHsSyntacticTokenTypeList parsedModule
172
- logWith recorder Debug $ LogSyntacticTokens tokList
173
- pure tokList
170
+ pure $ computeRangeHsSyntacticTokenTypeList parsedModule
174
171
175
172
astTraversalWith :: forall b r . Data b => b -> (forall a . Data a => a -> [r ]) -> [r ]
176
173
astTraversalWith ast f = mconcat $ flip gmapQ ast \ y -> f y <> astTraversalWith y f
0 commit comments