创建Visual Studio主题特定的语法突出显示 [英] Create Visual Studio Theme Specific Syntax Highlighting

本文介绍了创建Visual Studio主题特定的语法突出显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Visual Studio 2012中创建语法突出显示(及更高版本),支持不同的主题(深色,浅色,蓝色).

I would like to create a Syntax Highlighter in Visual Studio 2012 (and above) that supports different themes (Dark, Light, Blue).

Visual Studio的编辑器分类器"项目模板说明了如何使用Microsoft.VisualStudio.Text.Classification.ClassificationFormatDefinition在环境中创建自己的颜色.效果很好...

Visual Studio's Editor Classifier project template explains how to create your own colors in the environment using Microsoft.VisualStudio.Text.Classification.ClassificationFormatDefinition. It works fine...

...,直到您意识到Visual Studio 2012(及更高版本)中存在不同的主题,并且您并未真正支持它们.在深色主题环境中,浅色主题上漂亮的深蓝色标识符变得不可读.

... until you realize that there are different themes in Visual Studio 2012 (and above) and you don't really support them. Your pretty dark blue colored identifiers on the light theme becomes unreadable in a dark themed environment.

据我了解,如果您在工具/选项/字体和工具"中更改了 ClassificationFormatDefinition 给定主题(例如:浅色)中的颜色不会影响不同主题(例如:深色)中相同的 ClassificationFormatDefinition .颜色似乎在不同主题之间是独立的.

To my understanding if you change your ClassificationFormatDefinition in the Tools/Options/Fonts & Colors in a given theme (e.g.: Light) it won't affect the same ClassificationFormatDefinition in a different theme (e.g.: Dark). The colors seem to be independent across different themes.

那很好.但是我如何实现定义相同的 ClassificationFormatDefinition (例如:MyKeywords),在所有主题中具有相同的名称,但是为它们提供不同的颜色? 标识符",在Light主题上默认为黑色,在Black主题上默认为黑色.

That is good. But how do I achieve defining the same ClassificationFormatDefinition (e.g.: MyKeywords) that has the same name in all the themes, but provides different colors for them? Just like Visual Studio's own "Identifier", which is default black on the Light theme and default while on the Black theme.

我知道Microsoft.VisualStudio.PlatformUI.VSColorTheme.ThemeChanged事件,该事件使我可以在更改颜色主题时得到通知.我是否必须使用它并以某种方式掌握我现有的 ClassificationFormatDefinition 并根据新主题为其分配新的颜色?但这还引发了一个问题:这些修改后的颜色是否会保留到环境中,即如果我重新启动Visual Studio,则下次在所有不同的主题中所做的更改都会存在.

I know about the Microsoft.VisualStudio.PlatformUI.VSColorTheme.ThemeChanged event that allows me to get notified when the color themes are changed. Do I have to use this and somehow get hold of my existing ClassificationFormatDefinition and assign new colors to them based on the new theme? But that also pops a question: will these modified colors be persisted to the environment, i.e. if I restart Visual Studio, will my changes be there the next time in all the different themes.

我还没有找到任何可以说明 ClassificationFormatDefinition 支持哪个主题的属性,也没有找到关于该主题的有用文章.

I haven't found any attribute that would state which theme the ClassificationFormatDefinition supports nor found much helpful article on the subject.

任何帮助表示赞赏.

推荐答案

使用F#Power Tools的代码,这似乎可以帮助您似乎正在侦听ThemeChanged事件并更新分类器- https://github.com/fsprojects/VisualFSharpPowerTools/blob/a7d7aa9dd3d2a90f21c6947867ac7d7163b9f99a/src/FSharpVSPowerTools/SyntaxConstructClassifierProvider.cs

This might help you, code from F# Power Tools, seems to be listening to the ThemeChanged event and updating the classifiers - https://github.com/fsprojects/VisualFSharpPowerTools/blob/a7d7aa9dd3d2a90f21c6947867ac7d7163b9f99a/src/FSharpVSPowerTools/SyntaxConstructClassifierProvider.cs

这篇关于创建Visual Studio主题特定的语法突出显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆