coc-extensions / coc-powershell

PowerShellEditorService integration for coc.vim

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Autoformat command

50nar opened this issue · comments

commented

Is it possible to use this to autoformat powershell code ?

In theory this should already work since PowerShell Editor Services (the language server for PowerShell) already supports formatting.

Just need to figure out how to invoke formatting with coc - if that doesn’t work, this could be a bug.

Looking at my logs, it looks like the formatting isn’t turned on…

"documentFormattingProvider": false,
"documentRangeFormattingProvider": false,
"documentOnTypeFormattingProvider": null,
commented

Is there any way to support you guys with some coins with these efforts?
IMO this project is going to be very popular as there is nothing else that would provide autoformat and autocomplete for powershell for vim it's a big deal for open-source community that wants to actually start using powershell, Microsoft should make this a priority project ;)

Right now we're just 2 Microsoft folks (and 1 non-Microsoft folk) moonlighting this project 😅

My team, the PowerShell team, would be the best place to officially own it... but the team (of 13 for all of PowerShell + Win32-OpenSSH) has a lot on its plate at the moment.

Best support would be time, if I'm brutally honest. Helping with docs, reproducing issues so we can fix them, and yes PRs always welcome 😊

We also need to setup a test suite so we don't break things.

If these are something you can help with, we'd be happy for the support 😊

commented

I've made a dirty poor man's plugin for this if anyone is interested. vim-pwsh-formatter

Nice!

The good news is that PowerShell Editor Services already supports handling formatting so if we wanna enable this in coc-powershell, all we have to do is tell coc.nvim that it's supported.

@TylerLeonhardt I'm trying to implement format handlers for coc-fsharp these days, got some hands-on experience with coc.nvim;

Basically:

  1. The formatexpr option is tied to gq, but not =. = uses built-in indent function, backed by the vimL associated with the file type (indent.vim) -- so that can also be rerouted.
  2. Manually call CocAction('format') works great -- so is CocAction('formatSelection', 'v') -- mind the "mode string" again.
  3. Haven't figure out how is the format-while-typing handler called by coc.nvim -- may be called during an automatic hard wrap (see 1.)

I discovered that PSES has poorly hooked up formatting... that relies on this code in the client side:

https://github.com/PowerShell/vscode-powershell/blob/master/src/features/DocumentFormatter.ts

I'm doing some major refactoring of PSES and this code wont be required in the future but for now it is

@TylerLeonhardt ringring ;)

Good news and bad news:

bad news - coc.nvim doesn't support:
vscode.languages.registerDocumentFormattingEditProvider
vscode.languages.registerDocumentRangeFormattingEditProvider
vscode.languages.registerOnTypeFormattingEditProvider

so I can't implement this at the moment. That said, PowerShell Editor Services is moving to handle the formatting registration automatically so in the 2.0 version of PowerShell Editor Services formatting should work out of the box.

good to know!

We will race with coc.nvim to see what happens first: neoclide/coc.nvim#1179

race conditions! :D

yeah for F#, I just declared these capabilities in the language server so it works automatically.
Let's see how coc.nvim will respond.

I just declared these capabilities in the language server

Right. PowerShell Editor Services never did this for some reason... really not sure why.

Thanks to PSES 2.0, this works now :) :call CocAction('format')