From 227132b856725d5078a66d627f444a2ddd8fcf87 Mon Sep 17 00:00:00 2001 From: vaskir Date: Tue, 22 Nov 2016 21:57:23 +0300 Subject: [PATCH 1/2] highlight DU cases and Active Patterns as "Enum" Roslyn classification type --- src/fsharp/vs/ServiceLexing.fs | 1 + src/fsharp/vs/ServiceLexing.fsi | 1 + src/fsharp/vs/service.fs | 3 +++ vsintegration/src/FSharp.Editor/ColorizationService.fs | 4 +++- 4 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/fsharp/vs/ServiceLexing.fs b/src/fsharp/vs/ServiceLexing.fs index 295a380af14..5d5c3d450e4 100755 --- a/src/fsharp/vs/ServiceLexing.fs +++ b/src/fsharp/vs/ServiceLexing.fs @@ -88,6 +88,7 @@ type FSharpTokenColorKind = | Number = 9 | Operator = 10 | TypeName = 11 + | Pattern = 12 /// Categorize an action the editor should take in response to a token, e.g. brace matching /// diff --git a/src/fsharp/vs/ServiceLexing.fsi b/src/fsharp/vs/ServiceLexing.fsi index f372449f410..f7328635365 100755 --- a/src/fsharp/vs/ServiceLexing.fsi +++ b/src/fsharp/vs/ServiceLexing.fsi @@ -53,6 +53,7 @@ type internal FSharpTokenColorKind = | Number = 9 | Operator = 10 | TypeName = 11 + | Pattern = 12 /// Gives an indication of what should happen when the token is typed in an IDE type internal FSharpTokenTriggerClass = diff --git a/src/fsharp/vs/service.fs b/src/fsharp/vs/service.fs index 8945c607213..dc0863e46b2 100755 --- a/src/fsharp/vs/service.fs +++ b/src/fsharp/vs/service.fs @@ -1371,6 +1371,9 @@ type TypeCheckInfo // typevariables get colored as types when they occur in syntactic types custom builders, custom operations get colored as keywords | CNR(_, (Item.TypeVar _ | Item.Types _ | Item.UnqualifiedType _) , (ItemOccurence.UseInType | ItemOccurence.UseInAttribute), _, _, _, m) -> yield (m, FSharpTokenColorKind.TypeName) + | CNR(_, (Item.UnionCase _ | Item.ActivePatternCase _), + (ItemOccurence.Binding | ItemOccurence.Implemented | ItemOccurence.Pattern | ItemOccurence.Use | ItemOccurence.UseInType), _, _, _, m) -> + yield (m, FSharpTokenColorKind.Pattern) | _ -> () |] member x.ScopeResolutions = sResolutions diff --git a/vsintegration/src/FSharp.Editor/ColorizationService.fs b/vsintegration/src/FSharp.Editor/ColorizationService.fs index e4ae973b2ee..82ff7d13d5b 100644 --- a/vsintegration/src/FSharp.Editor/ColorizationService.fs +++ b/vsintegration/src/FSharp.Editor/ColorizationService.fs @@ -51,7 +51,9 @@ type internal FSharpColorizationService() = | FSharpTokenColorKind.PreprocessorKeyword -> ClassificationTypeNames.PreprocessorKeyword | FSharpTokenColorKind.Operator -> ClassificationTypeNames.Operator | FSharpTokenColorKind.TypeName -> ClassificationTypeNames.ClassName - | FSharpTokenColorKind.Default | _ -> ClassificationTypeNames.Text + | FSharpTokenColorKind.Pattern -> ClassificationTypeNames.EnumName + | FSharpTokenColorKind.Default + | _ -> ClassificationTypeNames.Text static let scanSourceLine(sourceTokenizer: FSharpSourceTokenizer, textLine: TextLine, lineContents: string, lexState: FSharpTokenizerLexState) : SourceLineData = From 4b83070e7ccf23d128a7caf3acfa3566fc1b0b1d Mon Sep 17 00:00:00 2001 From: vaskir Date: Wed, 23 Nov 2016 21:39:32 +0300 Subject: [PATCH 2/2] highlight modules and constructors fix custom CE names and DU cases highlighting --- src/fsharp/vs/ServiceLexing.fs | 1 + src/fsharp/vs/ServiceLexing.fsi | 1 + src/fsharp/vs/service.fs | 16 +++++++++++++--- .../src/FSharp.Editor/ColorizationService.fs | 1 + 4 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/fsharp/vs/ServiceLexing.fs b/src/fsharp/vs/ServiceLexing.fs index 5d5c3d450e4..39c6ea778f8 100755 --- a/src/fsharp/vs/ServiceLexing.fs +++ b/src/fsharp/vs/ServiceLexing.fs @@ -89,6 +89,7 @@ type FSharpTokenColorKind = | Operator = 10 | TypeName = 11 | Pattern = 12 + | Module = 13 /// Categorize an action the editor should take in response to a token, e.g. brace matching /// diff --git a/src/fsharp/vs/ServiceLexing.fsi b/src/fsharp/vs/ServiceLexing.fsi index f7328635365..c300c57d810 100755 --- a/src/fsharp/vs/ServiceLexing.fsi +++ b/src/fsharp/vs/ServiceLexing.fsi @@ -54,6 +54,7 @@ type internal FSharpTokenColorKind = | Operator = 10 | TypeName = 11 | Pattern = 12 + | Module = 13 /// Gives an indication of what should happen when the token is typed in an IDE type internal FSharpTokenTriggerClass = diff --git a/src/fsharp/vs/service.fs b/src/fsharp/vs/service.fs index dc0863e46b2..a5df081c9c4 100755 --- a/src/fsharp/vs/service.fs +++ b/src/fsharp/vs/service.fs @@ -1365,13 +1365,23 @@ type TypeCheckInfo | CNR(_, (Item.Value vref), ItemOccurence.Use, _, _, _, m) when valRefEq g g.seq_vref vref -> yield (m, FSharpTokenColorKind.Keyword) // custom builders, custom operations get colored as keywords - | CNR(_, (Item.CustomBuilder _ | Item.CustomOperation _), ItemOccurence.Use, _, _, _, m) -> + | CNR(_, Item.CustomBuilder(_, valRef), ItemOccurence.Use, _, _, _, _) -> + yield (valRef.Range, FSharpTokenColorKind.Keyword) + | CNR(_, Item.CustomOperation _, ItemOccurence.Use, _, _, _, m) -> yield (m, FSharpTokenColorKind.Keyword) // types get colored as types when they occur in syntactic types or custom attributes // typevariables get colored as types when they occur in syntactic types custom builders, custom operations get colored as keywords - | CNR(_, (Item.TypeVar _ | Item.Types _ | Item.UnqualifiedType _) , (ItemOccurence.UseInType | ItemOccurence.UseInAttribute), _, _, _, m) -> + | CNR(_, (Item.TypeVar _ | Item.Types _ | Item.UnqualifiedType _), + (ItemOccurence.UseInType | ItemOccurence.UseInAttribute | ItemOccurence.Binding _), _, _, _, m) -> + yield (m, FSharpTokenColorKind.TypeName) + | CNR(_, Item.CtorGroup _, ItemOccurence.Use, _, _, _, m) -> yield (m, FSharpTokenColorKind.TypeName) - | CNR(_, (Item.UnionCase _ | Item.ActivePatternCase _), + | CNR(_, Item.ModuleOrNamespaces _, ItemOccurence.Binding, _, _, _, m) -> + yield (m, FSharpTokenColorKind.Module) + | CNR(_, Item.UnionCase (UnionCaseInfo (_, r), _), + (ItemOccurence.Binding | ItemOccurence.Implemented | ItemOccurence.Pattern | ItemOccurence.Use | ItemOccurence.UseInType), _, _, _, _) -> + yield (r.Range, FSharpTokenColorKind.Pattern) + | CNR(_, Item.ActivePatternCase _, (ItemOccurence.Binding | ItemOccurence.Implemented | ItemOccurence.Pattern | ItemOccurence.Use | ItemOccurence.UseInType), _, _, _, m) -> yield (m, FSharpTokenColorKind.Pattern) | _ -> () diff --git a/vsintegration/src/FSharp.Editor/ColorizationService.fs b/vsintegration/src/FSharp.Editor/ColorizationService.fs index 82ff7d13d5b..4964075fd10 100644 --- a/vsintegration/src/FSharp.Editor/ColorizationService.fs +++ b/vsintegration/src/FSharp.Editor/ColorizationService.fs @@ -52,6 +52,7 @@ type internal FSharpColorizationService() = | FSharpTokenColorKind.Operator -> ClassificationTypeNames.Operator | FSharpTokenColorKind.TypeName -> ClassificationTypeNames.ClassName | FSharpTokenColorKind.Pattern -> ClassificationTypeNames.EnumName + | FSharpTokenColorKind.Module -> ClassificationTypeNames.ModuleName | FSharpTokenColorKind.Default | _ -> ClassificationTypeNames.Text