Skip to content

DSLD needs a better auto-formatting for DSL builder pattern #603

@ybayk

Description

@ybayk

Consider the following typical DSL representing a search query:

and {
  or {
     term 'foo'
     term 'bar'
  }
  not {
     term 'baz'
  }
}

Assume and(Closure block) method is proposed by the contribution block and the method does not contain required params besides trailing closure.
A much preferred state after autocompletion would be:

and {
  |
}

For a method with required parameters (e.g. method name: and, namedParams:[score:float]), desired autocompletion would look like this:

and (score: | ) {
  
}

Even when Eclipse Content Assist preferences set to "Use closure literals for closure arguments" and "Place trailing closure args after closing parens", the best that could be achieved today is

and { it }

Desired formatting rules are DSLD-specific, so I propose to add more formatting flags for the "method" tag in the contribution block. We already have noParens which is a good start but it is not sufficient.

We need at least four more options:

  1. option to suppress "it" as not making sense in this scenario
  2. option to set caret position next line and insert closing curly bracket one more line below
  3. option to override preference "Use closure literals for closure arguments"
  4. option to override preference "Place trailing closure args after closing parens"

I have not investigated how hard this will be to implement, just fishing if this is a sound proposal.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions