Skip to content
This repository has been archived by the owner on Jul 31, 2023. It is now read-only.

Formatter with microsoft python language server #131

Closed
deb75 opened this issue Sep 30, 2020 · 4 comments
Closed

Formatter with microsoft python language server #131

deb75 opened this issue Sep 30, 2020 · 4 comments

Comments

@deb75
Copy link

deb75 commented Sep 30, 2020

hello,

I tried lsp-format-buffer and it answeers :

Capability not supported by the language server: "documentFormattingProvider"

Can i add a formatter along microsoft language server ?

Regards

@deb75
Copy link
Author

deb75 commented Oct 22, 2020

Hi,

I think it should be possible to bound lsp-format-buffer to a custom function calling yapf. I have it installed together with the palantir language server which is configured to call yapf when invoking lsp-format-buffer.

Unfortunately, I am not skilled enough in lisp to perform that. Should anyone know how to call an external program (python script) and apply it to the current buffer, could provide me an example how to do that.

@jcs090218
Copy link
Member

Try shell-command function?

@seagle0128
Copy link
Collaborator

seagle0128 commented Oct 22, 2020

Try this snippet or https://github.com/JorisE/yapfify.

(defun lsp-python-ms-format-buffer ()
  (interactive)
  (when (and (executable-find "yapf") buffer-file-name)
    (call-process "yapf" nil nil nil "-i" buffer-file-name)))
(add-hook 'python-mode-hook
          (lambda ()
            (add-hook 'after-save-hook #'lsp-python-ms-format-buffer t t)))

@deb75
Copy link
Author

deb75 commented Feb 12, 2021

Thanks, this wonderfully makes the job. I still have to bound this function to C-c l = = when in a python buffer.

Regards

@deb75 deb75 closed this as completed Feb 12, 2021
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

3 participants