adrianlee44 / atom-aligner

Easily align multi-line with support for different operators and custom configurations
https://atom.io/packages/aligner
MIT License
78 stars 3 forks source link

How to specify `multiple` in a language plugin? #18

Closed marnen closed 9 years ago

marnen commented 9 years ago

I'm trying to write an Aligner plugin for Gherkin. I would like to specify multiple as a property of the | character. However, because multiple seems to have to be a nested object rather than a simple string, every method I can think of fails, as follows:

1. Specify object within provider.coffee

# lib/provider.coffee
module.exports =
  config:
    '|-multiple':
      type: 'object'
      default:
        number:
          alignment: 'left'
        string:
          alignment: 'right'

Result: appears to display correctly on package settings screen, but operatorConfig.getConfig('|', '.text.gherkin.feature').multiple is {number: {}, string: {}}. Also, settings don't appear to save to ~/.atom/config.cson properly. Perhaps this is an Atom bug?

2. Use multiply hyphenated keys in provider.coffee

# lib/provider.coffee
module.exports =
  config:
    '|-multiple-number-alignment':
      type: 'string'
      default: 'left'
    '|-multiple-string-alignment':
      type: 'string'
      default: 'right'

Result: operatorConfig.getConfig('|', '.text.gherkin.feature').multiple is just the string right. Apparently Aligner, when splitting keys, discards everything after the second hyphen, so both of these keys are equivalent to |-multiple. I can try to submit a pull request to implement smarter splitting, if that seems like the right solution.

3. Specify object in package's config.cson file

This is actually the preferable choice for me, because the multiple option really shouldn't be user-configurable for my use case. Now if only I could get it to work!

# config.cson
setting:
  '|':
    multiple:
      number:
        alignment: 'left'
      string:
        alignment: 'right'

Result: This appears to be entirely ineffective (and likewise when I do the equivalent thing in JSON).

As you might imagine, I'm at my wits' end. What should I do here? Should I patch Atom or Aligner so that one of these works? @adrianlee44 Do you have any thoughts on which of these three methods is most compatible with Aligner's architecture?

I'm using Atom 0.188.0 on Mac OS X 10.10.

marnen commented 9 years ago

...and I neglected to mention that I'm using Aligner 0.9.1.

adrianlee44 commented 9 years ago

Thanks for your interest in aligner, @marnen.

Allow me to answer your thoughts on each of the format,

  1. That was my original intention but there seem to be a bug with object type in config. It wasn't very reliable when I was developing this and hence not using this format.
  2. This is the current approach for aligner config. As you have mentioned above, it's currently splitting on hyphens but only taking the first 2 as character and config key. Atom will render this format into a long and difficult to read title in Atom setting page, so these config objects usually includes a title and a description. This approach also allows option to be configurable. I thought of using an unrecognized type (e.g. type: 'private') for this config but Atom complains in the console.
  3. This format will match the format I have on the main package at the moment. The only problem is that it's not a valid Atom config object and requires conversion. The conversion function exist on atom-aligner but currently there is no good way to guarantee atom-aligner package is activated before language packages.

To be honest, multiple param was originally created to handle , and it wasn't a fully thought-out config parameters. I'm still thinking about it and am open to suggestion.

May I ask what character/operator you are trying to align and how they should be aligned?

marnen commented 9 years ago

Thanks for your detailed response! I'm trying to align tables in Gherkin (Cucumber):

Scenario:
  Given I have a pipe-delimited table in my scenario
  When I invoke Aligner
  Then the table should look something like this:
    | first  | last         | state |
    | Marnen | Laibow-Koser | MA    |
adrianlee44 commented 9 years ago

Just want to leave a quick update.

I'm currently working on this and should have a fix very soon. The update config file will look something like:

config:
  ':-alignment:
    type: 'string'
    default: 'right'
privateConfig:
  '|-multiple-string-alignment': 'right'
  '|-multiple-number-alignment: 'left'

privateConfig will not show up in the setting panel.

marnen commented 9 years ago

Thanks! I look forward to trying it out.

adrianlee44 commented 9 years ago

Aligner has been bumped to v0.11.0 with better configuration support. You can find the documentation at https://github.com/adrianlee44/atom-aligner/wiki/Creating-aligner-add-ons. Let me know if you run into any bug / question.