apple / sourcekit-lsp

Language Server Protocol implementation for Swift and C-based languages

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Code folding improvements + bugs

NSExceptional opened this issue · comments

  • Multi-line collections cannot be folded at all
  • Individual cases in a switch cannot be folded at all
  • This range folds entirely into a single line when only the comment should be folded; instead, the first line of the decl right below it is also collapsed.
    Screenshot 2023-10-12 at 11 41 17 AM
  • Here, the folding marker is incorrectly on the line above the return statement. It is in the correct spot if the comment is removed. It behaves just like the above, where the following line is consumed by folding the comment. I'm guessing this implies all comments should be foldable, but that if a foldable statement exists below a comment, it mistakenly interferes with the ability to fold that statement.
    Screenshot 2023-10-12 at 11 43 03 AM
    Screenshot 2023-10-12 at 11 45 29 AM
  • Trailing )'s are not folded up the way trailing }'s are
    Screenshot 2023-10-12 at 11 49 24 AM
    Unless they're preceded by a }:
    Screenshot 2023-10-12 at 11 52 05 AM
    Screenshot 2023-10-12 at 11 53 12 AM

Edit: Adding more below as I come across them

  • Multiline function/init declarations, such as
     func someMethodWithLotsOfArgs( <--- this part
         arg1: T,
         arg2: U,
         arg3: V,
         arg4: W,
         ...
     ) {                            <--- down to here
         ...
     }

Tracked in Apple’s issue tracker as rdar://116877123

I think the folding issues with comment should be fixed by #804 but the other issues are definitely also ones we should fix.

If anyone is interesting in fixing these: The folding ranges are computed in

public func foldingRange(_ req: FoldingRangeRequest) async throws -> [FoldingRange]? {
, which is a fairly isolated SwiftSyntax visitor that doesn’t require too much outside knowledge apart from swift-syntax trees.

Tests live in https://github.com/apple/sourcekit-lsp/blob/main/Tests/SourceKitLSPTests/FoldingRangeTests.swift