eclipse-archived / ceylon.formatter

A formatter for the Ceylon programming language, written in Ceylon.
Apache License 2.0
14 stars 11 forks source link

Profiles #74

Closed quintesse closed 10 years ago

quintesse commented 10 years ago

Implement the concept of "profiles". These are files that only contain formatting options. They'd be located alongside the Ceylon config file (so they could appear in ./.ceylon and ~/.ceylon etc) with names like format.default, format.personal, format.myproject, etc. When the formatter is invoked without any special options it will look for format.default in the same way Ceylon looks for the config file (looking locally first, then going up the directory hierarchy and looking in special places like the user's home folder etc). The format tool would also take an argument --profile=name to override that default by telling it to look for the file format.name instead. It should probably also be possible to say --profile=path/to/file to point directly to a specific profile file. Like for any Ceylon tool it should be possible to set a value for the profile argument in the config file using the section [formattool] and the key profile.

@lucaswerkmeister thinks it would be useful to have the profiles inherit options from parent profiles (just like the config file inherits from parent config files). I'm not so sure because I don't see tools like Eclipse implement formatting profiles like that, but if we implement this it should probably be possible to easily generate a "full profile" by telling the formatter to write all options with their current settings to a file somewhere (eg. --write=path/to/file).

lucaswerkmeister commented 10 years ago

Also, we should add one part of this – the default profile – for the initial release, therefore allowing people to keep their regular config file completely free of any formatter settings.

Like for any Ceylon tool it should be possible to set a value for the profile argument in the config file using the section [formattool] and the key profile.

You mean there should be a ceylon format tool? (ATM it’s ceylon run ceylon.formatter.)

quintesse commented 10 years ago

You mean there should be a ceylon format tool?

Yes, don't you think so? :)

We don't yet officially support Ceylon-based plugins, but I think this can be "faked" for now by adding a simple shell/batch script (see ceylon plugin) that runs ceylon run ceylon.formatter with the arguments it was passed. That way a user can install the formatter and immediately have a ceylon format command.

Edit: fixed typo, changed ceylon script to ceylon plugin

quintesse commented 10 years ago

Also, we should add one part of this – the default profile – for the initial release

Exactly. See #75

lucaswerkmeister commented 10 years ago

Yes, don't you think so? :)

Sure, it just doesn’t exist yet :)

Exactly. See #75

Yeah, I didn’t know you were going to create a second issue when I wrote that comment.

quintesse commented 10 years ago

Sure, it just doesn’t exist yet :)

I think it's as simple as adding the file ./script/ceylon/formatter/ceylon-format with the following contents:

USAGE='<arg1> <arg2>'
DESCRIPTION='Format command blah blah'
LONG_USAGE='Here you explain how to
use the format command.'

. $CEYLON_HOME/bin/ceylon-sh-setup

$CEYLON run ceylon.formatter/1.1.0 $@

and a ./script/ceylon/formatter/ceylon-format.bat with:

set "USAGE=<arg1> <arg2>"
set "DESCRIPTION=Format command blah blah"
set "LONG_USAGE=Here you explain how to"
set "LONG_USAGE=%LONG_USAGE%use the format command."

call %CEYLON_HOME%\bin\ceylon-sh-setup.bat %*

if "%errorlevel%" == "1" (
    exit /b 0
)
%CEYLON% run ceylon.formatter/1.1.0 %*

And run ceylon plugin pack ceylon.formatter/1.1.0. And ceylon plugin install ceylon.formatter/1.1.0.

Disclaimer: I didn't try any of this. Edit: fixed examples Edit2: scripts -> script

lucaswerkmeister commented 10 years ago

Alright, I finally got around to trying this out! My findings:

  1. The folder is called script, not scripts
  2. Yes, the .bat file is required. And screw that single-line string format. I can’t be bothered to convert that manually :D
  3. Even though the script was, according to the messages, correctly packaged and installed, I still get an error that 'format' is not a ceylon command :-(
$ ceylon plugin list
ceylon-format (ceylon.formatter)
ceylon-format.bat (ceylon.formatter)
ceylon-format.bat~ (ceylon.formatter)

wtf?

quintesse commented 10 years ago

ad 3) on what OS are you @lucaswerkmeister ? The file needs to be considered "executable" (meaning +x on Unix-likes and having .bat extension on Windows)

ad 4) seems the code that shows plugin scripts needs to be a bit more clever (ceylon/ceylon-compiler#1775)

lucaswerkmeister commented 10 years ago

The file needs to be considered "executable"

That’s what was missing, thanks! (Linux, chmod fixed it; bat wasn’t necessary after all.)

5) The --help output seems to truncate leading spaces from my LONG_USAGE; without indentation, it looks a bit odd.

lucaswerkmeister commented 10 years ago

6) Command-line options seem to break:

ceylon format --indent="8-wide tabs" source

creates three empty directories --indent, 8-wide and tabs.

quintesse commented 10 years ago

ad 4) is fixed now

quintesse commented 10 years ago

ad 6) can you try if ceylon format "--indent=8-wide tabs" source works? It might just be the way the arguments are passed to the script

lucaswerkmeister commented 10 years ago

4) thanks!

lucaswerkmeister commented 10 years ago

6) doesn’t make any difference… which makes sense, because the ceylon command never sees these quotes – they’re interpreted by the shell.

EDIT: And putting a -- before it doesn’t help either.

quintesse commented 10 years ago

Ah yes, I get it, it's the script itself, like I said I didn't test any of it. Doing $CEYLON run ceylon.formatter/1.1.0 $@ is just too simplistic when dealing with arguments that can contain spaces.

lucaswerkmeister commented 10 years ago

Replacing $@ with "$@ (quotes individual arguments) results in only two folders: 8-wide tabs and --indent.

The following command actually works:

ceylon format --indentMode="8-wide tabs" source

I just forgot the name of the option facedesk

quintesse commented 10 years ago

Ah :)

Yes, I too just found some articles saying that you should always quote "$@"

But why does it create directories when using wrong options? That doesn't really seem like desired behaviour, right? I mean, people make typos all the time.

lucaswerkmeister commented 10 years ago

I just implemented #75, and if a “profile” really means nothing more than passing "profile.``profile``" instead of "profile.default" to the ConfigFinder (with the signature configOptions(profile = "default")), then I don’t see why this has to wait for 1.2… am I missing something @quintesse?

quintesse commented 10 years ago

No, I already assumed it would be easy but I didn't want to pressure you too much :) I'll re-schedule for 1.1 then

lucaswerkmeister commented 10 years ago

Haha, I think I was just in an “I don’t want to think about a massive formatter settings redesign while I’m rushing through ceylon.ast” mood in ceylon/ceylon-ide-eclipse#987 :D

quintesse commented 10 years ago

Great! :)