同一 TM Scope 中单词的语法高亮颜色如何不同? [英] How can the syntax highlighting color differ for words in the same TM Scope?

查看:27
本文介绍了同一 TM Scope 中单词的语法高亮颜色如何不同?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的 C++ 代码中,使用我的一些语法高亮方案,typedef DWORD 的颜色与其描述的变量不同,但如果我查看两者的 TM 范围,它们都是一样的:

控制这种行为的是什么黑魔法?(最终,我想在此主题的设置中覆盖蓝色)

解决方案

尽管 TextMate Scopes Inspector 显示不同的内容,但什么原因导致DWORD"为蓝色?我认为这是一个

要确认这是由装饰引起的,请使用帮助 → 切换开发人员工具,单击选择元素"图标(默认 Ctrl+Shift+C),然后单击感兴趣的文本.如果您看到名称以TextEditorDecorationType"开头的类,则说明已应用装饰.截图:

不幸的是,除了单独禁用它们直到它停止发生之外,我不知道如何追踪哪个扩展正在添加装饰.

一旦您找到导致它的原因,它可能就可以成为主题.Microsoft 有一个名为 decorator-sample 的示例扩展添加主题装饰.您可以将它的工作原理与您的案例中的相关扩展进行比较.具体来说,在它的 package.json 中查找包含颜色"的贡献".

2019-09-04 更新:正如 Johann 所指出的,C++ (cpptools) 扩展 使用 Decorations 来做语义高亮,例如高亮 typedef 名称,如 DWORD.我最初没有观察到这种行为,因为我使用的是Light (Visual Studio)"主题,它没有利用新功能.但是,Light+"和Dark+"主题(可能还有其他)确实如此.

但是,如链接文章中所述,这些颜色的主题方式与其他地方的主题颜色的工作方式不同.该扩展不是提供命名颜色,而是解析活动的 textMateRules(来自活动主题和任何 settings.json 自定义),寻找特定名称,然后相应地构建装饰.因此,这里有多层异常行为在起作用.

In my C++ code, with some of my syntax highlighting schemes, the typedef DWORD is colored differently from the variable it describes, but if I look at the TM scopes for the two, they are both the same:

What black magic is it that controls this behavior? (ultimately, I want to override the blue color in my settings for this theme)

解决方案

What causes "DWORD" to have a blue color despite the TextMate Scopes Inspector showing something different? I think it is a Decoration, probably applied by an extension you have installed (in my VSCode, "DWORD" is not colored like that, even when windows.h is #included).

Another example of this behavior can be seen with the way "launch.json" files are handled: create a file (anywhere) called "launch.json" and put a few fields into it, including one called "version". The "version" attribute will be gray, unlike the others, and despite what the TextMate inspector says. (Incidentally, I have filed an issue requesting that that gray color be removed.) Here is a screenshot:

To confirm this is caused by a decoration, use Help → Toggle Developer Tools, click the "Select an element" icon (default Ctrl+Shift+C), then click on the text of interest. If you see a class whose name begins with "TextEditorDecorationType", then a decoration has been applied. Screenshot:

Unfortunately, I do not know how to track down which extension is adding the decoration other than by disabling them individually until it stops happening.

Once you find the one that is causing it, it may be themable. Microsoft has a sample extension called decorator-sample that adds a themable decoration. You may be able to compare how that works to the relevant extension in your case. Specifically, look in its package.json for a "contributes" containing "colors".

Update 2019-09-04: As Johann noted, the C++ (cpptools) extension uses Decorations to do semantic highlighting, such as highlighting typedef names like DWORD. I did not observe that behavior originally because I was using the "Light (Visual Studio)" theme, which does not take advantage of the new capability. However, the "Light+" and "Dark+" themes (perhaps among others) do.

But, as explained in the linked article, the way these colors are themed is different from how theme colors work elsewhere. Rather than contributing a named color, the extension parses the active textMateRules (from the active theme and any settings.json customizations), looking for specific names, then builds decorations accordingly. So there are multiple layers of exceptional behavior at work here.

这篇关于同一 TM Scope 中单词的语法高亮颜色如何不同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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