From fb5317b1bc655f938da72e95a7bd92cfda75c9bf Mon Sep 17 00:00:00 2001 From: Patrick Date: Thu, 1 Feb 2024 01:06:57 +0800 Subject: [PATCH 1/6] add infix operator --- .../src/Ide/Plugin/SemanticTokens/Mappings.hs | 13 ++++++++++++- .../src/Ide/Plugin/SemanticTokens/Query.hs | 2 +- .../src/Ide/Plugin/SemanticTokens/SemanticConfig.hs | 1 + .../src/Ide/Plugin/SemanticTokens/Types.hs | 3 +++ plugins/hls-semantic-tokens-plugin/test/Main.hs | 3 ++- .../test/testdata/T1.expected | 4 ++-- .../test/testdata/TOperator.expected | 12 ++++++++++++ .../test/testdata/TOperator.hs | 9 +++++++++ 8 files changed, 42 insertions(+), 5 deletions(-) create mode 100644 plugins/hls-semantic-tokens-plugin/test/testdata/TOperator.expected create mode 100644 plugins/hls-semantic-tokens-plugin/test/testdata/TOperator.hs diff --git a/plugins/hls-semantic-tokens-plugin/src/Ide/Plugin/SemanticTokens/Mappings.hs b/plugins/hls-semantic-tokens-plugin/src/Ide/Plugin/SemanticTokens/Mappings.hs index 1003708b41..25c31e6e04 100644 --- a/plugins/hls-semantic-tokens-plugin/src/Ide/Plugin/SemanticTokens/Mappings.hs +++ b/plugins/hls-semantic-tokens-plugin/src/Ide/Plugin/SemanticTokens/Mappings.hs @@ -29,6 +29,16 @@ import Language.LSP.Protocol.Types (LspEnum (knownValues), UInt, absolutizeTokens) import Language.LSP.VFS hiding (line) +-- * 0. Mapping name to Hs semantic token type. + +idInfixOperator :: Identifier -> Maybe HsSemanticTokenType +idInfixOperator (Right name) = nameInfixOperator name +idInfixOperator _ = Nothing + +nameInfixOperator :: Name -> Maybe HsSemanticTokenType +nameInfixOperator name | isSymOcc (nameOccName name) = Just TOperator +nameInfixOperator _ = Nothing + -- * 1. Mapping semantic token type to and from the LSP default token type. -- | map from haskell semantic token type to LSP default token type @@ -46,6 +56,7 @@ toLspTokenType conf tk = case tk of TRecordField -> stRecordField conf TPatternSynonym -> stPatternSynonym conf TModule -> stModule conf + TOperator -> stOperator conf lspTokenReverseMap :: SemanticTokensConfig -> Map.Map SemanticTokenTypes HsSemanticTokenType lspTokenReverseMap config @@ -66,7 +77,7 @@ tyThingSemantic ty = case ty of | isTyVar vid -> Just TTypeVariable | isRecordSelector vid -> Just TRecordField | isClassOpId vid -> Just TClassMethod - | isFunVar vid -> Just TFunction + | isFunVar vid -> Just TFunction <> (nameInfixOperator $ getName vid) | otherwise -> Just TVariable AConLike con -> case con of RealDataCon _ -> Just TDataConstructor diff --git a/plugins/hls-semantic-tokens-plugin/src/Ide/Plugin/SemanticTokens/Query.hs b/plugins/hls-semantic-tokens-plugin/src/Ide/Plugin/SemanticTokens/Query.hs index 847da4e61f..a238fc0369 100644 --- a/plugins/hls-semantic-tokens-plugin/src/Ide/Plugin/SemanticTokens/Query.hs +++ b/plugins/hls-semantic-tokens-plugin/src/Ide/Plugin/SemanticTokens/Query.hs @@ -50,7 +50,7 @@ idIdSemanticFromHie hieKind rm ns = do spanInfos <- M.lookup name' rm' let typeTokenType = foldMap (typeSemantic hieKind) $ listToMaybe $ mapMaybe (identType . snd) spanInfos contextInfoTokenType <- foldMap (contextInfosMaybeTokenType . identInfo . snd) spanInfos - fold [typeTokenType, Just contextInfoTokenType] + fold [typeTokenType, Just contextInfoTokenType, idInfixOperator ns] contextInfosMaybeTokenType :: Set.Set ContextInfo -> Maybe HsSemanticTokenType contextInfosMaybeTokenType details = foldMap infoTokenType (Set.toList details) diff --git a/plugins/hls-semantic-tokens-plugin/src/Ide/Plugin/SemanticTokens/SemanticConfig.hs b/plugins/hls-semantic-tokens-plugin/src/Ide/Plugin/SemanticTokens/SemanticConfig.hs index b3d8aeb7ad..dccebae5d2 100644 --- a/plugins/hls-semantic-tokens-plugin/src/Ide/Plugin/SemanticTokens/SemanticConfig.hs +++ b/plugins/hls-semantic-tokens-plugin/src/Ide/Plugin/SemanticTokens/SemanticConfig.hs @@ -42,6 +42,7 @@ docName tt = case tt of TTypeFamily -> "type families" TRecordField -> "record fields" TModule -> "modules" + TOperator -> "operators" toConfigName :: String -> String toConfigName = ("st" <>) 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 214069b1ed..0600ff6194 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 @@ -36,6 +36,7 @@ import Language.Haskell.TH.Syntax (Lift) data HsSemanticTokenType = TVariable -- none function variable | TFunction -- function + | TOperator-- operator | TDataConstructor -- Data constructor | TTypeVariable -- Type variable | TClassMethod -- Class method @@ -69,6 +70,7 @@ instance Default SemanticTokensConfig where , stTypeFamily = SemanticTokenTypes_Interface , stRecordField = SemanticTokenTypes_Property , stModule = SemanticTokenTypes_Namespace + , stOperator = SemanticTokenTypes_Operator } -- | SemanticTokensConfig_ is a configuration for the semantic tokens plugin. -- it contains map between the hs semantic token type and default token type. @@ -85,6 +87,7 @@ data SemanticTokensConfig = STC , stTypeFamily :: !SemanticTokenTypes , stRecordField :: !SemanticTokenTypes , stModule :: !SemanticTokenTypes + , stOperator :: !SemanticTokenTypes } deriving (Generic, Show) diff --git a/plugins/hls-semantic-tokens-plugin/test/Main.hs b/plugins/hls-semantic-tokens-plugin/test/Main.hs index 25744672b2..7e6e8bfd65 100644 --- a/plugins/hls-semantic-tokens-plugin/test/Main.hs +++ b/plugins/hls-semantic-tokens-plugin/test/Main.hs @@ -224,7 +224,8 @@ semanticTokensFunctionTests = goldenWithSemanticTokensWithDefaultConfig "local functions" "TFunctionLocal", goldenWithSemanticTokensWithDefaultConfig "functions under type synonym" "TFunctionUnderTypeSynonym", goldenWithSemanticTokensWithDefaultConfig "function in let binding" "TFunctionLet", - goldenWithSemanticTokensWithDefaultConfig "negative case non-function with constraint" "TNoneFunctionWithConstraint" + goldenWithSemanticTokensWithDefaultConfig "negative case non-function with constraint" "TNoneFunctionWithConstraint", + goldenWithSemanticTokensWithDefaultConfig "TOperator" "TOperator" ] main :: IO () diff --git a/plugins/hls-semantic-tokens-plugin/test/testdata/T1.expected b/plugins/hls-semantic-tokens-plugin/test/testdata/T1.expected index 5377bb2728..ca60c0f0f3 100644 --- a/plugins/hls-semantic-tokens-plugin/test/testdata/T1.expected +++ b/plugins/hls-semantic-tokens-plugin/test/testdata/T1.expected @@ -63,11 +63,11 @@ 36:11-13 TVariable "vv" 37:10-12 TVariable "gg" 38:14-17 TRecordField "foo" -38:18-19 TFunction "$" +38:18-19 TOperator "$" 38:20-21 TVariable "f" 38:24-27 TRecordField "foo" 39:14-17 TRecordField "foo" -39:18-19 TFunction "$" +39:18-19 TOperator "$" 39:20-21 TVariable "f" 39:24-27 TRecordField "foo" 41:1-3 TFunction "go" diff --git a/plugins/hls-semantic-tokens-plugin/test/testdata/TOperator.expected b/plugins/hls-semantic-tokens-plugin/test/testdata/TOperator.expected new file mode 100644 index 0000000000..8b8e316a50 --- /dev/null +++ b/plugins/hls-semantic-tokens-plugin/test/testdata/TOperator.expected @@ -0,0 +1,12 @@ +4:1-3 TFunction "go" +4:4-5 TFunction "f" +4:6-7 TVariable "x" +4:10-11 TFunction "f" +4:12-13 TOperator "$" +4:14-15 TVariable "x" +6:2-6 TOperator "$$$$" +6:10-11 TFunction "b" +7:1-2 TVariable "x" +7:7-11 TOperator "$$$$" +9:1-2 TFunction "b" +9:7-8 TClassMethod "+" diff --git a/plugins/hls-semantic-tokens-plugin/test/testdata/TOperator.hs b/plugins/hls-semantic-tokens-plugin/test/testdata/TOperator.hs new file mode 100644 index 0000000000..6c66964de8 --- /dev/null +++ b/plugins/hls-semantic-tokens-plugin/test/testdata/TOperator.hs @@ -0,0 +1,9 @@ +module TOperator where + +-- imported operator +go f x = f $ x +-- operator defined in local module +($$$$) = b +x = 1 $$$$ 2 +-- class method take precedence over operator +b = 1 + 1 From 69086532dde1fdad28e4e081217d79cab3078bca Mon Sep 17 00:00:00 2001 From: Patrick Date: Thu, 1 Feb 2024 01:20:29 +0800 Subject: [PATCH 2/6] add test --- .../test/testdata/TOperator.expected | 21 ++++++++++++++++--- .../test/testdata/TOperator.hs | 5 ++++- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/plugins/hls-semantic-tokens-plugin/test/testdata/TOperator.expected b/plugins/hls-semantic-tokens-plugin/test/testdata/TOperator.expected index 8b8e316a50..4e518b4f21 100644 --- a/plugins/hls-semantic-tokens-plugin/test/testdata/TOperator.expected +++ b/plugins/hls-semantic-tokens-plugin/test/testdata/TOperator.expected @@ -5,8 +5,23 @@ 4:12-13 TOperator "$" 4:14-15 TVariable "x" 6:2-6 TOperator "$$$$" -6:10-11 TFunction "b" 7:1-2 TVariable "x" 7:7-11 TOperator "$$$$" -9:1-2 TFunction "b" -9:7-8 TClassMethod "+" +8:6-7 TTypeVariable "a" +8:8-11 TTypeConstructor ":+:" +8:12-13 TTypeVariable "b" +8:16-19 TDataConstructor "Add" +8:20-21 TTypeVariable "a" +8:22-23 TTypeVariable "b" +10:1-4 TFunction "add" +10:8-11 TTypeConstructor "Int" +10:12-15 TTypeConstructor ":+:" +10:16-19 TTypeConstructor "Int" +10:23-26 TTypeConstructor "Int" +12:1-4 TFunction "add" +12:6-9 TDataConstructor "Add" +12:10-11 TVariable "x" +12:12-13 TVariable "y" +12:17-18 TVariable "x" +12:19-20 TClassMethod "+" +12:21-22 TVariable "y" diff --git a/plugins/hls-semantic-tokens-plugin/test/testdata/TOperator.hs b/plugins/hls-semantic-tokens-plugin/test/testdata/TOperator.hs index 6c66964de8..00e581fb7a 100644 --- a/plugins/hls-semantic-tokens-plugin/test/testdata/TOperator.hs +++ b/plugins/hls-semantic-tokens-plugin/test/testdata/TOperator.hs @@ -5,5 +5,8 @@ go f x = f $ x -- operator defined in local module ($$$$) = b x = 1 $$$$ 2 +data a :+: b = Add a b +-- type take precedence over operator +add :: Int :+: Int -> Int -- class method take precedence over operator -b = 1 + 1 +add (Add x y) = x + y From 39b8d8a37b4793d71dd8d6d53e6e84504e3d839e Mon Sep 17 00:00:00 2001 From: Patrick Date: Thu, 1 Feb 2024 22:04:25 +0800 Subject: [PATCH 3/6] mark all infix operator to have operator semantic type --- .../src/Ide/Plugin/SemanticTokens/Mappings.hs | 8 +++-- .../src/Ide/Plugin/SemanticTokens/Types.hs | 4 +-- .../test/testdata/TOperator.expected | 34 +++++++++++-------- .../test/testdata/TOperator.hs | 5 +-- 4 files changed, 30 insertions(+), 21 deletions(-) diff --git a/plugins/hls-semantic-tokens-plugin/src/Ide/Plugin/SemanticTokens/Mappings.hs b/plugins/hls-semantic-tokens-plugin/src/Ide/Plugin/SemanticTokens/Mappings.hs index 25c31e6e04..56452b7c94 100644 --- a/plugins/hls-semantic-tokens-plugin/src/Ide/Plugin/SemanticTokens/Mappings.hs +++ b/plugins/hls-semantic-tokens-plugin/src/Ide/Plugin/SemanticTokens/Mappings.hs @@ -1,6 +1,7 @@ {-# LANGUAGE GADTs #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE TypeFamilies #-} +{-# LANGUAGE TypeOperators #-} -- | -- This module provides mappings to convert token type information in the Haskell IDE plugin. It includes functions for: @@ -72,12 +73,15 @@ lspTokenTypeHsTokenType cf tk = Map.lookup tk (lspTokenReverseMap cf) -- | tyThingSemantic tyThingSemantic :: TyThing -> Maybe HsSemanticTokenType -tyThingSemantic ty = case ty of +tyThingSemantic ty | (Just hst) <- tyThingSemantic' ty = Just hst <> nameInfixOperator (getName ty) +tyThingSemantic _ = Nothing +tyThingSemantic' :: TyThing -> Maybe HsSemanticTokenType +tyThingSemantic' ty = case ty of AnId vid | isTyVar vid -> Just TTypeVariable | isRecordSelector vid -> Just TRecordField | isClassOpId vid -> Just TClassMethod - | isFunVar vid -> Just TFunction <> (nameInfixOperator $ getName vid) + | isFunVar vid -> Just TFunction | otherwise -> Just TVariable AConLike con -> case con of RealDataCon _ -> Just TDataConstructor 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 0600ff6194..b9752c37a0 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 @@ -36,7 +36,6 @@ import Language.Haskell.TH.Syntax (Lift) data HsSemanticTokenType = TVariable -- none function variable | TFunction -- function - | TOperator-- operator | TDataConstructor -- Data constructor | TTypeVariable -- Type variable | TClassMethod -- Class method @@ -46,11 +45,10 @@ data HsSemanticTokenType | TTypeSynonym -- Type synonym | TTypeFamily -- type family | TRecordField -- from match bind + | TOperator-- operator | TModule -- module name deriving (Eq, Ord, Show, Enum, Bounded, Generic, Lift) - - -- type SemanticTokensConfig = SemanticTokensConfig_ Identity instance Default SemanticTokensConfig where def = STC diff --git a/plugins/hls-semantic-tokens-plugin/test/testdata/TOperator.expected b/plugins/hls-semantic-tokens-plugin/test/testdata/TOperator.expected index 4e518b4f21..5ff519bf09 100644 --- a/plugins/hls-semantic-tokens-plugin/test/testdata/TOperator.expected +++ b/plugins/hls-semantic-tokens-plugin/test/testdata/TOperator.expected @@ -2,26 +2,32 @@ 4:4-5 TFunction "f" 4:6-7 TVariable "x" 4:10-11 TFunction "f" -4:12-13 TOperator "$" +4:12-13 TFunction "$" 4:14-15 TVariable "x" 6:2-6 TOperator "$$$$" 7:1-2 TVariable "x" 7:7-11 TOperator "$$$$" 8:6-7 TTypeVariable "a" -8:8-11 TTypeConstructor ":+:" +8:8-11 TOperator ":+:" 8:12-13 TTypeVariable "b" 8:16-19 TDataConstructor "Add" 8:20-21 TTypeVariable "a" 8:22-23 TTypeVariable "b" -10:1-4 TFunction "add" -10:8-11 TTypeConstructor "Int" -10:12-15 TTypeConstructor ":+:" -10:16-19 TTypeConstructor "Int" -10:23-26 TTypeConstructor "Int" -12:1-4 TFunction "add" -12:6-9 TDataConstructor "Add" -12:10-11 TVariable "x" -12:12-13 TVariable "y" -12:17-18 TVariable "x" -12:19-20 TClassMethod "+" -12:21-22 TVariable "y" +9:7-10 TOperator ":-:" +9:12-13 TTypeVariable "a" +9:14-15 TTypeVariable "b" +9:19-20 TTypeVariable "a" +9:22-23 TTypeVariable "b" +11:1-4 TFunction "add" +11:8-11 TTypeConstructor "Int" +11:12-15 TOperator ":+:" +11:16-19 TTypeConstructor "Int" +11:23-26 TTypeConstructor "Int" +11:27-30 TOperator ":-:" +11:31-34 TTypeConstructor "Int" +13:1-4 TFunction "add" +13:6-9 TDataConstructor "Add" +13:10-11 TVariable "x" +13:12-13 TVariable "y" +13:18-19 TVariable "x" +13:21-22 TVariable "y" diff --git a/plugins/hls-semantic-tokens-plugin/test/testdata/TOperator.hs b/plugins/hls-semantic-tokens-plugin/test/testdata/TOperator.hs index 00e581fb7a..d9f472e62d 100644 --- a/plugins/hls-semantic-tokens-plugin/test/testdata/TOperator.hs +++ b/plugins/hls-semantic-tokens-plugin/test/testdata/TOperator.hs @@ -6,7 +6,8 @@ go f x = f $ x ($$$$) = b x = 1 $$$$ 2 data a :+: b = Add a b +type (:-:) a b = (a, b) -- type take precedence over operator -add :: Int :+: Int -> Int +add :: Int :+: Int -> Int :-: Int -- class method take precedence over operator -add (Add x y) = x + y +add (Add x y) = (x, y) From 213896ad4491e9fddcb8319cbdf24b78562f1868 Mon Sep 17 00:00:00 2001 From: Patrick Date: Fri, 2 Feb 2024 22:53:58 +0800 Subject: [PATCH 4/6] update scheme --- .../schema/ghc92/default-config.golden.json | 1 + .../ghc92/vscode-extension-schema.golden.json | 56 +++++++++++++++++++ .../schema/ghc94/default-config.golden.json | 1 + .../ghc94/vscode-extension-schema.golden.json | 56 +++++++++++++++++++ .../schema/ghc96/default-config.golden.json | 1 + .../ghc96/vscode-extension-schema.golden.json | 56 +++++++++++++++++++ .../schema/ghc98/default-config.golden.json | 1 + .../ghc98/vscode-extension-schema.golden.json | 56 +++++++++++++++++++ 8 files changed, 228 insertions(+) diff --git a/test/testdata/schema/ghc92/default-config.golden.json b/test/testdata/schema/ghc92/default-config.golden.json index 78ee03b5d2..5ffe094772 100644 --- a/test/testdata/schema/ghc92/default-config.golden.json +++ b/test/testdata/schema/ghc92/default-config.golden.json @@ -123,6 +123,7 @@ "dataConstructorToken": "enumMember", "functionToken": "function", "moduleToken": "namespace", + "operatorToken": "operator", "patternSynonymToken": "macro", "recordFieldToken": "property", "typeConstructorToken": "enum", diff --git a/test/testdata/schema/ghc92/vscode-extension-schema.golden.json b/test/testdata/schema/ghc92/vscode-extension-schema.golden.json index fcff330b84..f5c4680d5e 100644 --- a/test/testdata/schema/ghc92/vscode-extension-schema.golden.json +++ b/test/testdata/schema/ghc92/vscode-extension-schema.golden.json @@ -541,6 +541,62 @@ "scope": "resource", "type": "string" }, + "haskell.plugin.semanticTokens.config.operatorToken": { + "default": "operator", + "description": "LSP semantic token type to use for operators", + "enum": [ + "namespace", + "type", + "class", + "enum", + "interface", + "struct", + "typeParameter", + "parameter", + "variable", + "property", + "enumMember", + "event", + "function", + "method", + "macro", + "keyword", + "modifier", + "comment", + "string", + "number", + "regexp", + "operator", + "decorator" + ], + "enumDescriptions": [ + "LSP Semantic Token Type: namespace", + "LSP Semantic Token Type: type", + "LSP Semantic Token Type: class", + "LSP Semantic Token Type: enum", + "LSP Semantic Token Type: interface", + "LSP Semantic Token Type: struct", + "LSP Semantic Token Type: typeParameter", + "LSP Semantic Token Type: parameter", + "LSP Semantic Token Type: variable", + "LSP Semantic Token Type: property", + "LSP Semantic Token Type: enumMember", + "LSP Semantic Token Type: event", + "LSP Semantic Token Type: function", + "LSP Semantic Token Type: method", + "LSP Semantic Token Type: macro", + "LSP Semantic Token Type: keyword", + "LSP Semantic Token Type: modifier", + "LSP Semantic Token Type: comment", + "LSP Semantic Token Type: string", + "LSP Semantic Token Type: number", + "LSP Semantic Token Type: regexp", + "LSP Semantic Token Type: operator", + "LSP Semantic Token Type: decorator" + ], + "scope": "resource", + "type": "string" + }, "haskell.plugin.semanticTokens.config.patternSynonymToken": { "default": "macro", "description": "LSP semantic token type to use for pattern synonyms", diff --git a/test/testdata/schema/ghc94/default-config.golden.json b/test/testdata/schema/ghc94/default-config.golden.json index 6bd1d4a642..a214839857 100644 --- a/test/testdata/schema/ghc94/default-config.golden.json +++ b/test/testdata/schema/ghc94/default-config.golden.json @@ -123,6 +123,7 @@ "dataConstructorToken": "enumMember", "functionToken": "function", "moduleToken": "namespace", + "operatorToken": "operator", "patternSynonymToken": "macro", "recordFieldToken": "property", "typeConstructorToken": "enum", diff --git a/test/testdata/schema/ghc94/vscode-extension-schema.golden.json b/test/testdata/schema/ghc94/vscode-extension-schema.golden.json index 73ed5b0855..9bf9808fa6 100644 --- a/test/testdata/schema/ghc94/vscode-extension-schema.golden.json +++ b/test/testdata/schema/ghc94/vscode-extension-schema.golden.json @@ -541,6 +541,62 @@ "scope": "resource", "type": "string" }, + "haskell.plugin.semanticTokens.config.operatorToken": { + "default": "operator", + "description": "LSP semantic token type to use for operators", + "enum": [ + "namespace", + "type", + "class", + "enum", + "interface", + "struct", + "typeParameter", + "parameter", + "variable", + "property", + "enumMember", + "event", + "function", + "method", + "macro", + "keyword", + "modifier", + "comment", + "string", + "number", + "regexp", + "operator", + "decorator" + ], + "enumDescriptions": [ + "LSP Semantic Token Type: namespace", + "LSP Semantic Token Type: type", + "LSP Semantic Token Type: class", + "LSP Semantic Token Type: enum", + "LSP Semantic Token Type: interface", + "LSP Semantic Token Type: struct", + "LSP Semantic Token Type: typeParameter", + "LSP Semantic Token Type: parameter", + "LSP Semantic Token Type: variable", + "LSP Semantic Token Type: property", + "LSP Semantic Token Type: enumMember", + "LSP Semantic Token Type: event", + "LSP Semantic Token Type: function", + "LSP Semantic Token Type: method", + "LSP Semantic Token Type: macro", + "LSP Semantic Token Type: keyword", + "LSP Semantic Token Type: modifier", + "LSP Semantic Token Type: comment", + "LSP Semantic Token Type: string", + "LSP Semantic Token Type: number", + "LSP Semantic Token Type: regexp", + "LSP Semantic Token Type: operator", + "LSP Semantic Token Type: decorator" + ], + "scope": "resource", + "type": "string" + }, "haskell.plugin.semanticTokens.config.patternSynonymToken": { "default": "macro", "description": "LSP semantic token type to use for pattern synonyms", diff --git a/test/testdata/schema/ghc96/default-config.golden.json b/test/testdata/schema/ghc96/default-config.golden.json index 6bd1d4a642..a214839857 100644 --- a/test/testdata/schema/ghc96/default-config.golden.json +++ b/test/testdata/schema/ghc96/default-config.golden.json @@ -123,6 +123,7 @@ "dataConstructorToken": "enumMember", "functionToken": "function", "moduleToken": "namespace", + "operatorToken": "operator", "patternSynonymToken": "macro", "recordFieldToken": "property", "typeConstructorToken": "enum", diff --git a/test/testdata/schema/ghc96/vscode-extension-schema.golden.json b/test/testdata/schema/ghc96/vscode-extension-schema.golden.json index 73ed5b0855..9bf9808fa6 100644 --- a/test/testdata/schema/ghc96/vscode-extension-schema.golden.json +++ b/test/testdata/schema/ghc96/vscode-extension-schema.golden.json @@ -541,6 +541,62 @@ "scope": "resource", "type": "string" }, + "haskell.plugin.semanticTokens.config.operatorToken": { + "default": "operator", + "description": "LSP semantic token type to use for operators", + "enum": [ + "namespace", + "type", + "class", + "enum", + "interface", + "struct", + "typeParameter", + "parameter", + "variable", + "property", + "enumMember", + "event", + "function", + "method", + "macro", + "keyword", + "modifier", + "comment", + "string", + "number", + "regexp", + "operator", + "decorator" + ], + "enumDescriptions": [ + "LSP Semantic Token Type: namespace", + "LSP Semantic Token Type: type", + "LSP Semantic Token Type: class", + "LSP Semantic Token Type: enum", + "LSP Semantic Token Type: interface", + "LSP Semantic Token Type: struct", + "LSP Semantic Token Type: typeParameter", + "LSP Semantic Token Type: parameter", + "LSP Semantic Token Type: variable", + "LSP Semantic Token Type: property", + "LSP Semantic Token Type: enumMember", + "LSP Semantic Token Type: event", + "LSP Semantic Token Type: function", + "LSP Semantic Token Type: method", + "LSP Semantic Token Type: macro", + "LSP Semantic Token Type: keyword", + "LSP Semantic Token Type: modifier", + "LSP Semantic Token Type: comment", + "LSP Semantic Token Type: string", + "LSP Semantic Token Type: number", + "LSP Semantic Token Type: regexp", + "LSP Semantic Token Type: operator", + "LSP Semantic Token Type: decorator" + ], + "scope": "resource", + "type": "string" + }, "haskell.plugin.semanticTokens.config.patternSynonymToken": { "default": "macro", "description": "LSP semantic token type to use for pattern synonyms", diff --git a/test/testdata/schema/ghc98/default-config.golden.json b/test/testdata/schema/ghc98/default-config.golden.json index 3a1db12be3..86c99b6b9d 100644 --- a/test/testdata/schema/ghc98/default-config.golden.json +++ b/test/testdata/schema/ghc98/default-config.golden.json @@ -116,6 +116,7 @@ "dataConstructorToken": "enumMember", "functionToken": "function", "moduleToken": "namespace", + "operatorToken": "operator", "patternSynonymToken": "macro", "recordFieldToken": "property", "typeConstructorToken": "enum", diff --git a/test/testdata/schema/ghc98/vscode-extension-schema.golden.json b/test/testdata/schema/ghc98/vscode-extension-schema.golden.json index d79f94383b..d7e33d9e7d 100644 --- a/test/testdata/schema/ghc98/vscode-extension-schema.golden.json +++ b/test/testdata/schema/ghc98/vscode-extension-schema.golden.json @@ -523,6 +523,62 @@ "scope": "resource", "type": "string" }, + "haskell.plugin.semanticTokens.config.operatorToken": { + "default": "operator", + "description": "LSP semantic token type to use for operators", + "enum": [ + "namespace", + "type", + "class", + "enum", + "interface", + "struct", + "typeParameter", + "parameter", + "variable", + "property", + "enumMember", + "event", + "function", + "method", + "macro", + "keyword", + "modifier", + "comment", + "string", + "number", + "regexp", + "operator", + "decorator" + ], + "enumDescriptions": [ + "LSP Semantic Token Type: namespace", + "LSP Semantic Token Type: type", + "LSP Semantic Token Type: class", + "LSP Semantic Token Type: enum", + "LSP Semantic Token Type: interface", + "LSP Semantic Token Type: struct", + "LSP Semantic Token Type: typeParameter", + "LSP Semantic Token Type: parameter", + "LSP Semantic Token Type: variable", + "LSP Semantic Token Type: property", + "LSP Semantic Token Type: enumMember", + "LSP Semantic Token Type: event", + "LSP Semantic Token Type: function", + "LSP Semantic Token Type: method", + "LSP Semantic Token Type: macro", + "LSP Semantic Token Type: keyword", + "LSP Semantic Token Type: modifier", + "LSP Semantic Token Type: comment", + "LSP Semantic Token Type: string", + "LSP Semantic Token Type: number", + "LSP Semantic Token Type: regexp", + "LSP Semantic Token Type: operator", + "LSP Semantic Token Type: decorator" + ], + "scope": "resource", + "type": "string" + }, "haskell.plugin.semanticTokens.config.patternSynonymToken": { "default": "macro", "description": "LSP semantic token type to use for pattern synonyms", From 155d6cdced31e91914c5ba2a4e7c80e14de86c10 Mon Sep 17 00:00:00 2001 From: Patrick Date: Sat, 3 Feb 2024 00:16:02 +0800 Subject: [PATCH 5/6] fix test --- .../hls-semantic-tokens-plugin/test/testdata/TOperator.expected | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/hls-semantic-tokens-plugin/test/testdata/TOperator.expected b/plugins/hls-semantic-tokens-plugin/test/testdata/TOperator.expected index 5ff519bf09..bcc567fe31 100644 --- a/plugins/hls-semantic-tokens-plugin/test/testdata/TOperator.expected +++ b/plugins/hls-semantic-tokens-plugin/test/testdata/TOperator.expected @@ -2,7 +2,7 @@ 4:4-5 TFunction "f" 4:6-7 TVariable "x" 4:10-11 TFunction "f" -4:12-13 TFunction "$" +4:12-13 TOperator "$" 4:14-15 TVariable "x" 6:2-6 TOperator "$$$$" 7:1-2 TVariable "x" From 5dfdbb47dbfa9aac99350182fc26bb35fa70011f Mon Sep 17 00:00:00 2001 From: Patrick Date: Sat, 3 Feb 2024 02:33:29 +0800 Subject: [PATCH 6/6] fix more test --- .../hls-semantic-tokens-plugin/test/testdata/T1.expected | 4 ++-- .../test/testdata/TInstanceClassMethodBind.expected | 6 +++--- .../test/testdata/TInstanceClassMethodBind.hs | 4 ++-- .../test/testdata/TInstanceClassMethodUse.expected | 2 +- .../test/testdata/TInstanceClassMethodUse.hs | 2 +- .../test/testdata/TQualifiedName.expected | 4 ++-- 6 files changed, 11 insertions(+), 11 deletions(-) diff --git a/plugins/hls-semantic-tokens-plugin/test/testdata/T1.expected b/plugins/hls-semantic-tokens-plugin/test/testdata/T1.expected index ca60c0f0f3..cbf7699f19 100644 --- a/plugins/hls-semantic-tokens-plugin/test/testdata/T1.expected +++ b/plugins/hls-semantic-tokens-plugin/test/testdata/T1.expected @@ -12,7 +12,7 @@ 15:5-8 TClassMethod "boo" 15:9-10 TVariable "x" 15:13-14 TVariable "x" -15:15-16 TClassMethod "+" +15:15-16 TOperator "+" 17:6-8 TTypeConstructor "Dd" 17:11-13 TDataConstructor "Dd" 17:14-17 TTypeConstructor "Int" @@ -74,7 +74,7 @@ 41:6-9 TRecordField "foo" 42:1-4 TFunction "add" 42:8-16 TModule "Prelude." -42:16-17 TClassMethod "+" +42:16-17 TOperator "+" 47:1-5 TVariable "main" 47:9-11 TTypeConstructor "IO" 48:1-5 TVariable "main" diff --git a/plugins/hls-semantic-tokens-plugin/test/testdata/TInstanceClassMethodBind.expected b/plugins/hls-semantic-tokens-plugin/test/testdata/TInstanceClassMethodBind.expected index 9468da2fc0..a4a6ef98e0 100644 --- a/plugins/hls-semantic-tokens-plugin/test/testdata/TInstanceClassMethodBind.expected +++ b/plugins/hls-semantic-tokens-plugin/test/testdata/TInstanceClassMethodBind.expected @@ -1,7 +1,7 @@ 4:6-9 TTypeConstructor "Foo" 4:12-15 TDataConstructor "Foo" 4:16-19 TTypeConstructor "Int" -5:10-12 TClass "Eq" -5:13-16 TTypeConstructor "Foo" -6:6-8 TClassMethod "==" +5:10-14 TClass "Show" +5:15-18 TTypeConstructor "Foo" +6:5-9 TClassMethod "show" 6:12-21 TVariable "undefined" diff --git a/plugins/hls-semantic-tokens-plugin/test/testdata/TInstanceClassMethodBind.hs b/plugins/hls-semantic-tokens-plugin/test/testdata/TInstanceClassMethodBind.hs index 68b634f470..33976a48c1 100644 --- a/plugins/hls-semantic-tokens-plugin/test/testdata/TInstanceClassMethodBind.hs +++ b/plugins/hls-semantic-tokens-plugin/test/testdata/TInstanceClassMethodBind.hs @@ -2,5 +2,5 @@ module TInstanceClassMethodBind where data Foo = Foo Int -instance Eq Foo where - (==) = undefined +instance Show Foo where + show = undefined diff --git a/plugins/hls-semantic-tokens-plugin/test/testdata/TInstanceClassMethodUse.expected b/plugins/hls-semantic-tokens-plugin/test/testdata/TInstanceClassMethodUse.expected index e55735f77a..2bf39be435 100644 --- a/plugins/hls-semantic-tokens-plugin/test/testdata/TInstanceClassMethodUse.expected +++ b/plugins/hls-semantic-tokens-plugin/test/testdata/TInstanceClassMethodUse.expected @@ -1,2 +1,2 @@ 4:1-3 TFunction "go" -4:10-12 TClassMethod "==" +4:8-12 TClassMethod "show" diff --git a/plugins/hls-semantic-tokens-plugin/test/testdata/TInstanceClassMethodUse.hs b/plugins/hls-semantic-tokens-plugin/test/testdata/TInstanceClassMethodUse.hs index 24ea9efd28..689d1643d4 100644 --- a/plugins/hls-semantic-tokens-plugin/test/testdata/TInstanceClassMethodUse.hs +++ b/plugins/hls-semantic-tokens-plugin/test/testdata/TInstanceClassMethodUse.hs @@ -1,5 +1,5 @@ module TInstanceClassMethodUse where -go = (==) +go = show diff --git a/plugins/hls-semantic-tokens-plugin/test/testdata/TQualifiedName.expected b/plugins/hls-semantic-tokens-plugin/test/testdata/TQualifiedName.expected index cdbe36bc46..0ca7cd7d5b 100644 --- a/plugins/hls-semantic-tokens-plugin/test/testdata/TQualifiedName.expected +++ b/plugins/hls-semantic-tokens-plugin/test/testdata/TQualifiedName.expected @@ -7,6 +7,6 @@ 7:18-22 TClassMethod "elem" 8:1-2 TVariable "c" 8:6-14 TModule "Prelude." -8:14-15 TClassMethod "+" +8:14-15 TOperator "+" 9:1-2 TVariable "d" -9:6-7 TClassMethod "+" +9:6-7 TOperator "+"