突出显示SQL模式名称

huangapple go评论52阅读模式
英文:

Highlighting the SQL schema name

问题

在VS Code中,选择SQL语言时,关键字会被高亮显示。我需要在高亮显示的地方,将位于句点之前的模式、表或别名以不同的颜色进行高亮显示(下面显示了应该高亮显示的内容)。

代码应该类似于这样:
screenshot

以下是上述截图中用于您的复制示例的代码:

SELECT TABLE.COL1, T2.COL2
FROM SCHEMA1.TABLE1
INNER JOIN SCHEMA1.TABLE2 AS T2 ON TABLE1.COL1 = T2.COL2

我不理解VS Code中的SQL代码高亮显示设置是如何工作的,我找不到有关如何进行设置的说明。

英文:

In VS Code, when selecting the SQL language, the keywords are highlighted. I need the schemas, tables, or aliases that stand in front of the dot to be highlighted in a different color (below shows what should be highlighted).

The code should look something like this:
screenshot

Here's the code used in the above screenshot for your repro purposes:

SELECT TABLE.COL1, T2.COL2
FROM SCHEMA1.TABLE1
INNER JOIN SCHEMA1.TABLE2 AS T2 ON TABLE1.COL1 = T2.COL2

I don't understand how the SQL code highlighting settings work in VS Code and I can't find instructions on how to do it.

答案1

得分: 0

如果您在命令面板中使用“Developer: Inspect Editor Token and Scopes”命令,并将光标放在您想要自定义颜色的上下文中,您会发现它们具有“constant.other.database-name.sql” TextMate范围(这有点奇怪,因为它们并不都是数据库名称-有些是表名称(我怀疑VS Code中的内置TextMate SQL语法](https://github.com/microsoft/vscode/blob/main/extensions/sql/syntaxes/sql.tmLanguage.json)要么不是很好,要么达到了TextMate语法的技术限制),因此您可以使用以下配置:

"editor.tokenColorCustomizations": {
    "[<主题名称>]": { // TODO 插入您的主题名称,或者删除此包装块以应用于所有主题
        "textMateRules": [
            {
                "scope": "constant.other.database-name.sql",
                "settings": {
                    "foreground": "#FF0000", // TODO
                }
            }
        ]
    }
},
英文:

If you use the Developer: Inspect Editor Token and Scopes command in the command palette and put the caret in the contexts you want to customize colours for, you'll see that they have the constant.other.database-name.sql TextMate scope (which is odd, since not all of them are database names- some are table names (I suspect the builtin TextMate grammar for SQL in VS Code is not either very good, or hitting technical limitations of TextMate grammars)), so you can use the following config:

&quot;editor.tokenColorCustomizations&quot;: {
    &quot;[&lt;Theme Name&gt;]&quot;: { // TODO insert your theme&#39;s name, or remove this wrapper block to apply to all themes
        &quot;textMateRules&quot;: [
            {
                &quot;scope&quot;: &quot;constant.other.database-name.sql&quot;,
                &quot;settings&quot;: {
                    &quot;foreground&quot;: &quot;#FF0000&quot;, // TODO
                }
            }
        ]
    }
},

huangapple
  • 本文由 发表于 2023年5月29日 23:33:51
  • 转载请务必保留本文链接:https://go.coder-hub.com/76358593.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定