Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Indentation is way off #27

Closed
supermarin opened this issue Dec 2, 2014 · 3 comments
Closed

Indentation is way off #27

supermarin opened this issue Dec 2, 2014 · 3 comments

Comments

@supermarin
Copy link

Here are 2 examples, let's start with a simpler one:

import Cocoa

println("OHAI")

class Installer {
    required init() {
   println("hohoho")
        }

}

Installer()
println("END")

As you type, indentation gets immediately wrong on required init,. Even if you select all and +, it stays screwed.

A more complex example is by pasting the sample code from Quick:

import Quick
import Nimble

print("hello")

class TableOfContentsSpec: QuickSpec {
    override func spec() {
   describe("the table of contents below") {
   it("has everything you need to get started") {
   let sections = TableOfContents().sections
      expect(sections).to(contain("Quick: Examples and Example Groups"))
      expect(sections).to(contain("Nimble: Assertions using expect(...).to"))
      expect(sections).to(contain("How to Install Quick"))
    }

    context("if it doesn't have what you're looking for") {
   it("needs to be updated") {
   let you = You(awesome: true)
        expect{you.submittedAnIssue}.toEventually(beTruthy())
      }
  }
  }
}
}
@sharplet
Copy link

sharplet commented Dec 6, 2014

I have an example of some multi-line expressions that took a bit of work to format. Here's about what I would like:

let simple = Add(
               left: Number(1),
               right: Number(2)
             )

let complex = Multiply(
                left: Add(
                  left: Number(1),
                  right: Number(2)
                ),
                right: Number(3)
              )

But this is what you currently get:

let expression = Add(
                     // this level of indent is kind of ok
                     left: Number(1),
                     right: Number(2)
                     )
                 // <= but it would be nice for this to be back here

// <= indent should be reset back to the previous statement
//                   but is instead here, and we keep getting deeper!
                     let complex = Multiply(
                                            left: Add(
                                                      left: Number(1),
                                                      right: Number(2)
                                                      ),
                                                      right: Number(3)
                                                      )

Actually, here's the same thing in Ruby:

simple = Add.new(
  Number.new(1),
  Number.new(2)
)

complex = Multiply.new(
  Number.new(1),
  Add.new(
    Number.new(2),
    Number.new(3)
  )
)

Which is probably a much more sane approach:

let simple = Add(
  Number(1),
  Number(2)
)

let complex = Multiply(
  left: Number(1),
  right: Add(
    left: Number(2),
    right: Number(3)
  )
)

@keith
Copy link
Owner

keith commented Dec 6, 2014

@sharplet this indentation around parens was actually intentional. Rather than aligning on colons like Objective-C this is setup to align on the opening paren similar to python. The second example is definitely an issue though. I'm definitely open to suggestions about this. Xcode currently indents this like this:

let bar = Add(
  left: 5,
  right: 6
)

@keith
Copy link
Owner

keith commented Dec 6, 2014

@supermarin @sharplet if both of you could try the branch from this PR #30 that would be great. It entirely changes indentation. It is not currently handling the parens example any differently, but it should fix the other examples.

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

No branches or pull requests

3 participants