Sublime Text:如何更正 SQL Server 语法 [英] Sublime Text: how to correct SQL Server syntax

查看:43
本文介绍了Sublime Text:如何更正 SQL Server 语法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 Sublime Text(第 3 版)的新手,我在获得正确的 SQL 语法突出显示方面遇到了困难.

每当我查看 SQL 查询时,ST 都会将#"视为注释.例如,这里 # 之后的所有内容都变灰了:

INSERT INTO #TEST (A,B,C,D)值 ('a','b','c','d')

我想纠正这个问题,所以我几个星期四处寻找答案,但没有一个有效......

我首先在 C:\Program Files\Sublime Text 3\Packages 中查找文件 SQL.sublime-package.

我在评论区找到了这段文字:

- 匹配:#"范围:punctuation.definition.comment.sql推:- meta_scope:comment.line.number-sign.sql- 匹配:\n流行音乐:真的

所以我尝试编辑它:

  • 删除文本块会导致 Sublime Text 错误:
<块引用>

错误加载语法文件Packages/SQL/SQL.sublime-syntax":无法阅读 Packages/SQL/SQL.sublime-syntax

  • 用其他东西改变 # 符号(例如--"):没有效果

您是否有解决方案可以在 Sublime Text 3 中获得正确的 SQL 语法高亮显示?

非常感谢

解决方案

您走对了;你试过的应该对你有用.如果您收到一个错误,表明 Sublime 无法加载语法,最可能的原因是您删除了太多文件或以其他一些微妙的方式更改了文件.sublime-syntax 文件是 YAML,因此它们对缩进之类的东西很敏感.

另请注意,直接在 Packages 文件夹中执行任何操作都是一个坏主意;修改 sublime-package 文件在短期内有效,但是通过删除和替换它们来升级它们.因此,除非您是最初制作文件的人,否则直接修改内容是一种方法,您的更改会在您最不希望的时候被毫不客气地删除.

进行以下更改对我有用.这使用

如果您之前修改了实际的 sublime-package 文件,这可能不起作用.在这种情况下,您可能需要重新安装 Sublime 以取回原始文件;这样做不会删除您的设置.或者,您可以从 Sublime 网站下载 Windows 便携式版本(即使您不使用 Windows)并从那里获取原始软件包以替换您修改的那个.

I am new to Sublime Text (version 3) and I am experiencing difficulties to get a proper SQL syntax highlighting.

Whenever I am looking at SQL queries, ST considers "#" as comment. For example, here everything beyond # gets greyed out:

INSERT INTO #TEST (A,B,C,D)
VALUES ('a','b','c','d')

I would like to correct this, so I looked around for answers for weeks but none of them works...

I started by looking in C:\Program Files\Sublime Text 3\Packages to find the file SQL.sublime-package.

I found this text in the comments section:

- match: "#"
  scope: punctuation.definition.comment.sql
  push:
   - meta_scope: comment.line.number-sign.sql
    - match: \n
      pop: true

So I tried to edit it:

  • Deleting the text block results in a Sublime Text error:

Error loading syntax file "Packages/SQL/SQL.sublime-syntax": Unable to read Packages/SQL/SQL.sublime-syntax

  • Changing the # sign by something else (e.g. "--"): no effect

Do you have a solution to get a proper SQL syntax highlighting in Sublime Text 3?

Thanks a lot

解决方案

You're on the right track; what you tried should work for you. If you get an error indicating that Sublime can't load the syntax, the most likely cause is that you deleted too much or altered the file in some other subtle way. sublime-syntax files are YAML, and as such they're sensitive to things like indentation.

Note also that doing anything in the Packages folder directly is a Bad Idea; modifying a sublime-package file works in the short term, but they're upgraded by removing them and replacing them. So unless you're the one that made the file in the first place, modifying the contents directly is a recipe for your change to be unceremoniously removed at some future point when you least expect it.

Making the following changes worked for me. This uses the OverrideAudit package to make the change (disclaimer: I am the package author). That will let you easily make the change in a safe way and also let you know if the underlying package ever gets upgraded.

  1. Install OverrideAudit
  2. From the Command Palette, select OverrideAudit: Create Override
  3. Select the SQL package, then the SQL.sublime-syntax file
  4. Use the find panel to search for comments: to see the context that contains all of the match patterns that represent comments. This should be around line 128, depending on what version of Sublime you're using

  comments:
    - match: "--"
      scope: punctuation.definition.comment.sql
      push:
        - meta_scope: comment.line.double-dash.sql
        - match: \n
          pop: true
    - match: "#"
      scope: punctuation.definition.comment.sql
      push:
        - meta_scope: comment.line.number-sign.sql
        - match: \n
          pop: true
    - match: /\*
      scope: punctuation.definition.comment.sql
      push:
        - meta_scope: comment.block.c
        - match: \*/
          pop: true

  1. Delete just the match rule that matches the comment style you don't want; make sure that you don't modify any other lines before or after or change the indent. The result should look like this when you're done:

  comments:
    - match: "--"
      scope: punctuation.definition.comment.sql
      push:
        - meta_scope: comment.line.double-dash.sql
        - match: \n
          pop: true
    - match: /\*
      scope: punctuation.definition.comment.sql
      push:
        - meta_scope: comment.block.c
        - match: \*/
          pop: true

  1. Save the syntax file.

As soon as you save the file, the change should take effect immediately. If you check the Sublime console with View > Show Console you should see a line that says generating syntax summary, which indicates that Sublime has seen and reloaded the syntax. If there's an error during this process, it will be displayed here.

After performing these steps, your sample text renders like this (using the Adaptive theme and the Monokai color scheme:

If you've previously modified the actual sublime-package file this may not work. In such a case you may need to do a reinstall of Sublime to get the original file back; doing so won't remove your settings. Alternatively you can download the Windows portable version from the Sublime website (even if you're not using windows) and get the pristine package from there to replace the one you modified.

这篇关于Sublime Text:如何更正 SQL Server 语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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