REditorSupport / languageserver

An implementation of the Language Server Protocol for R
Other
586 stars 94 forks source link

Run formatting in background process #251

Open renkun-ken opened 4 years ago

renkun-ken commented 4 years ago

Currently, formatting runs in the master process of languageserver which is a blocking action (#141). If user enables formatOnSave or formatOnPaste, then either saving a large document or pasting a large chunk of code will block the lsp from processing other events.

As @randy3k noted,

I think Format Document should be a blocking action though to ensure user changes are not lost. There may be nothing we could do at this moment.

I'm wondering if we could create a background process to perform the formatting and if any edits are made to the document being formatted, or user choose to cancel it via Canceling a Work Done Progress as we could create a progress before that, the task process should be terminated to accept user edits.

randy3k commented 4 years ago

I guess we could make it a background process. The current task manager is not powerful enough to handle this situation. Also, we are not executing the $/cancelRequest request, not sure if VSCode would send the cancel request for formatOnSave.

lorenzwalthert commented 4 years ago

A note on this: Because of the cache, it could make sense to style the input in the background and throw it away only to build the cache (keep in mind that we cache output, not input). Then, when you style again in the blocking foreground process, all top-level expressions that are already compliant to the style guide (hopefully man) were cached will return almost immediately. Not sure I have the full context here, so just an idea.