Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Format on save #731

Merged
merged 7 commits into from
Sep 30, 2019
Merged

Format on save #731

merged 7 commits into from
Sep 30, 2019

Conversation

tomv564
Copy link
Contributor

@tomv564 tomv564 commented Sep 25, 2019

For issue #8

Adds support for sync request (blocking the editor for up to 1 second)

Default off, enable by setting lsp_format_on_save to true in preferences.

@coveralls
Copy link

coveralls commented Sep 25, 2019

Coverage Status

Coverage remained the same at 36.015% when pulling c190a69 on format-on-save into 2072a12 on master.

@rwols
Copy link
Member

rwols commented Sep 25, 2019

I have something to say about this, but I need a little more time, so please don't merge this yet.

@rchl
Copy link
Member

rchl commented Sep 25, 2019

It might be related to this PR or might not but I think this will not work for eslint server. I believe (after a short look at its code) that the way eslint server formats code on saving, is that it expects to get textDocument/willSaveWaitUntil notification and from there it handles the formatting.

Some references:

@tomv564
Copy link
Contributor Author

tomv564 commented Sep 25, 2019

@rchl good to know, eslint doesn't have a formattingProvider so willSaveWaitUntil is the only way to make it work. I think the implementation would be very similar to this one, if you're keen on trying it out!

plugin/formatting.py Outdated Show resolved Hide resolved
@rchl
Copy link
Member

rchl commented Sep 27, 2019

@tomv564 I'm quite intimidated by this code base and didn't have time to properly learn it. So we'll see if I get the courage. :)

Copy link
Member

@rwols rwols left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tried this locally and it works when there haven't been recent changes to the document. When the user types a bunch of characters and then hits CTRL+S the textDocument/didChange notification is sent out too late. Interesting to see the use of view.settings() directly. The while-loop is unncessarily busy on CPUs and we can do better with a simple condition variable.

  • We should use a condition variable instead of a busy while loop,
  • We should send textDocument/didChange just before doing the formatting.

plugin/core/rpc.py Outdated Show resolved Hide resolved
plugin/formatting.py Outdated Show resolved Hide resolved
@tomv564
Copy link
Contributor Author

tomv564 commented Sep 27, 2019

Good reminder from @rwols that this is the first time we introduce a regular sublime setting (at the view level) instead of an LSP setting. I didn't think much about it beyond the necessity of turning this feature on granularly (per project/syntax) - is it the best way to solve this?

@tomv564
Copy link
Contributor Author

tomv564 commented Sep 29, 2019

@rchl I added the willSaveWaitUntil logic to this PR as it was so similar. If you checkout branch workspace_configuration_request then you will get these changes and a minimal workspace/configuration implementation for the eslint server.

@rchl
Copy link
Member

rchl commented Sep 29, 2019

@tomv564 It does actually work (after I've adjusted my LSP-eslint to expose setting from a correct place). Very nice, thank you for your work. :)

As for the workspace/configuration changes, I guess that will be discussed separately.

rwols
rwols previously approved these changes Sep 29, 2019
Copy link
Member

@rwols rwols left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't think much about it beyond the necessity of turning this feature on granularly (per project/syntax) - is it the best way to solve this?

There should be a description in the user docs on how to enable this at least, right?

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

Successfully merging this pull request may close these issues.

4 participants