Skip to content

Conversation

@award999
Copy link

@award999 award999 commented Nov 7, 2025

Needed to get playground support into SourceKit-LSP: swiftlang/sourcekit-lsp#2340

Needed to get playground support into SourceKit-LSP: swiftlang/sourcekit-lsp#2340
/// This property is always present whether the `Playground` has a `label` or not.
///
/// Follows the format output by `swift play --list`.
public var id: String
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this needs to capture either the corresponding product or target as well so that the playground can be executed in the appropriate context

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@owenv the LSP code that parses these does include the target https://github.com/swiftlang/sourcekit-lsp/pull/2340/files#diff-d76b1dc09dd52af2a88684043d44d1e5261f013c09f6137dffd4e23aebce6e56R91 but do you want the comment code to reflect the expected format?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a better explanation about id but let me know if there is more you wanted

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, so it seems like the playgrounds implementation is building a dylib composed of every target in the package and linking the runner against that. This will work in small examples, but in general it's not safe to assume all the targets in a package can be safely linked into a single image. e.g. they may have different platform requirements, conflicting static initializers, multiple copies of a binary dependency built from the same sources, etc. I think sourcekit-lsp will need to pick a single specific appropriate library product containing the playground's code, thread that through to the play command, and adjust the build of the runner accordingly

Copy link
Member

@ahoppen ahoppen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple small comments, otherwise LGTM.

Comment on lines +48 to +49
case .dictionary(let locationDict) = dictionary["location"],
let location = Location(fromLSPDictionary: locationDict)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be shortened slightly.

Suggested change
case .dictionary(let locationDict) = dictionary["location"],
let location = Location(fromLSPDictionary: locationDict)
let location = Location(fromLSPAny: dictionary["location"])

/// location of the playground and identifiers to allow executing the playground through a "swift play" command.
///
/// **(LSP Extension)**
public struct Playground: ResponseType, Equatable, LSPAnyCodable {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn’t used anywhere yet, right? Do you want to introduce the workspace/playgrounds request in this PR already or in a follow-up PR? I’m fine with either.

Comment on lines +48 to +49
case .dictionary(let rangeDict) = dictionary["range"],
let range = Range<Position>(fromLSPDictionary: rangeDict)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, we can use the init(fromLSPAny:) convenience initializer.

Suggested change
case .dictionary(let rangeDict) = dictionary["range"],
let range = Range<Position>(fromLSPDictionary: rangeDict)
let range = Range<Position>(fromLSPAny: dictionary["range"])

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants