Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ open Microsoft.VisualStudio.Editor
open Microsoft.VisualStudio.PlatformUI
open Microsoft.VisualStudio.Shell
open Microsoft.VisualStudio.Shell.Interop
open Microsoft.Internal.VisualStudio.Shell.Interop
open Microsoft.VisualStudio.Language.StandardClassification
open Microsoft.VisualStudio.Text.Classification
open Microsoft.VisualStudio.Utilities
Expand Down Expand Up @@ -91,23 +90,7 @@ module internal ClassificationDefinitions =
[<Import(typeof<SVsServiceProvider>)>] serviceProvider: IServiceProvider
) =

let (|LightTheme|DarkTheme|UnknownTheme|) id =
if
id = KnownColorThemes.Light
|| id = KnownColorThemes.Blue
|| id = Guids.blueHighContrastThemeId
then
LightTheme
elif id = KnownColorThemes.Dark then
DarkTheme
else
UnknownTheme

let getCurrentThemeId () =
let themeService =
serviceProvider.GetService(typeof<SVsColorThemeService>) :?> IVsColorThemeService

themeService.CurrentTheme.ThemeId
let mutable isDarkBackground = false

let customColorData =
[
Expand Down Expand Up @@ -143,7 +126,16 @@ module internal ClassificationDefinitions =
|}
]

let setIsDarkBackground () =
isDarkBackground <-
VSColorTheme
.GetThemedColor(EnvironmentColors.ToolWindowBackgroundColorKey)
.GetBrightness() < 0.5f

let setColors _ =

setIsDarkBackground ()

let fontAndColorStorage =
serviceProvider.GetService(typeof<SVsFontAndColorStorage>) :?> IVsFontAndColorStorage

Expand Down Expand Up @@ -172,10 +164,10 @@ module internal ClassificationDefinitions =
let oldProps = formatMap.GetTextProperties(ict)

let newProps =
match getCurrentThemeId () with
| LightTheme -> oldProps.SetForeground item.LightThemeColor
| DarkTheme -> oldProps.SetForeground item.DarkThemeColor
| UnknownTheme -> oldProps
if isDarkBackground then
oldProps.SetForeground item.DarkThemeColor
else
oldProps.SetForeground item.LightThemeColor

formatMap.SetTextProperties(ict, newProps)

Expand All @@ -187,15 +179,13 @@ module internal ClassificationDefinitions =

do VSColorTheme.add_ThemeChanged handler

do setIsDarkBackground ()

member _.GetColor(ctype) =
match customColorData |> List.tryFindV (fun item -> item.ClassificationName = ctype) with
| ValueSome item ->
let light, dark = item.LightThemeColor, item.DarkThemeColor

match getCurrentThemeId () with
| LightTheme -> Nullable light
| DarkTheme -> Nullable dark
| UnknownTheme -> Nullable()
if isDarkBackground then Nullable dark else Nullable light
| ValueNone -> Nullable()

interface ISetThemeColors with
Expand Down