PowerShell / PowerShellEditorServices

A common platform for PowerShell development support in any editor or application!
MIT License
622 stars 213 forks source link

Configure PSSA from Start-EditorServices #2001

Closed csc027 closed 1 year ago

csc027 commented 1 year ago

Summary

How do I configure the underlying PSScriptAnalyzer (PSSA) instance to use custom rules from the starting point Start-EditorServices for use in non-Visual Studio Code editors?

Description

I have a working PSES setup working for my Neovim setup, providing completion and linting for the default ruleset. However, I currently do not know how to configure custom PSSA rules for the PSSA instance bundled with PSES.

I know for VS Code, you could change the settings in your workspace, as documented here.

To be clear, I was able to get those rules working via implicit settings documented here. However, I have many different PowerShell repositories in my use case. It would be onerous to save a settings file each and every repository.

So, is it possible to configure the underlying PSSA instance's settings to explicitly use custom rules from either Start-EditorServices or from making specific changes to the environment that PSSA runs from?

andyleejordan commented 1 year ago

I think you would have to send those same settings that VS Code uses over LSP using whatever method your LSP client in Neovim provides to do so. In my experience this can be kind of tricky depending on the client, but here's the docs I found for Neovim's LSP client.

andyleejordan commented 1 year ago

Ah ha, specifically you'll want to look at [vim.lsp.start_client()](https://neovim.io/doc/user/lsp.html#vim.lsp.start()), and pass it a map under the settings key in the start config.

andyleejordan commented 1 year ago

Here is a completely random example of that I found on GitHub for you: https://github.com/ChristianChiarulli/nvim/blob/1631262e8df1de2ad0ecfd5f7dffd9c4476d7933/ftplugin/java.lua#L119

csc027 commented 1 year ago

Thank you so much! I was tearing my hair out trying to figure out how to pass the values to the server. For some reason, I was so stuck thinking about how to configure it via the entry point, that it didn't event occur to me that I should pass the settings through the LSP protocol.

csc027 commented 1 year ago

Also, how useful would it be to add this to the documentation somewhere, perhaps in docs/guide? I'm not sure what the roadmap is for PSES; so, I'm not sure how quickly the settings would change.

andyleejordan commented 1 year ago

It would be a great addition. I have work planned for this month to make using PSES from Emacs/Vim etc. (as in other LSP clients that are not VS Code) much easier, and will include some tested documentation on configuration. Because yes, LSP can be so confusing. It's fantastic tech compared to where we were at a decade ago, but I remember the pain the first time I tried to get Emacs with an LSP client to send a setting to OmniSharp (a C# LSP server)...it's the only reason I remembered enough to know what to look for here!

csc027 commented 1 year ago

That sounds awesome! Would you take a PR for documentation after the changes are put in? I can't profess to know Emacs very well, but I think I could add the one for NeoVim.

andyleejordan commented 1 year ago

Would love it, heck I'd welcome it now! I'll keep it updated after the fact too. The best Vim example I currently have is the end to end test: https://github.com/PowerShell/PowerShellEditorServices/blob/main/test/vim-test.vim

csc027 commented 1 year ago

Okay, cool. I'll put some time in once the weekend hits. It'll probably start as a draft.

csc027 commented 1 year ago

I added a draft PR #2016. I'll get some more changes in as I think of things that are missing. Feel free to comment on any style or content issues with it.


Edit: No longer a draft.