swift.vim icon indicating copy to clipboard operation
swift.vim copied to clipboard

Multiline guard indentation

Open keith opened this issue 10 years ago • 0 comments

Currently there's a problem with multiline guards (and if lets) where the cases on their own lines will not be indented correctly. See an example here: https://github.com/keith/swift.vim/blob/7d7c6e33ba752ff8eb860cfc73b5dee57c3e15f0/example/example.swift#L327-L331

This is a hard problem. We can't only rely on the line above, or matching brackets/parens as we are everywhere else. Instead I guess we'll have to match multiple lines above, and find a guard/if. This will also have to handle the valid cases for closures in the statements such as:

guard let foo = bar.map({ $0.whatever }),
    let ugh = vim.syntaxfiles {

I took a stab at this by matching a line ending with a comma above the current line, and the current line having an = with:

previous =~ ",$" && line =~ '\v^s*(\w|\s)+\='

But this doesn't handle where clauses, or statements that are over more than 2 lines.

keith avatar Jan 09 '16 03:01 keith