# SourceKit-LSP and Obj-C headers indexing?

**URL:** <https://forums.swift.org/t/sourcekit-lsp-and-obj-c-headers-indexing/80213>\
**Category:** SourceKit-LSP\
**Created:** [May 30, 2025, 9:32am UTC](https://forums.swift.org/t/sourcekit-lsp-and-obj-c-headers-indexing/80213 "2025-05-30T09:32:34Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![rockbruno](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/rockbruno/32/41051_2.png) [@rockbruno](https://forums.swift.org/u/rockbruno)\
**Post date:** [May 30, 2025, 9:32am UTC](https://forums.swift.org/t/sourcekit-lsp-and-obj-c-headers-indexing/80213/1 "2025-05-30T09:32:34Z")

</div>

I've been working on a BSP to connect sourcekit-lsp and Bazel, and I ran into something involving headers that I wanted to check with you folks what I'm supposed to do.

I've had no issue getting sourcekit-lsp to process and index Swift targets and .m files, but all my header files are "raw":

 ![Screenshot 2025-05-30 at 11.21.35](https://global.discourse-cdn.com/swift/original/3X/5/a/5a3bb0427b5fff4f9136059debbbab8b0c4610b5.png)

The way I'm approaching this is that I have `build/sources` return all header/implementations for Obj-C with the appropriate tags, and then returning the compilation options for the implementation while returning `nil` for the headers.

This causes the implementation / swift files to correctly point to header file, but the header file itself has no indexing as you can see in the picture. According to the docs sourcekit-lsp should be automatically trying to figure out how to index the header by finding a associated "main file", but I wonder what I've messed up to cause this to not work.

---

<div class="post-metadata">

**Author:** ![bnbarham](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/bnbarham/32/17708_2.png) [@bnbarham](https://forums.swift.org/u/bnbarham)\
**Post date:** [May 30, 2025, 11:58pm UTC](https://forums.swift.org/t/sourcekit-lsp-and-obj-c-headers-indexing/80213/2 "2025-05-30T23:58:21Z")

</div>

> I've been working on a BSP to connect sourcekit-lsp and Bazel

Very cool :)!

> According to the docs sourcekit-lsp should be automatically trying to figure out how to index the header by finding a associated "main file"

That should be the case, see eg. `ClangLanguageService.buildSettings`. Is it possible that we haven't finished indexing the files that include the header?

You can also have a look at (or include here) the [extended logging](https://github.com/swiftlang/sourcekit-lsp/blob/main/Documentation/Enable%20Extended%20Logging.md), which should hopefully give us a better idea about what's going on.

---

<div class="post-metadata">

**Author:** ![rockbruno](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/rockbruno/32/41051_2.png) [@rockbruno](https://forums.swift.org/u/rockbruno)\
**Post date:** [May 31, 2025, 8:19am UTC](https://forums.swift.org/t/sourcekit-lsp-and-obj-c-headers-indexing/80213/3 "2025-05-31T08:19:50Z")

</div>

Thanks Ben! I can see with the extended logging that it's failing to find the main file. I think it's probably the compiler arguments I return for the .m file then, as looking at Xcode I can see that what sourcekit-lsp is trying to build is slightly different from Xcode (there are some missing index flags from my side among other things). I'll try to add these each of these individually then and see which ones do the trick, will return here once I find out :)

---

<div class="post-metadata">

**Author:** ![rockbruno](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/rockbruno/32/41051_2.png) [@rockbruno](https://forums.swift.org/u/rockbruno)\
**Post date:** [May 31, 2025, 10:52am UTC](https://forums.swift.org/t/sourcekit-lsp-and-obj-c-headers-indexing/80213/4 "2025-05-31T10:52:24Z")

</div>

Passing `-x objective-c` at the beginning and `-index-store-path {path} -working-directory {root}` did the trick 🙂 Interestingly the color scheme for .m and .h files are different because Cursor is assuming the header is a C++ file, but that's probably something on my side so I'll ignore that for now. Thanks for the help Ben!

 ![Screenshot 2025-05-31 at 12.50.14](https://global.discourse-cdn.com/swift/original/3X/b/c/bcb7484eb1d7b1aa5293ee927714c07d68c340fd.png)

 ![Screenshot 2025-05-31 at 12.50.22](https://global.discourse-cdn.com/swift/original/3X/f/a/fac187fe17430d8f168f460013ccf499a167397b.png)

---

<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:** [June 2, 2025, 4:32am UTC](https://forums.swift.org/t/sourcekit-lsp-and-obj-c-headers-indexing/80213/5 "2025-06-02T04:32:04Z")

</div>

Very cool to see you using the BSP integration for Bazel. 🤩

Interesting that `-x objective-c` is needed. Do you also need to set `-x objective-c` when building the project? If not, you shouldn’t need to pass it to SourceKit-LSP either. If you are willing to share extended logging without `-x objective-c`, I would be interested to see it to figure out what’s going on here.

`-index-store-path` should no longer be needed with SourceKit-LSP in Swift 6.2. I fixed that issue in [If a build server doesn’t specify `-index-store-path` in the SourceKit options, add it during background indexing by ahoppen · Pull Request #2000 · swiftlang/sourcekit-lsp · GitHub](https://github.com/swiftlang/sourcekit-lsp/pull/2000).

And finally regarding `-working-directory`, that also shouldn’t be necessary if you return a `workingDirectory` in the `TextDocumentSourceKitOptionsResult` as documented in [sourcekit-lsp/Contributor Documentation/BSP Extensions.md at main · swiftlang/sourcekit-lsp · GitHub](https://github.com/swiftlang/sourcekit-lsp/blob/main/Contributor%20Documentation/BSP%20Extensions.md#textdocumentsourcekitoptions). Does that not work for you?

---

<div class="post-metadata">

**Author:** ![roland-reed](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/roland-reed/32/43689_2.png) [@roland-reed](https://forums.swift.org/u/roland-reed)\
**Post date:** [December 8, 2025, 3:06am UTC](https://forums.swift.org/t/sourcekit-lsp-and-obj-c-headers-indexing/80213/6 "2025-12-08T03:06:40Z")

</div>

Hi, we used to use -index-store-path and -index-db-path to boost up symbol lookup in VSCode, but recently we found the LSP will crash immediately after startup, I saw this post and found that you removed `-index-store-path` option (and may be also `-index-db-path`?), are there any alternatives for these two options in Swift 6.2? Thanks!

---

<div class="post-metadata">

**Author:** ![rockbruno](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/rockbruno/32/41051_2.png) [@rockbruno](https://forums.swift.org/u/rockbruno)\
**Post date:** [December 8, 2025, 7:59am UTC](https://forums.swift.org/t/sourcekit-lsp-and-obj-c-headers-indexing/80213/7 "2025-12-08T07:59:54Z")

</div>

I don't think anything changed on that front, the LSP automatically adds / keeps -index-store-path depending on what you provided to it. [sourcekit-lsp/Sources/SemanticIndex/UpdateIndexStoreTaskDescription.swift at d449cb78be1a001ae4efd8dd023da8301eb2af0a · swiftlang/sourcekit-lsp · GitHub](https://github.com/swiftlang/sourcekit-lsp/blob/d449cb78be1a001ae4efd8dd023da8301eb2af0a/Sources/SemanticIndex/UpdateIndexStoreTaskDescription.swift#L413)
