clangd: Incorrect Semantic Token Type Using LibFmt

#define FMT_HEADER_ONLY
#include <fmt/format.h>

enum class TestEnum
{
    E1,
    E2,
    E3,
    E4,
    E5,
    E6,
};

template <typename FormatContext>
static auto FormatEnum(const TestEnum& type, FormatContext& ctx) -> decltype(ctx.out())
{
    switch (type)
    {
    case TestEnum::E1:
        return fmt::format_to(ctx.out(), "1");
    case TestEnum::E2:
        return fmt::format_to(ctx.out(), "2");
    case TestEnum::E3:
        return fmt::format_to(ctx.out(), "3");
    case TestEnum::E4:
        return fmt::format_to(ctx.out(), "4");
    case TestEnum::E5:
        return fmt::format_to(ctx.out(), "5");
    case TestEnum::E6:
        return fmt::format_to(ctx.out(), "6");
    }
}

Some function calls are not labelled with correct semantic token type: image

However, hover window seems to work correctly: image

The following is a self-contained repro including libfmt headers and compile_commands.json clangd_bug.zip

System information

Output of clangd --version: clangd-14

Editor/LSP plugin: vscode 1.66.0

Operating system: WSL2 Ubuntu 20.04

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 15

Most upvoted comments