c++linuxc++17kde-plasmakate

How do I enable c++17 language in Kate text editor?


Meaning enabling proper syntax and error highlighting, and suggestions. I'm not building my program through Kate, only editing code.

When I try to write the following in Kate (in a file called main.cpp that Kate uses c++ syntax highlighting etc. on, but it must be using an older language version):

#include <filesystem>
//stuff
std::filesystem::path path;

, I get the error: [clang] (no member) No member named 'filesystem' in namespace 'std', which is almost identical to the error that Visual Studio gives if I try to use std::filesystem without changing the Language setting to c++17 (or later). But, I have no idea how to change to c++17 syntax highlighting in Kate, or if that's even possible.

I checked the documentation and googled, and checked all the results on stackoverflow that I could find, and went through all the menus, but I don't know enough about using Kate yet to be able to figure out how to enable c++17 language in Kate on my own, unfortunately.

edit: In Settings > Configure Kate > LSP Client > Default Server Settings it says:

"servers": {
    ...
    "c": {
        "command": ["clangd", "-log=error", "--background-index", "--limit-results=500", "--completion-style=bundled"],
        "commandDebug": ["clangd", "-log=verbose", "--background-index"],
        "url": "https://clang.llvm.org/extra/clangd/",
        "highlightingModeRegex": "^(C|ANSI C89|Objective-C)$"
    },
    "cpp": {
        "use": "c",
        "highlightingModeRegex": "^(C\\+\\+|ISO C\\+\\+|Objective-C\\+\\+)$"
    },

Solution

  • I know this question has been lying here for some time but, according to this answer or this answer in SO, you need to add -std=c++17 to clangd command, like this:

        "cpp": {
            "use": "c",
            "command": ["clangd", "-log=error", "--background-index",
                        "--limit-results=500", "--completion-style=bundled",
                        "-std=c++17"],
            "highlightingModeRegex": "^(C\\+\\+|ISO C\\+\\+-23|Objective-C\\+\\+)$"
        },
    

    I hope it works.