swiftlang / vscode-swift

Visual Studio Code Extension for Swift
https://marketplace.visualstudio.com/items?itemName=sswg.swift-lang
Apache License 2.0
709 stars 47 forks source link

Issues when a folder contains multiple Swift packages #768

Open svanimpe opened 2 months ago

svanimpe commented 2 months ago

To Reproduce

Steps to reproduce the behavior (in an empty directory):

mkdir first && cd first && swift package init --type executable
cd ..
mkdir second && cd second && swift package init --type executable
cd ..
code .

In other words, create a project structure like this, then open it in VS Code:

.
├── first
│   ├── Package.swift
│   └── Sources
│       └── main.swift
└── second
    ├── Package.swift
    └── Sources
        └── main.swift

Issues

Open a Package.swift file. When using Swift 5.9, features such as autocompletion don't work in this file. With Swift 6.0, I get the following additional error:

Screenshot 2024-04-25 at 11 19 43

Workaround

Open first or second separately in VS Code. Everything works fine then.

Environment

svanimpe commented 2 months ago

This seems to be a general issue with Swift packages in a subfolder, not just folders that contain multiple packages. I also have this issue in directories that contain, for example, one Swift package, and one NPM project.

adam-fowler commented 2 months ago

@svanimpe I think this is another sourcekit-lsp issue. It looks like it has been around for a while, but without the underlined import

adam-fowler commented 2 months ago

I've added https://github.com/apple/sourcekit-lsp/issues/1210

svanimpe commented 2 months ago

Thanks Adam!

award999 commented 1 month ago

@svanimpe just curious, does it work if you setup a multi-root workspace (https://code.visualstudio.com/docs/editor/workspaces#_multiroot-workspaces) which contains the various folders?