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

fix "formatting on save" potentially running on outdated document state #2336

Merged
merged 1 commit into from
Oct 12, 2023

Conversation

rchl
Copy link
Member

@rchl rchl commented Oct 12, 2023

Issue reported on Discord where with both "code actions on save" and "formatting on save" enabled, the formatting would be done on an outdated document state if code actions have triggered an edit.

Reproducible with a go document like:

package main

	func main() {
		fmt.Println("Hello1")
	}

and following project settings:

	"settings": {
		"lsp_format_on_save": true,
		"lsp_code_actions_on_save": {
			"source.organizeImports": true,
		}
	}

That resulted in broken edit where part of the added import would be missing.

The FormattingTask did trigger _purge_changes_async() on start but since the tasks ran in one continuous flow on the async thread, we didn't get to handle ST's on_text_changed notification in between tasks.

Fix by starting next task from set_timeout_async to allow pending events to trigger.

@rwols rwols merged commit c3def7f into main Oct 12, 2023
4 checks passed
@rwols rwols deleted the fix/formatting branch October 12, 2023 19:05
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.

2 participants