vscode-haxe icon indicating copy to clipboard operation
vscode-haxe copied to clipboard

Indent breaks with completion using trimTrailingWhitespace

Open MangelMaxime opened this issue 9 years ago • 20 comments

I just pull the latest version of vscode-haxe and it appear that autocompletion is breaking the current indentation when there is no dot in the line to autocomplete.

For example :

public function render(g: Graphics): Void {
        image
        g.drawImage(_texture, rect.origin.x, rect.origin.y);
}

Become :

public function render(g: Graphics): Void {
image
        g.drawImage(_texture, rect.origin.x, rect.origin.y);
}

To reproduce this bug, you can simply try to press enter at the end of a line. Wait 1sec, and their you should see that your cursor has been moved to the beginning of the line.

I am under linux.

MangelMaxime avatar Jan 17 '16 15:01 MangelMaxime

Just to add more info, if we do a space in the line it's also breaking the completion to remove the trailing space.

Oh, I found the problem. I am using the files.trimTrailingWhitespace: true that causing the problem because if I set it to false it's ok.

It's was working before, so I think it a bug.

MangelMaxime avatar Jan 17 '16 20:01 MangelMaxime

If I'm understanding correctly, I can't seem to reproduce the problem. Here I setup a function like yours, type the member name, press enter, and the indentation doesn't get messed up. I try it with a dot, no indentation seems to get messed up:

test

I'm on linux also, vscode 0.10.1.

jcward avatar Jan 18 '16 23:01 jcward

Ok, I will check if I have the lates version of VSCode. Did you turn on files.trimTrailingWhitespace: true when doing your testing ?

MangelMaxime avatar Jan 19 '16 07:01 MangelMaxime

No, I didn't try trimTrailingWhitespace -- I'll test with that.

jcward avatar Jan 19 '16 15:01 jcward

This is indeed a problem with trimTrailingWhitespaces which makes the feature unusable. I don't see why this would happen because it should only affect trailing whitespaces.

Is there a way to distinguish completion-file-saving from normal file-saving and ignore the trailing for the former? This would also take care of actual trailing whitespace issues which I encountered in other editors before (see https://github.com/fdorg/flashdevelop/issues/604).

By the way, right now it won't even let me tab-indent, the tab is immediately deleted because the file is saved (for some reason... toplevel completion or something?).

Simn avatar Jan 26 '16 19:01 Simn

@simn: Ah, yes, the file is saved prior to the completion call (related: https://github.com/HaxeFoundation/haxe/issues/4651) -- I was just about to ask if there was any movement on that or the function signature / comma parsing (https://github.com/HaxeFoundation/haxe/pull/4758) issues.

trimTrailingWhitespace is a vscode setting? Perhaps we could chagne it before, and restore it after, the document.save() calls.

jcward avatar Jan 26 '16 19:01 jcward

I can't figure out how to modify configuration. The type WorkspaceConfiguration seems to be read-only.

Simn avatar Jan 26 '16 19:01 Simn

@simm File->Preferrences and you have two choices per workspace or more globally

pleclech avatar Jan 26 '16 20:01 pleclech

Yes I know how to do it manually. Jeff suggested changing the setting temporarily before saving the document and I don't know how to do that.

Simn avatar Jan 26 '16 21:01 Simn

I m working on a patch, changing before and restoring after didn't do anything

pleclech avatar Jan 26 '16 21:01 pleclech

I'm curious how you changed that because all I see on the configuration is get and has.

Simn avatar Jan 26 '16 21:01 Simn

yes...

pleclech avatar Jan 26 '16 21:01 pleclech

The vscode API indeed only has get and has: https://code.visualstudio.com/docs/extensionAPI/vscode-api#WorkspaceConfiguration

Of course, ideally we wouldn't have to save files as part of the completion flow. ;)

jcward avatar Jan 26 '16 21:01 jcward

Why have I never run into this? Are you guys setting this preference manually?

jcward avatar Jan 26 '16 21:01 jcward

Yes, I use it in every IDE/editor because you get stupid diffs otherwise.

Simn avatar Jan 26 '16 21:01 Simn

Got it. So perhaps we could implement an extension-level preference that does the same thing, but is aware of the completion auto-save issue. Perhaps with workspace.onDidSaveTextDocument ?

jcward avatar Jan 26 '16 21:01 jcward

That what i was thinking until configuration can be writable...

pleclech avatar Jan 26 '16 21:01 pleclech

Maybe that's indeed necessary. However, it's still strange that VS Code removed all whitespaces on a line, not just trailing ones. Might be a bug on their end?

Simn avatar Jan 26 '16 21:01 Simn

There is another problem for now there is not a pre-event present before saving https://github.com/Microsoft/vscode/issues/239

pleclech avatar Jan 27 '16 00:01 pleclech

Why do we need that? We manually call document.save() in HaxeContext, so whatever code you want to execute you can put there.

Simn avatar Jan 27 '16 08:01 Simn