# Jump to definition not working very well in VSCode

**URL:** <https://forums.swift.org/t/jump-to-definition-not-working-very-well-in-vscode/70261>\
**Category:** VSCode Swift extension\
**Created:** [February 25, 2024, 12:55pm UTC](https://forums.swift.org/t/jump-to-definition-not-working-very-well-in-vscode/70261 "2024-02-25T12:55:29Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![hasen6](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/hasen6/32/34176_2.png) [@hasen6](https://forums.swift.org/u/hasen6)\
**Post date:** [February 25, 2024, 12:55pm UTC](https://forums.swift.org/t/jump-to-definition-not-working-very-well-in-vscode/70261/1 "2024-02-25T12:55:29Z")

</div>

I just started using the Swift extension in VSCode and noticed if I CMD click or hover the definition is not found. Which is weird since that is listed as one of the features of the extension...  
I found some information about adding server arguments to fix the situation, which does improve it a lot but still many definitions of methods within the project for some reason cannot be found. I'm yet to see a clear pattern and what works and what doesn't even. Are there any other server arguments that can be added to fix it even more?

```
"swift.sourcekit-lsp.serverArguments": [
    "-Xswiftc",
    "-sdk",
    "-Xswiftc",
    "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk",
    "-Xswiftc",
    "-target",
    "-Xswiftc",
    "arm64-apple-ios13.0-simulator",
]

```

---

<div class="post-metadata">

**Author:** ![adam-fowler](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/adam-fowler/32/9266_2.png) [@adam-fowler](https://forums.swift.org/u/adam-fowler)\
**Post date:** [February 26, 2024, 3:05pm UTC](https://forums.swift.org/t/jump-to-definition-not-working-very-well-in-vscode/70261/2 "2024-02-26T15:05:03Z")

</div>

Jump to definition only works once you have a built project. It also has to have been built with the same arguments as are passed to the LSP server. There is some support for doing this in the extension already. There is a command `Swift: Select Target Platform..` which allows you to select an iOS platform. This builds with the correct SDK and setups the LSP server with this SDK as well.

There is one gotcha with this though, Apple do not support building iOS projects with SwiftPM. There are multiple issues, you have to clean the project when switching between platforms because they use the same folders, building tests doesn't appear to work.

On top of that LSP functionality does sometimes fail when using SourceKit-LSP from Swift 5.9. You can use the command `Swift: Restart LSP Server` in those situations to get it running again.

---

<div class="post-metadata">

**Author:** ![hasen6](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/hasen6/32/34176_2.png) [@hasen6](https://forums.swift.org/u/hasen6)\
**Post date:** [February 26, 2024, 3:50pm UTC](https://forums.swift.org/t/jump-to-definition-not-working-very-well-in-vscode/70261/3 "2024-02-26T15:50:44Z")

</div>

Thanks for the reply. So basically what you're saying is you need to build a project first for it to work but there isn't really any way to do that? So in fact jump to definition doesn't in fact work?

EDIT: It seems the project I'm testing is an xcode project when it should be a swift package. That's the main reason the jump to definition does not work well? As I said before, I'm new to swift.

---

<div class="post-metadata">

**Author:** ![0xTim](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/0xtim/32/27968_2.png) [@0xTim](https://forums.swift.org/u/0xTim)\
**Post date:** [February 26, 2024, 4:50pm UTC](https://forums.swift.org/t/jump-to-definition-not-working-very-well-in-vscode/70261/4 "2024-02-26T16:50:26Z")

</div>

> [@hasen6](#):
>
> EDIT: It seems the project I'm testing is an xcode project when it should be a swift package. That's the main reason the jump to definition does not work well? As I said before, I'm new to swift.

How are you opening the project in VSCode? Do you have a Package.swift file?

---

<div class="post-metadata">

**Author:** ![vns](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/vns/32/37396_2.png) [@vns](https://forums.swift.org/u/vns)\
**Post date:** [February 26, 2024, 5:07pm UTC](https://forums.swift.org/t/jump-to-definition-not-working-very-well-in-vscode/70261/5 "2024-02-26T17:07:02Z")

</div>

Swift LSP requires building to work correctly. That has some implementation reasoning behind this, but I do not remember which exactly. Hopefully it could be fixed at some point, yet currently that is the state.

With Xcode projects (and basically all SDK dependant code) it is a lot worse situation. Swift LSP is concerned only about Swift, obviously :) Some iOS/macOS/etc app has set of its own dependencies and build artifacts. I have tried in light of NeoVim some solutions, that try to be-friend Xcode build artifacts, but it wasn't the best experience. So if you want to write iOS app, better to use Xcode. If not, all you need is to run `swift test`.

---

<div class="post-metadata">

**Author:** ![hasen6](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/hasen6/32/34176_2.png) [@hasen6](https://forums.swift.org/u/hasen6)\
**Post date:** [February 26, 2024, 5:18pm UTC](https://forums.swift.org/t/jump-to-definition-not-working-very-well-in-vscode/70261/6 "2024-02-26T17:18:46Z")

</div>

> [@0xTim](#):
>
> How are you opening the project in VSCode? Do you have a Package.swift file?

No, it's an xcode project and that seems to be part of the problem. I didn't realise vscode couldn't deal with regular xcode projects.

---

<div class="post-metadata">

**Author:** ![0xTim](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/0xtim/32/27968_2.png) [@0xTim](https://forums.swift.org/u/0xTim)\
**Post date:** [February 26, 2024, 6:22pm UTC](https://forums.swift.org/t/jump-to-definition-not-working-very-well-in-vscode/70261/7 "2024-02-26T18:22:58Z")

</div>

Yeah that will cause issues. It's possible to build Xcode projects with some of the configuration that Adam spoke about, but the extension is very much focused on Swift packages

---

<div class="post-metadata">

**Author:** ![adam-fowler](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/adam-fowler/32/9266_2.png) [@adam-fowler](https://forums.swift.org/u/adam-fowler)\
**Post date:** [February 26, 2024, 8:05pm UTC](https://forums.swift.org/t/jump-to-definition-not-working-very-well-in-vscode/70261/8 "2024-02-26T20:05:19Z")

</div>

VSCode and SourceKit-LSP do not recognise Xcode projects. You have to create a Package.swift that includes all the files in your project if you want LSP features to work.

---

<div class="post-metadata">

**Author:** ![Mike](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/mike/32/15284_2.png) [@Mike](https://forums.swift.org/u/Mike)\
**Post date:** [February 6, 2025, 5:22pm UTC](https://forums.swift.org/t/jump-to-definition-not-working-very-well-in-vscode/70261/9 "2025-02-06T17:22:37Z")

</div>

Ho do you run `swift build` for ios? the swift build is for macOS every time I I get no `such module 'UIKit'` (that makes sense as as there is no UIkit in macOS). I tried some work arounds:  
` swift build --arch arm64 -Xswiftc -sdk -Xswiftc /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS18.1.sdk -Xswiftc -target -Xswiftc arm64-apple-ios18.0`  
But it emits some other errors. Strange

---

<div class="post-metadata">

**Author:** ![451222664](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/451222664/32/40418_2.png) [@451222664](https://forums.swift.org/u/451222664)\
**Post date:** [April 7, 2025, 9:54am UTC](https://forums.swift.org/t/jump-to-definition-not-working-very-well-in-vscode/70261/10 "2025-04-07T09:54:27Z")

</div>

I've also encountered the "Jump to definition not working" issue. I'm using CocoaPods to integrate project component code, and I can successfully run the iOS project through SWEETPAD and the generated buildServer.json, but I'm unable to click and jump to function definitions.

---

<div class="post-metadata">

**Author:** ![SoySauceFor3](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/soysaucefor3/32/44627_2.png) [@SoySauceFor3](https://forums.swift.org/u/SoySauceFor3)\
**Post date:** [February 25, 2026, 6:27pm UTC](https://forums.swift.org/t/jump-to-definition-not-working-very-well-in-vscode/70261/12 "2026-02-25T18:27:36Z")

</div>

I installed the “SweetPad” extension, and after running `Sweetpad: Generate Build Server Config` which generates `buildServer.json`, I built the app in vscode and all the reference/definitions/documentation starts to work.

This is the url of the extension: [https://sweetpad.hyzyla.dev/](https://sweetpad.hyzyla.dev/)

---

<div class="post-metadata">

**Author:** ![maqboolkhan](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/maqboolkhan/32/44628_2.png) [@maqboolkhan](https://forums.swift.org/u/maqboolkhan)\
**Post date:** [February 25, 2026, 10:45pm UTC](https://forums.swift.org/t/jump-to-definition-not-working-very-well-in-vscode/70261/13 "2026-02-25T22:45:23Z")

</div>

Thank you so much, SweetPad is game changer :-)
