jarod2d / sublime_valign

Vertical alignment plugin for Sublime Text 2 and 3
91 stars 7 forks source link

Incorrect alignment of throws #30

Open mrjoelkemp opened 10 years ago

mrjoelkemp commented 10 years ago

Expected:

  if (!cb)        throw new Error('expected callback');
  if (!directory) throw new Error('expected directory name or list of filenames');
  if (!filename)  throw new Error('expected filename whose dependents to compute');

Instead, valign did nothing to indent those lines.

jarod2d commented 10 years ago

Thanks for the report. This is unfortunately probably not something that VAlign will be able to do any time soon, since it's much more sophisticated than what it does right now, which is simply aligning rows based on particular alignment characters like = or :.

There's two ways I could see this working. The plugin could attempt to recognize consecutive if statements, but this would require language-specific handling and would become complicated very quickly. It could also attempt to search for the largest matching substring in each row (in this case, throw new Error('expected) and align those. That would be my preferred approach, although I would need to think about it for a while to figure out what the implications of that would be.

In either case, I don't have a whole lot of time to work on the plugin at the moment. If you or anyone else would like to add support for this, I'd be happy to take a look at any pull requests.