swiftlang / sourcekit-lsp

Language Server Protocol implementation for Swift and C-based languages
Apache License 2.0
3.32k stars 277 forks source link

Code actions are sorted alphabetically, making `try!` the first Fix-It option in VS Code #1696

Closed ahoppen closed 1 month ago

ahoppen commented 1 month ago

When I have the following code

func throwing() throws {}

func test() throws {
  throwing()
}

And invoke code actions on throwing(), then VS Code shows Did you mean to disable error propagation? as the first item, despite it being the worst of the three options. I assume that’s because it’s ordering code actions alphabetically. Is there a way to show them in the order that SourceKit-LSP returns them, which would show Did you mean to use 'try'? as the first option?

Screenshot 2024-09-19 at 17 58 47
plemarquand commented 1 month ago

The alphabetized response is actually coming directly from sourcekit-lsp. The code that sorts the returned code actions can be found here: https://github.com/swiftlang/sourcekit-lsp/blob/ffed667c538789daf6e15477f0c89a80a481d7eb/Sources/SourceKitLSP/Swift/SwiftLanguageService.swift#L847

If this response shouldn't be sorted I'd be happy to write up a PR.

ahoppen commented 1 month ago

Synced to Apple’s issue tracker as rdar://136373062