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 (.. ),
@@ -99,16 +98,16 @@ computeSemanticTokens recorder pid _ nfp = do
99
98
logWith recorder Debug (LogConfig config)
100
99
semanticId <- lift getAndIncreaseSemanticTokensId
101
100
102
- (sortOn fst -> tokenList, First mapping) <- do
101
+ tokenList <- sortOn fst <$> do
103
102
rangesyntacticTypes <- lift $ useWithStale GetSyntacticTokens nfp
104
103
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
106
105
maybeToExceptT (PluginRuleFailed " no syntactic nor semantic tokens" ) $ hoistMaybe $
107
106
(mk HsSyntacticTokenType rangeSyntacticList <$> rangesyntacticTypes)
108
107
<> (mk HsSemanticTokenType rangeSemanticList <$> rangesemanticTypes)
109
108
110
109
-- 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
112
111
113
112
semanticTokensFull :: Recorder (WithPriority SemanticLog ) -> PluginMethodHandler IdeState 'Method_TextDocumentSemanticTokensFull
114
113
semanticTokensFull recorder state pid param = runActionE " SemanticTokens.semanticTokensFull" state computeSemanticTokensFull
@@ -166,9 +165,7 @@ getSyntacticTokensRule :: Recorder (WithPriority SemanticLog) -> Rules ()
166
165
getSyntacticTokensRule recorder =
167
166
define (cmapWithPrio LogShake recorder) $ \ GetSyntacticTokens nfp -> handleError recorder $ do
168
167
(parsedModule, _) <- withExceptT LogDependencyError $ useWithStaleE GetParsedModuleWithComments nfp
169
- let tokList = computeRangeHsSyntacticTokenTypeList parsedModule
170
- logWith recorder Debug $ LogSyntacticTokens tokList
171
- pure tokList
168
+ pure $ computeRangeHsSyntacticTokenTypeList parsedModule
172
169
173
170
astTraversalWith :: forall b r . Data b => b -> (forall a . Data a => a -> [r ]) -> [r ]
174
171
astTraversalWith ast f = mconcat $ flip gmapQ ast \ y -> f y <> astTraversalWith y f
0 commit comments