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

Integration with Swift Package Index #769

Open dschaefer2 opened 2 months ago

dschaefer2 commented 2 months ago

The Swift Package Index is a valuable resource for discovering gems in the Swift package ecosystem. The index web site has a cool feature that gives you code snippets that you can paste into your Package.swift to hook up the dependencies. It would be a great productivity enhancer if we could leverage the index with automations in VSCode with the help of sourcekit-lsp to discover and add these dependencies.

A potential solution would be to add a command that opens the Swift Package Index website in webview. We can inject Javascript into these pages to make the necessary calls to allow sourcekit-lsp to add dependencies to the package with the right URL and and version. https://github.com/apple/sourcekit-lsp/pull/1193 provides an example on how this could be done.

From there, there are two options to hook up the UI. We could inject HTML buttons and action code in the "Use this package" dialog. The better option is to work with the SPI team to add this code to the pages directly, detecting whether vscode was present and making the calls there.

The index also provides snippets for adding the target dependencies. I think that would better be done in the language server as the user is adding the target so I don't believe automation around that part of the index UI would be necessary. The user can still use the current Copy function there to add those manually in the meantime.

daveverwer commented 2 months ago

Hello @dschaefer2! I just got pinged with this thread. It's an interesting idea!

@finestructure and I run the Swift Package Index and we'd certainly rather be involved early with any plans you have. Would it be worth having a chat? Our Discord is probably the best place to say hi and we can start up a DM conversation or quick call there.

dschaefer2 commented 2 months ago

Thanks! Yeah, this could be really cool. I'm just thinking of ways of making the Package manifest easier to work with. I'm probably not the one that's going to be working on this though. I know @daveyc123 was taking a peak at it, or he may have someone else in mind.

daveverwer commented 2 months ago

Well, we're here (or there) whenever you need us! 👍