yedit icon indicating copy to clipboard operation
yedit copied to clipboard

source format removes all comments

Open Andrei-Pozolotin opened this issue 11 years ago • 20 comments

problem: Shift+Ctrl+F removes all comments

origin: http://dadacoalition.org/yedit/

system:

Eclipse Java EE IDE for Web Developers.
Version: Luna Service Release 1 (4.4.1)
Build id: 20140925-1800
  YEdit Feature 1.0.16  org.dadacoalition.yedit.feature.group   YEdit Project
java -version
java version "1.8.0_25"
Java(TM) SE Runtime Environment (build 1.8.0_25-b17)
Java HotSpot(TM) 64-Bit Server VM (build 25.25-b02, mixed mode)
uname -a
Linux wks002 3.13.0-39-generic #66-Ubuntu SMP Tue Oct 28 13:30:27 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux

Andrei-Pozolotin avatar Nov 09 '14 16:11 Andrei-Pozolotin

Thanks for reporting!

This is most probably not an easy thing to fix. The formatter is built on the DumperOptions from SnakeYAML which was not made with editor formatting in mind.

I don't have time to look at this at the moment, but I will try to take a look at in a couple of months.

oyse avatar Nov 10 '14 19:11 oyse

cool. thanks for looking.

Andrei-Pozolotin avatar Nov 12 '14 02:11 Andrei-Pozolotin

+1 for this request. At least auto-formatter should be able to act on only selected lines (if no lines are selected, then format all) so I can manually do partial formatting.

fchen avatar Oct 10 '15 04:10 fchen

As mentioned this is not an easy fix. The 3rd party parser that is used is not really made with this type of scenario in mind.

Suggestions for how this can be implemented or pull-requests are always welcome though.

oyse avatar Oct 11 '15 18:10 oyse

+1

gazal-k avatar Mar 01 '16 10:03 gazal-k

+1 and I humbly offer my opinion that a comment-nuking formatter is fatally flawed and should be removed from this plugin.

chrisinmtown avatar Apr 11 '16 15:04 chrisinmtown

@chrisinmtown Yeah, you are probably right.

oyse avatar May 20 '16 20:05 oyse

+1

moezubair avatar May 27 '16 15:05 moezubair

+1

stevewallcgi avatar Jun 01 '16 14:06 stevewallcgi

Øystein: @oyse can you please agree with Andrey how to best handle this: https://bitbucket.org/asomov/snakeyaml/issues/346/

Andrei-Pozolotin avatar Jun 08 '16 00:06 Andrei-Pozolotin

  1. First, let us clarify the problem. YAML 1.1/1.2 specification explicitly ignores any comments. Any attempts to keep the comments will make SnakeYAML non-spec-compliant
  2. Feel free to make a proposal to respect the comments in YAML 2.0 (the spec is under construction).
  3. It should be (probably) possible to respect comments in a fork of SnakeYAML. The YAML processing (http://yaml.org/spec/1.1/current.html#id859109) should be extended with the support for comments (events, nodes etc) This is a major exercise.
  4. My recommendation is to drop auto-formatting altogether because it does not belong here. Formatting of YAML is sensitive, it has many flavours, it is a subject for major irritation and misunderstanding.

SnakeYAML developer.

P.S. Please do not use human names when you talk about Open Source project. It is always a community. (SnakeYAML is definitely no one-man-project)

asomov avatar Jun 08 '16 14:06 asomov

I humbly offer my opinion that a comment-nuking formatter is fatally flawed and should be removed from this plugin.

I wouldn't argue againts calling it 'flawed'. However simply removing it helps no-one and might actually hamper someone. Even a flawed formatter may be useful to someone (i.e. if I don't have comments in my file then its totally fine). So I'd actually argue against removing.

If you don't like what the formatter does, you can always simply refrain from using it.

If its removed... then all choice regards to using or not using it is removed from the user as well.

kdvolder avatar Jun 09 '16 00:06 kdvolder

What might be easy to do... is have the formatter run a quick check to see if any comments are present in the file, and if so either:

  • do nothing (i.e. no formatting)
  • popup a confirmation message asking the user if its okay to 'nuke' the comments

kdvolder avatar Jun 09 '16 00:06 kdvolder

What might be easy to do... is have the formatter run a quick check to see if any comments are >present in the file, and if so either:

This is not easy. The formatter does not know if there are any comments. They are removed.

asomov avatar Jun 09 '16 12:06 asomov

I mean the formatter = "the thing in the YEdit editor which grabs the text from the edit buffer and massages it somehow".

Clearly that 'formatter' has access to the text of the document in full and it shouldn't be hard to grep the text with some regexp to see if it contains a comment anywhere.

kdvolder avatar Jun 09 '16 16:06 kdvolder

@kdvolder Yes, that could be do-able. Good suggestion.

oyse avatar Jun 09 '16 18:06 oyse

@Andrei-Pozolotin Adding this to SnakeYAML or to the Yaml 2.0 spec is not easy. I think a better approach would be that someone made a general Yaml formatter that could be used both in YEdit and other places, but I am not aware of any such project unfortunatly.

oyse avatar Jun 09 '16 20:06 oyse

@oyse @asomov thank you guys. need to think again.

@oyse : how about adding an eclipse plugin preference checkbox "enable auto format", and then keeping it disabled by default? basically, its hard to kill Ctrl+Shift+F reflex for some people, hence it needs some assistance :-)

Andrei-Pozolotin avatar Jun 10 '16 01:06 Andrei-Pozolotin

+1 for disabling the Ctrl+Shfit+F hotkey by default. We do this in our commercial product, which includes our open source, Yedit based editor for Swagger-OpenAPI.

+1 for leaving the formatter in the current code base. Even though we've disabled the hot key, it's still helpful to have the command available through the QuickAccess toolbar, as a way to convert JSON to more idiomatic YAML. Those JSON sources don't have YAML comments, so the formatter is useful and non-destructive when used that way.

+1 for adding text-based comment detection and a pop-up warning before proceeding with formatting. A nice improvement!

+1 for (eventually) amending the YAML spec and SnakeYAML implementation to remove the requirement of ignoring/discarding comments. I think that's a significant design flaw that disregards the practical needs of YAML editors, and the humans who use them.

My team is slammed right now, but as we have available bandwidth, we hope to contribute to some of the above.

tedepstein avatar Jun 24 '16 13:06 tedepstein

Can I recommend allowing for an external formatter like the python editor does with pep8? Would give us the option to format things as needed for the particular app. I get that it's not handled in the spec .. but it's heavily used in things like Ansible and others for documenting things in line.

sandinak avatar Jul 02 '19 16:07 sandinak