Skip to content
This repository has been archived by the owner on Sep 7, 2020. It is now read-only.

Indent breaks with completion using trimTrailingWhitespace #4

Open
MangelMaxime opened this issue Jan 17, 2016 · 20 comments
Open

Indent breaks with completion using trimTrailingWhitespace #4

MangelMaxime opened this issue Jan 17, 2016 · 20 comments

Comments

@MangelMaxime
Copy link

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
Copy link
Author

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.

@jcward
Copy link
Owner

jcward commented Jan 18, 2016

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.

@MangelMaxime
Copy link
Author

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

@jcward
Copy link
Owner

jcward commented Jan 19, 2016

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

@Simn
Copy link

Simn commented Jan 26, 2016

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 fdorg/flashdevelop#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?).

@jcward
Copy link
Owner

jcward commented Jan 26, 2016

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

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

@jcward jcward changed the title Breaking indention on completion Indent breaks with completion using trimTrailingWhitespace Jan 26, 2016
@Simn
Copy link

Simn commented Jan 26, 2016

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

@pleclech
Copy link
Contributor

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

@Simn
Copy link

Simn commented Jan 26, 2016

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.

@pleclech
Copy link
Contributor

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

@Simn
Copy link

Simn commented Jan 26, 2016

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

@pleclech
Copy link
Contributor

yes...

@jcward
Copy link
Owner

jcward commented Jan 26, 2016

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
Copy link
Owner

jcward commented Jan 26, 2016

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

@Simn
Copy link

Simn commented Jan 26, 2016

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

@jcward
Copy link
Owner

jcward commented Jan 26, 2016

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 ?

@pleclech
Copy link
Contributor

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

@Simn
Copy link

Simn commented Jan 26, 2016

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?

@pleclech
Copy link
Contributor

There is another problem for now there is not a pre-event present before saving microsoft/vscode#239

@Simn
Copy link

Simn commented Jan 27, 2016

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants