HaxeFoundation / intellij-haxe

Haxe plugin for IntelliJ Platform based IDEs (IDEA, Android-Studio)
http://intellij-haxe.org
Apache License 2.0
219 stars 100 forks source link

Code-aligning wrong behavior for @:metas #50

Open boozook opened 10 years ago

boozook commented 10 years ago

Calling autoalign-feature wrong behavior: It switch from

@:buildXml("&<include name='${haxelib:hx-nanovg}/Build.xml'/>")
class Main...

to

@:buildXml("&<include name='${haxelib:hx - nanovg}/Build.xml'/>")

For full example look Demo.hx#L9.

TIR: STB-7295

EBatTiVo commented 10 years ago

A quick test with the jar on the TiVo/ClassHierarchy branch shows it to be working. Using auto-align did not change the spacing. Reformat, however, did change the spacing, consistent with settings. This is an option in the settings panel: File->Settings->(LeftPanel:)CodeStyle (Haxe)->(RightPanel:)Spaces tab->Additive operators. If it's checked, then you /should/ have the extra spaces.

Please check your settings and update this bug if you continue to have the issue. If you do, please tell us the version and origin of the plugin you are using and steps to reproduce it. Do you use the "Reformat block on typing '}'" setting? How do you expect auto-format to be triggered?

as3boyan commented 10 years ago

Seems to be related to reformat code functionality, I think it shouldn't change strings

EBatTiVo commented 10 years ago

Ah! I totally missed that the code was inside of a string. So, my tests were invalid. :(

I wouldn't expect a normal double-quoted string to be changed. The code inside of the single quotes appears to be an interpolation expression, and therefore, code, which should honor the code style settings. The outer set of double-quotes should override, though.

EBatTiVo commented 10 years ago

Reference: http://haxe.org/manual/lf-string-interpolation.html

boozook commented 10 years ago

Yes. There two problems in one and it's good. We need to fix the "$string"-problem and this issue will be solved too.

as3boyan commented 10 years ago

Code inside String is treated as regular Haxe code, as you can see in code editor though syntax highlighting.

Ok, I will add a check to formatter, if parent of such expressions is StringLiteralExpression - then do not change spacing.

as3boyan commented 9 years ago

This one is complicated

@:buildXml("&<include name='${haxelib:hx-nanovg}/Build.xml'/>")
haxelib:hx-nanovg

This part is treated as regular Haxe code, but it's not valid, and parsing chokes on ':', so it's hard to figure out that it's a part of string, I'm not sure how to handle this case.

Ok, I will add a check to formatter, if parent of such expressions is StringLiteralExpression - then do not change spacing.

SpacingProcessor doesn't seem to preserve whitespace data, we can get this data from PSI, but that's bad way to do this I think.

Treat invalid expression(in interpolated string) as string would be perfect, but that's seems to be very complex.

I could check if parent element is custom meta and check if it's contain errors, but I still need to get how much whitespace was there, but that's still very limited option. For example, if user will assign such string contents to some variable - this will not work. Checking if PSI element parent contains errors would work, but that would break most of it's reformatter functionality, because if parent is big enough, entire block will not be reformatted at all.