Skip to content

LSP mode format + organize import? #205

Answered by rickyson96
rickyson96 asked this question in Q&A
Discussion options

You must be logged in to vote

Hey, sorry for just responding to this.
I decided to use another method previously since its available, and currently I'm stuck in the situation where I need this and decided to dig deeper.

Thanks for your pointer, I have working solution right now! Here's the snippet.

(cl-defun apheleia-lsp-organize-import-formatter (&key buffer scratch callback stdin &allow-other-keys)
  (with-current-buffer buffer
	(if-let ((_ (lsp-feature? "textDocument/codeAction"))
			 (action (->> (lsp-get-or-calculate-code-actions "source.organizeImports")
						  lsp--select-action)))
		(-let* ((workspace-edit (cadr action))
				((&WorkspaceEdit :document-changes?) workspace-edit)
				(document-changes (seq-reverse

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@rickyson96
Comment options

Answer selected by rickyson96
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants