# Semantic highlighting in Objective-C seems completely wrong

**URL:** <https://forums.swift.org/t/semantic-highlighting-in-objective-c-seems-completely-wrong/88656>\
**Category:** SourceKit-LSP\
**Created:** [July 30, 2026, 12:39pm UTC](https://forums.swift.org/t/semantic-highlighting-in-objective-c-seems-completely-wrong/88656 "2026-07-30T12:39:27Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![jansorg](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/jansorg/32/42900_2.png) [@jansorg](https://forums.swift.org/u/jansorg)\
**Post date:** [July 30, 2026, 12:39pm UTC](https://forums.swift.org/t/semantic-highlighting-in-objective-c-seems-completely-wrong/88656/1 "2026-07-30T12:39:27Z")

</div>

The attached Objective-C `main.m` file seems to get completely wrong semantic highlighting.

I tested this with a buildserver-enabled project and also with a fresh, compilation-database project + SourceKit LSP. VSCode had shown the same token types and modifiers.

Swift 6.3.3 with both Xcode and Swiftly toolchain on Linux (Swiftly) and macOS (both).

I noticed a translation of token types in the log.

Is it possible that there's a missing (reverse) mapping?

Interpreting the SourceKit token type values as clangd values would show a much more reasonable highlighting (e.g. "class" instead of "parameter" for mapping "8: 2"). If that's true, then it would indicate a missing mapping of types received by clangd to the SourceKit LSP types, as far as I understand.

Thanks!

```objectivec
#import <Foundation/Foundation.h>

@interface MyClass: NSObject // <- "MyClass" is "parameter", "NSObject" is "parameter"

@end

@implementation MyClass // <- "MyClass" is "parameter"

@end

int main(int argc, char* argv[]) { // <- "main" is "type", "argc" is "variable"

}	

```

Legend emitted by SourceKit LSP via dynamic registration

```json
          "legend": {
            "tokenModifiers": [
              "declaration",
              "definition",
              "deprecated",
              "deduced",
              "readonly",
              "static",
              "abstract",
              "virtual",
              "dependentName",
              "defaultLibrary",
              "usedAsMutableReference",
              "usedAsMutablePointer",
              "constructorOrDestructor",
              "userDefined",
              "functionScope",
              "classScope",
              "fileScope",
              "globalScope"
            ],
            "tokenTypes": [
              "variable",
              "variable",
              "parameter",
              "function",
              "method",
              "function",
              "property",
              "variable",
              "class",
              "interface",
              "enum",
              "enumMember",
              "type",
              "type",
              "unknown",
              "namespace",
              "typeParameter",
              "concept",
              "type",
              "macro",
              "modifier",
              "operator",
              "bracket",
              "label",
              "comment"
            ]
          }

```

clangd -\> SourceKit translations from the Log:

```swift
2026-07-30 14:04:28.894227+0200 0x3af211 Info 0x0 55926 0 sourcekit-lsp: [org.swift.sourcekit-lsp:notification-2] clangd token type translations (1/1)
0: 8
1: 8
2: 7
3: 12
4: 13
5: 12
6: 9
7: 8
8: 2
9: 4
10: 3
11: 10
12: 1
13: 1
14: 26
15: 0
16: 6
17: 25
18: 1
19: 14
20: 16
22: 23
23: 24
24: 17

2026-07-30 14:04:28.894242+0200 0x3af211 Info 0x0 55926 0 sourcekit-lsp: [org.swift.sourcekit-lsp:notification-2] clangd token modifier translations (1/1)
2: 4
3: 10
4: 2
5: 3
6: 5
7: 11
8: 12
10: 13
11: 14
12: 15
13: 16
14: 17
15: 18
16: 19
17: 20

```

---

<div class="post-metadata">

**Author:** ![dima\_kozhinov](https://avatars.discourse-cdn.com/v4/letter/d/258eb7/32.png) [@dima\_kozhinov](https://forums.swift.org/u/dima_kozhinov)\
**Post date:** [July 30, 2026, 2:32pm UTC](https://forums.swift.org/t/semantic-highlighting-in-objective-c-seems-completely-wrong/88656/2 "2026-07-30T14:32:18Z")

</div>

Does sourcekit-lsp highlight Objective-C code as if it were Swift code?

---

<div class="post-metadata">

**Author:** ![jansorg](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/jansorg/32/42900_2.png) [@jansorg](https://forums.swift.org/u/jansorg)\
**Post date:** [July 30, 2026, 2:38pm UTC](https://forums.swift.org/t/semantic-highlighting-in-objective-c-seems-completely-wrong/88656/3 "2026-07-30T14:38:09Z")

</div>

I'm not sure how I could find out if it does.

But I don't think so, I see diagnostics, hover data, etc. which are expected for Objective-C code and which seem valid.

---

<div class="post-metadata">

**Author:** ![jansorg](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/jansorg/32/42900_2.png) [@jansorg](https://forums.swift.org/u/jansorg)\
**Post date:** [July 31, 2026, 8:29am UTC](https://forums.swift.org/t/semantic-highlighting-in-objective-c-seems-completely-wrong/88656/4 "2026-07-31T08:29:53Z")

</div>

> [@jansorg](#):
>
> `clangd token type translations`

At least according to the sources, there should be a translation of clangd token types to LSP token types. I'm not sure what's wrong (clangd itself, the translation, or something else), but I haven't seen expected highlighting for Objective-C sources yet.

> <https://github.com/noctule-ide/sourcekit-lsp/blob/80d2c143cac7da4f76341435ec827090b6223e19/Sources/ClangLanguageService/ClangLanguageService.swift#L542>

---

<div class="post-metadata">

**Author:** ![ahoppen](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/ahoppen/32/36046_2.png) [@ahoppen](https://forums.swift.org/u/ahoppen)\
**Post date:** [July 31, 2026, 10:13am UTC](https://forums.swift.org/t/semantic-highlighting-in-objective-c-seems-completely-wrong/88656/5 "2026-07-31T10:13:47Z")

</div>

This sounds like it might be [SourceKit-LSP overrides syntax highlighting provided by clangd · Issue #2643 · swiftlang/sourcekit-lsp · GitHub](https://github.com/swiftlang/sourcekit-lsp/issues/2643), which was fixed in [Always advertise the SourceKit-LSP semantic tokens legend by Steffeeen · Pull Request #2712 · swiftlang/sourcekit-lsp · GitHub](https://github.com/swiftlang/sourcekit-lsp/pull/2712). Could you check if you’re still seeing the issue in the latest nightly main snapshot?

---

<div class="post-metadata">

**Author:** ![jansorg](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/jansorg/32/42900_2.png) [@jansorg](https://forums.swift.org/u/jansorg)\
**Post date:** [July 31, 2026, 3:12pm UTC](https://forums.swift.org/t/semantic-highlighting-in-objective-c-seems-completely-wrong/88656/6 "2026-07-31T15:12:37Z")

</div>

With the latest main-snapshot (6.5) the highlighting is better, so it's seems like it's the same bug.

I couldn't see that on GitHub, but would the fix also land with Swift 6.4 or only later with 6.5?

Thank you!

---

<div class="post-metadata">

**Author:** ![ahoppen](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/ahoppen/32/36046_2.png) [@ahoppen](https://forums.swift.org/u/ahoppen)\
**Post date:** [August 3, 2026, 11:42am UTC](https://forums.swift.org/t/semantic-highlighting-in-objective-c-seems-completely-wrong/88656/7 "2026-08-03T11:42:43Z")

</div>

The fix is currently only in `main`, so it won’t be part of the 6.4 release.
