镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

[feature request] disable semantic colouring by default #3419

Open

Description

@iamqiz

How are you using the lua-language-server?

Other

Which OS are you using?

Windows

What is the issue affecting?

Other

Expected Behaviour

我在用Qt creator,昨天用lua编写插件,然后下载了Dracula / oneDark pro 两个主题插件,
结果发现lua的local function return 等关键词老是和注释一样的颜色,见下图

Image

然后禁用主题插件之后,发现也不是主题插件导致的(默认主题下关键词也会跟注释一样颜色)
经过一天的折腾,到了晚上终于发现是lua language server 插件导致的,
一查这个插件,发现是qt 官方出品,

Image

然后我就到qt creator论坛反馈bug, 结果发帖被判定为垃圾信息无法发帖,
然后就通过帮助菜单下找到了反馈bug的地方.

今天突然想到可能是language server导致的,就在本项目issue里搜索,发现了一个类似的issue:
#3318
按照 tomlau10 的方法,
#3318 (comment)
我在 .luarc.json 里禁用了 semantic.enable , 高亮终于正常了.
我看了一下luaLS wiki, semantic.keyword 默认关闭的,我项目也没开启, luaLS居然能影响关键词..

谁能想到一个language server居然能影响语法高亮,
谁能想到一个language server居然把关键词和注释弄成一个颜色,

所以我建议默认关闭 semantic.enable ,😭

Actual Behaviour

.

Reproduction steps

.

Additional Notes

No response

Log File

No response

Activity

  1. tomlau10 commented on Jun 13, 2026

    @tomlau10
    Contributor

    我看了一下luaLS wiki, semantic.keyword 默认关闭的

    你可能是查了 github 上的舊 wiki?
    目前來說這個字段預設是打開的
    https://luals.github.io/wiki/settings/#semanticenable


    谁能想到一个language server居然能影响语法高亮,
    谁能想到一个language server居然把关键词和注释弄成一个颜色,

    我對 language server 的了解很淺,但我理解 lang server 並非改變語法高亮,只是改變了 token 的 type

    • 以 vscode 來說,預設是 textmate (regex 方式?) 來判斷 token type,這不一定準確的
    • 而 language server 在 "理解" 代碼後,會返回 semantic type,理論上應該更準確

    我剛試了下 qt creator editor,確實有這問題。。。
    但 vscode 上一切正常的
    我個人猜測是 Qt creator 無法處理 semantic token type 😇

    以下是 google ai mode 的回覆
    https://share.google/aimode/TzE2O3ychHp8XzGAk

    toggle

    這是一個非常經典的跨編輯器語法解析衝突問題。
    簡單來說,會造成這種現象,是因為 Qt Creator 處理「語法標籤」的機制沒有 VS Code 那麼聰明,導致兩者在解讀 Lua 語言伺服器(LSP)傳回來的資料時出現了落差。
    以下是為什麼關掉它就正常,以及為什麼 VS Code 沒事的底層原因:

    1. 什麼是 Semantic Highlighting(語意高亮)?

    傳統的代碼顏色(如 Qt Creator 內建的)只靠正則表達式(TextMate 語法規則)。它只看字面,例如看到 function 就塗藍色,看到雙引號 "" 就塗綠色。
    而語言伺服器(lua-language-server)開啟語意高亮後,會把代碼讀進記憶體做完整的「深度分析」,然後傳給編輯器一堆特殊的 Tokens(標籤),例如:「第 5 行第 3 個字是一個全域變數」、「第 10 行是一個自訂函式」。 [1]

    2. 為什麼 Qt Creator 會「亂掉」?

    當 Qt Creator 收到這些高級標籤時,它會試圖把這些標籤對應到你目前使用的編輯器主題顏色(Color Theme)。 [1]
    問題就出在這裡:

    • 標籤對應失敗(Mapping Gap):Lua LSP 丟出了很多 Lua 特有的語意標籤,但 Qt Creator 內建的主題根本沒有定義這些標籤該上什麼顏色。 [1, 2]
    • 強制覆蓋(Fallback 錯誤):當 Qt Creator 不知道該上什麼顏色時,它不會聰明地「保留原本的顏色」,而是經常用預設的純文字顏色(例如全白或全黑)直接把原本好好的顏色覆蓋掉(Override),導致整個畫面色彩變得很奇怪、甚至一片慘白。 [3]

    當你設定 "semantic.enable": false 後,就是叫 Lua 伺服器不要再傳這些高級標籤過來,Qt Creator 就乖乖用回原本的靜態規則,顏色自然就恢復正常了。

    3. 為什麼 VS Code 打開都正常?

    VS Code 是 LSP(語言伺服器協定)的親生父母(微軟開發),它對這套機制的支援度極高:

    • 完美的語意映射表:VS Code 的主題系統非常成熟。當 Lua LSP 傳來一個特殊的 Token(例如 variable.lua),VS Code 內部有一套強大的降級機制(Fallback hierarchy)。如果主題沒定義這個特殊的 Lua 變數顏色,它會自動降級去使用通用變數 variable 的顏色,絕對不會直接抹煞顏色。 [2]
    • 專門的插件優化:你在 VS Code 裡通常會安裝專用的 Lua 擴充套件,這些套件已經幫你把 lua-language-server 的所有語意標籤與 VS Code 各大熱門主題做好了手工對齊。而 Qt Creator 的 Language Client 現階段還比較通用、陽春,缺乏這種針對單一語言的精細調校。 [4]

    總結

    這不是 Lua 伺服器的錯,而是 Qt Creator 的 LSP 客戶端在處理「語意標籤顏色轉換」時不夠完善。在 Qt Creator 裡關掉它、專心讓伺服器處理「跳轉、自動補全」,把「畫顏色」留給 IDE 自己,是最靈巧也最省心的做法。 [1]
    如果想進一步調整,我可以和您分享:

    • 如何在 Qt Creator 裡手動擴充 Lua 的 MIME 類型
    • 怎麼在 Qt Creator 內建的 Inspect Language Clients 視窗裡查看伺服器到底傳了什麼資料 [5]

    [1] [https://github.com/](eclipse-lsp4e/lsp4e#821)
    [2] [https://www.reddit.com](https://www.reddit.com/r/neovim/comments/11l5msb/anyone_got_their_syntax_highlighting_messed_up/)
    [3] [https://github.com/](microsoft/pylance-release#7959)
    [4] [https://doc.qt.io](https://doc.qt.io/qtcreator/creator-language-servers.html)
    [5] [https://docs.huihoo.com](https://docs.huihoo.com/qt/qtcreator/10.x/creator-language-servers.html)

    所以我建议默认关闭 semantic.enable ,😭

    luals 本身也只說明針對 vscode 的 (?) 所以其他 editor 出錯的話,估計不會因此處理


    PS: 我只是 contributor 不是 maintainer

  2. Issues-translate-bot commented on Jun 13, 2026

    @Issues-translate-bot

    Sumneko Lua translate bot


    I looked at the luaLS wiki and semantic.keyword is turned off by default.

    Maybe you checked the old wiki on github?
    Currently, this field is turned on by default
    https://luals.github.io/wiki/settings/#semanticenable


    Who would have thought that a language server could actually affect syntax highlighting?
    Who would have thought that a language server would actually make keywords and comments the same color?

    My understanding of language server is very shallow, but I understand that lang server does not change the syntax highlighting, but only changes the type of the token.

    • For vscode, the default is textmate (regex method?) to determine the token type, which may not be accurate.
    • The language server will return semantic type after "understanding" the code, which should be more accurate in theory.

    I just tried qt creator editor and I did have this problem. . .
    But everything works fine on vscode
    My personal guess is that Qt creator cannot handle semantic token type 😇

    The following is the reply from google ai mode
    https://share.google/aimode/TzE2O3ychHp8XzGAk

    toggle

    This is a very classic cross-editor syntax parsing conflict problem.
    Simply put, this phenomenon occurs because Qt Creator's mechanism for processing "grammar tags" is not as smart as VS Code, resulting in a gap between the two in interpreting the data returned by the Lua Language Server (LSP).
    Here's the underlying reason why turning it off works, and why VS Code is fine:

    1. What is Semantic Highlighting?

    Traditional code colors (such as those built into Qt Creator) rely solely on regular expressions (TextMate syntax rules). It only looks at the literals. For example, it will be colored blue when it sees function, and it will be colored green when it sees double quotes "".
    When the language server (lua-language-server) turns on semantic highlighting, it will read the code into memory for complete "in-depth analysis", and then pass a bunch of special Tokens (tags) to the editor, for example: "The third word on line 5 is a global variable", "Line 10 is a custom function". [1]

    2. Why does Qt Creator get "messed up"?

    When Qt Creator receives these advanced tags, it will try to map these tags to the editor theme color (Color Theme) you are currently using. [1]
    The problem lies here:

    • Label mapping failure (Mapping Gap): Lua LSP throws out a lot of Lua-specific semantic labels, but the built-in theme of Qt Creator does not define what color these labels should be at all. [1, 2]
    • Forced override (Fallback error): When Qt Creator does not know what color to add, it will not "keep the original color" smartly. Instead, it will often use the default pure text color (such as all white or all black) to directly override the original good color (Override), causing the color of the entire screen to become very strange or even pale. [3]

    When you set "semantic.enable": false, you tell the Lua server not to send these advanced tags, and Qt Creator will revert to the original static rules, and the colors will naturally return to normal.

    3. Why does VS Code open normally?

    VS Code is the biological parent (developed by Microsoft) of LSP (Language Server Protocol), and it has extremely high support for this mechanism:

    • Perfect semantic mapping table: VS Code’s theme system is very mature. When Lua LSP passes a special Token (such as variable.lua), VS Code has a powerful fallback mechanism (Fallback hierarchy). If the theme does not define this special Lua variable color, it will automatically downgrade to use the color of the general variable variable and will never directly erase the color. [2]
    • Special plug-in optimization: You usually install special Lua extension kits in VS Code. These kits have helped you manually align all the semantic tags of lua-language-server with VS Code's major popular themes. However, Qt Creator's Language Client is still relatively generic and crude at this stage, lacking such fine tuning for a single language. [4]

    Summary

    This is not the Lua server's fault, but Qt Creator's LSP client's handling of "semantic tag color conversion" is not perfect enough. Turning it off in Qt Creator, focusing on letting the server handle "jumping, auto-completion", and leaving "painting colors" to the IDE itself is the most flexible and worry-free approach. [1]
    If you want to tweak it further, I can share it with you:

    • How to manually expand Lua's MIME type in Qt Creator
    • How to check what data is sent by the server in the Inspect Language Clients window built into Qt Creator [5]

    [1] [https://github.com/](eclipse-lsp4e/lsp4e#821)
    [2] [https://www.reddit.com](https://www.reddit.com/r/neovim/comments/11l5msb/anyone_got_their_syntax_highlighting_messed_up/)
    [3] [https://github.com/](microsoft/pylance-release#7959)
    [4] [https://doc.qt.io](https://doc.qt.io/qtcreator/creator-language-servers.html)
    [5] [https://docs.huihoo.com](https://docs.huihoo.com/qt/qtcreator/10.x/creator-language-servers.html)

    So I recommend turning off semantic.enable by default,😭

    luals itself only specifies (?) for vscode, so if other editors make errors, they probably won’t be dealt with accordingly.


    PS: I am just a contributor, not a maintainer

  3. iamqiz commented on Jun 13, 2026

    @iamqiz
    Author

    @tomlau10 谢谢您之前的回复我才解决了问题!

    你可能是查了 github 上的舊 wiki?
    目前來說這個字段預設是打開的

    我说的默认关闭的是 semantic.keyword 这个,

    Image

    既然默认关闭,我也没开启,且vscode 正常.那么导致 关键词和注释一样颜色的原因可能真是你说的"無法處理 semantic token type",
    或者可能是qt creator插件没处理好 LS返回的数据 (插件版本才1.0.0 😅)

  4. tomlau10 commented on Jun 13, 2026

    @tomlau10
    Contributor

    我说的默认关闭的是 semantic.keyword 这个,

    🙈 喔~ 不好意思我看錯了


    嗯~ 暫時最有可能的解釋,是 qt creator 不支持 semantic token type 🫠

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions