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

Commit73824d2

Browse files
committed
working theme manager added
1 parentf070cb8 commit73824d2

File tree

1 file changed

+78
-11
lines changed

1 file changed

+78
-11
lines changed

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

Lines changed: 78 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,15 @@
33
namespaceMicrosoft.VisualStudio.FSharp.Editor
44

55
openSystem
6+
openSystem.Composition
67
openSystem.ComponentModel.Composition
78
openSystem.Windows.Media
89

10+
openMicrosoft.VisualStudio
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
@@ -40,7 +46,66 @@ module internal FSharpClassificationTypes =
4046
| SemanticClassificationType.Property-> Property
4147
| SemanticClassificationType.Interface-> Interface
4248

49+
50+
4351
moduleinternalClassificationDefinitions=
52+
53+
[<Export; Shared>]
54+
typeinternalThemeColors
55+
[<ImportingConstructor>]
56+
(
57+
classificationformatMapService: IClassificationFormatMapService,
58+
classificationTypeRegistry: IClassificationTypeRegistryService,
59+
[<Import(typeof<SVsServiceProvider>)>] serviceProvider: IServiceProvider
60+
)=
61+
62+
let(|LighTheme|DarkTheme|UnknownTheme|)id=
63+
if id= Guid("de3dbbcd-f642-433c-8353-8f1df4370aba")||
64+
id= Guid("a4d6a176-b948-4b29-8c66-53c97a1ed7d0")then LighTheme
65+
elif id= Guid("1ded0138-47ce-435e-84ef-9ec1f439b749")then DarkTheme
66+
else UnknownTheme
67+
68+
letgetCurrentThemeId()=
69+
letthemeService= serviceProvider.GetService(typeof<SVsColorThemeService>):?> IVsColorThemeService
70+
themeService.CurrentTheme.ThemeId
71+
72+
letcolorData=// name, (light, dark)
73+
[ FSharpClassificationTypes.Function,(Colors.Black, Color.FromRgb(220uy,220uy,220uy))
74+
FSharpClassificationTypes.MutableVar,(Color.FromRgb(160uy,128uy,0uy), Color.FromRgb(255uy,210uy,28uy))
75+
FSharpClassificationTypes.Printf,(Color.FromRgb(43uy,145uy,175uy), Color.FromRgb(78uy,220uy,176uy))
76+
FSharpClassificationTypes.Property,(Colors.Black, Color.FromRgb(220uy,220uy,220uy))]
77+
78+
letsetColors _=
79+
letfontAndColorStorage= serviceProvider.GetService(typeof<SVsFontAndColorStorage>):?> IVsFontAndColorStorage
80+
letfontAndColorCacheManager= serviceProvider.GetService(typeof<SVsFontAndColorCacheManager>):?> IVsFontAndColorCacheManager
81+
lettextEditor= Guid("A27B4E24-A735-4D1D-B8E7-9716E1E3D8E0")
82+
fontAndColorCacheManager.CheckCache( ref textEditor)|> ignore
83+
fontAndColorStorage.OpenCategory(ref textEditor, uint32__FCSTORAGEFLAGS.FCSF_READONLY)|> ignore
84+
85+
letformatMap= classificationformatMapService.GetClassificationFormatMap(category="text")
86+
for ctype,(light, dark)in colorDatado
87+
// we don't touch the changes made by the user
88+
if fontAndColorStorage.GetItem(ctype, Array.zeroCreate1)<> VSConstants.S_OKthen
89+
letict= classificationTypeRegistry.GetClassificationType(ctype)
90+
letoldProps= formatMap.GetTextProperties(ict)
91+
letnewProps=match getCurrentThemeId()with
92+
| LighTheme-> oldProps.SetForeground light
93+
| DarkTheme-> oldProps.SetForeground dark
94+
| UnknownTheme-> oldProps
95+
formatMap.SetTextProperties(ict, newProps)
96+
fontAndColorStorage.CloseCategory()|> ignore
97+
98+
lethandler= ThemeChangedEventHandler setColors
99+
do VSColorTheme.add_ThemeChanged handler
100+
interface IDisposablewithmember__.Dispose()= VSColorTheme.remove_ThemeChanged handler
101+
102+
member__.getColor(ctype)=
103+
letlight,dark= colorData|> Map.ofList|> Map.find ctype
104+
match getCurrentThemeId()with
105+
| LighTheme-> Nullable light
106+
| DarkTheme-> Nullable dark
107+
| UnknownTheme-> Nullable()
108+
44109
[<Export; Name(FSharpClassificationTypes.Function); BaseDefinition(PredefinedClassificationTypeNames.FormalLanguage)>]
45110
letFSharpFunctionClassificationType:ClassificationTypeDefinition=null
46111

@@ -58,39 +123,41 @@ module internal ClassificationDefinitions =
58123
[<Name(FSharpClassificationTypes.Function)>]
59124
[<UserVisible(true)>]
60125
[<Order(After= PredefinedClassificationTypeNames.Keyword)>]
61-
typeinternalFSharpFunctionTypeFormat()as self=
126+
typeinternalFSharpFunctionTypeFormat[<ImportingConstructor>](theme: ThemeColors)asself=
62127
inherit ClassificationFormatDefinition()
63-
// Not setting any colors here, so it will inherit from "Plain Text" by default
128+
64129
do self.DisplayName<- SR.FSharpFunctionsOrMethodsClassificationType.Value
130+
self.ForegroundColor<- theme.getColor FSharpClassificationTypes.Function
65131

66132
[<Export(typeof<EditorFormatDefinition>)>]
67133
[<ClassificationType(ClassificationTypeNames= FSharpClassificationTypes.MutableVar)>]
68134
[<Name(FSharpClassificationTypes.MutableVar)>]
69135
[<UserVisible(true)>]
70136
[<Order(After= PredefinedClassificationTypeNames.Keyword)>]
71-
typeinternalFSharpMutableVarTypeFormat()as self=
137+
typeinternalFSharpMutableVarTypeFormat[<ImportingConstructor>](theme: ThemeColors)asself=
72138
inherit ClassificationFormatDefinition()
73-
139+
74140
do self.DisplayName<- SR.FSharpMutableVarsClassificationType.Value
75-
self.ForegroundColor<-Nullable Colors.Red
141+
self.ForegroundColor<-theme.getColor FSharpClassificationTypes.MutableVar
76142

77143
[<Export(typeof<EditorFormatDefinition>)>]
78144
[<ClassificationType(ClassificationTypeNames= FSharpClassificationTypes.Printf)>]
79145
[<Name(FSharpClassificationTypes.Printf)>]
80146
[<UserVisible(true)>]
81147
[<Order(After= PredefinedClassificationTypeNames.String)>]
82-
typeinternalFSharpPrintfTypeFormat()as self=
148+
typeinternalFSharpPrintfTypeFormat[<ImportingConstructor>](theme: ThemeColors)asself=
83149
inherit ClassificationFormatDefinition()
84-
150+
85151
do self.DisplayName<- SR.FSharpPrintfFormatClassificationType.Value
86-
self.ForegroundColor<-Nullable(Color.FromRgb(43uy,145uy,175uy))
87-
152+
self.ForegroundColor<-theme.getColor FSharpClassificationTypes.Printf
153+
88154
[<Export(typeof<EditorFormatDefinition>)>]
89155
[<ClassificationType(ClassificationTypeNames= FSharpClassificationTypes.Property)>]
90156
[<Name(FSharpClassificationTypes.Property)>]
91157
[<UserVisible(true)>]
92158
[<Order(After= PredefinedClassificationTypeNames.Keyword)>]
93-
typeinternalFSharpPropertyFormat()as self=
159+
typeinternalFSharpPropertyFormat[<ImportingConstructor>](theme: ThemeColors)asself=
94160
inherit ClassificationFormatDefinition()
95-
161+
96162
do self.DisplayName<- SR.FSharpPropertiesClassificationType.Value
163+
self.ForegroundColor<- theme.getColor FSharpClassificationTypes.Property

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp