Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit09a8c60

Browse files
majochaKevinRansom
authored andcommitted
Separate color themes for dark and light mode (dotnet#2450)
* working theme manager added* Shared is default* typo, named constants* extract constants* capitalization* fix build* Revert "fix build"This reverts commit022c690.* Revert "capitalization"This reverts commit21538dc.* Revert "extract constants"This reverts commitb1ee913.* use guid from vs sdk* known color themes are in the sdk, too* batch update seems to work after all
1 parent8aebb66 commit09a8c60

File tree

1 file changed

+77
-11
lines changed

1 file changed

+77
-11
lines changed

‎vsintegration/src/FSharp.Editor/Classification/ClassificationDefinitions.fs‎

Lines changed: 77 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ open System
66
openSystem.ComponentModel.Composition
77
openSystem.Windows.Media
88

9+
openMicrosoft.VisualStudio
10+
openMicrosoft.VisualStudio.Editor
11+
openMicrosoft.VisualStudio.PlatformUI
12+
openMicrosoft.VisualStudio.Shell
13+
openMicrosoft.VisualStudio.Shell.Interop
14+
openMicrosoft.Internal.VisualStudio.Shell.Interop
915
openMicrosoft.VisualStudio.Language.StandardClassification
1016
openMicrosoft.VisualStudio.Text.Classification
1117
openMicrosoft.VisualStudio.Utilities
@@ -41,6 +47,64 @@ module internal FSharpClassificationTypes =
4147
| SemanticClassificationType.Interface-> Interface
4248

4349
moduleinternalClassificationDefinitions=
50+
51+
[<Export>]
52+
typeinternalThemeColors
53+
[<ImportingConstructor>]
54+
(
55+
classificationformatMapService: IClassificationFormatMapService,
56+
classificationTypeRegistry: IClassificationTypeRegistryService,
57+
[<Import(typeof<SVsServiceProvider>)>] serviceProvider: IServiceProvider
58+
)=
59+
60+
let(|LightTheme|DarkTheme|UnknownTheme|)id=
61+
if id= KnownColorThemes.Light|| id= KnownColorThemes.Bluethen LightTheme
62+
elif id= KnownColorThemes.Darkthen DarkTheme
63+
else UnknownTheme
64+
65+
letgetCurrentThemeId()=
66+
letthemeService= serviceProvider.GetService(typeof<SVsColorThemeService>):?> IVsColorThemeService
67+
themeService.CurrentTheme.ThemeId
68+
69+
letcolorData=// name, (light, dark)
70+
[ FSharpClassificationTypes.Function,(Colors.Black, Color.FromRgb(220uy,220uy,220uy))
71+
FSharpClassificationTypes.MutableVar,(Color.FromRgb(160uy,128uy,0uy), Color.FromRgb(255uy,210uy,28uy))
72+
FSharpClassificationTypes.Printf,(Color.FromRgb(43uy,145uy,175uy), Color.FromRgb(78uy,220uy,176uy))
73+
FSharpClassificationTypes.Property,(Colors.Black, Color.FromRgb(220uy,220uy,220uy))]
74+
75+
letsetColors _=
76+
letfontAndColorStorage= serviceProvider.GetService(typeof<SVsFontAndColorStorage>):?> IVsFontAndColorStorage
77+
letfontAndColorCacheManager= serviceProvider.GetService(typeof<SVsFontAndColorCacheManager>):?> IVsFontAndColorCacheManager
78+
fontAndColorCacheManager.CheckCache( ref DefGuidList.guidTextEditorFontCategory)|> ignore
79+
fontAndColorStorage.OpenCategory(ref DefGuidList.guidTextEditorFontCategory, uint32__FCSTORAGEFLAGS.FCSF_READONLY)|> ignore
80+
81+
letformatMap= classificationformatMapService.GetClassificationFormatMap(category="text")
82+
try
83+
formatMap.BeginBatchUpdate()
84+
for ctype,(light, dark)in colorDatado
85+
// we don't touch the changes made by the user
86+
if fontAndColorStorage.GetItem(ctype, Array.zeroCreate1)<> VSConstants.S_OKthen
87+
letict= classificationTypeRegistry.GetClassificationType(ctype)
88+
letoldProps= formatMap.GetTextProperties(ict)
89+
letnewProps=match getCurrentThemeId()with
90+
| LightTheme-> oldProps.SetForeground light
91+
| DarkTheme-> oldProps.SetForeground dark
92+
| UnknownTheme-> oldProps
93+
formatMap.SetTextProperties(ict, newProps)
94+
fontAndColorStorage.CloseCategory()|> ignore
95+
finally formatMap.EndBatchUpdate()
96+
97+
lethandler= ThemeChangedEventHandler setColors
98+
do VSColorTheme.add_ThemeChanged handler
99+
interface IDisposablewithmember__.Dispose()= VSColorTheme.remove_ThemeChanged handler
100+
101+
member__.GetColor(ctype)=
102+
letlight,dark= colorData|> Map.ofList|> Map.find ctype
103+
match getCurrentThemeId()with
104+
| LightTheme-> Nullable light
105+
| DarkTheme-> Nullable dark
106+
| UnknownTheme-> Nullable()
107+
44108
[<Export; Name(FSharpClassificationTypes.Function); BaseDefinition(PredefinedClassificationTypeNames.FormalLanguage)>]
45109
letFSharpFunctionClassificationType:ClassificationTypeDefinition=null
46110

@@ -58,39 +122,41 @@ module internal ClassificationDefinitions =
58122
[<Name(FSharpClassificationTypes.Function)>]
59123
[<UserVisible(true)>]
60124
[<Order(After= PredefinedClassificationTypeNames.Keyword)>]
61-
typeinternalFSharpFunctionTypeFormat()as self=
125+
typeinternalFSharpFunctionTypeFormat[<ImportingConstructor>](theme: ThemeColors)asself=
62126
inherit ClassificationFormatDefinition()
63-
// Not setting any colors here, so it will inherit from "Plain Text" by default
127+
64128
do self.DisplayName<- SR.FSharpFunctionsOrMethodsClassificationType.Value
129+
self.ForegroundColor<- theme.GetColor FSharpClassificationTypes.Function
65130

66131
[<Export(typeof<EditorFormatDefinition>)>]
67132
[<ClassificationType(ClassificationTypeNames= FSharpClassificationTypes.MutableVar)>]
68133
[<Name(FSharpClassificationTypes.MutableVar)>]
69134
[<UserVisible(true)>]
70135
[<Order(After= PredefinedClassificationTypeNames.Keyword)>]
71-
typeinternalFSharpMutableVarTypeFormat()as self=
136+
typeinternalFSharpMutableVarTypeFormat[<ImportingConstructor>](theme: ThemeColors)asself=
72137
inherit ClassificationFormatDefinition()
73-
138+
74139
do self.DisplayName<- SR.FSharpMutableVarsClassificationType.Value
75-
self.ForegroundColor<-Nullable Colors.Red
140+
self.ForegroundColor<-theme.GetColor FSharpClassificationTypes.MutableVar
76141

77142
[<Export(typeof<EditorFormatDefinition>)>]
78143
[<ClassificationType(ClassificationTypeNames= FSharpClassificationTypes.Printf)>]
79144
[<Name(FSharpClassificationTypes.Printf)>]
80145
[<UserVisible(true)>]
81146
[<Order(After= PredefinedClassificationTypeNames.String)>]
82-
typeinternalFSharpPrintfTypeFormat()as self=
147+
typeinternalFSharpPrintfTypeFormat[<ImportingConstructor>](theme: ThemeColors)asself=
83148
inherit ClassificationFormatDefinition()
84-
149+
85150
do self.DisplayName<- SR.FSharpPrintfFormatClassificationType.Value
86-
self.ForegroundColor<-Nullable(Color.FromRgb(43uy,145uy,175uy))
87-
151+
self.ForegroundColor<-theme.GetColor FSharpClassificationTypes.Printf
152+
88153
[<Export(typeof<EditorFormatDefinition>)>]
89154
[<ClassificationType(ClassificationTypeNames= FSharpClassificationTypes.Property)>]
90155
[<Name(FSharpClassificationTypes.Property)>]
91156
[<UserVisible(true)>]
92157
[<Order(After= PredefinedClassificationTypeNames.Keyword)>]
93-
typeinternalFSharpPropertyFormat()as self=
158+
typeinternalFSharpPropertyFormat[<ImportingConstructor>](theme: ThemeColors)asself=
94159
inherit ClassificationFormatDefinition()
95-
160+
96161
do self.DisplayName<- SR.FSharpPropertiesClassificationType.Value
162+
self.ForegroundColor<- theme.GetColor FSharpClassificationTypes.Property

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp