From 48c2750f59d6c7bce7063d19fceaead6123e2c40 Mon Sep 17 00:00:00 2001 From: deathaxe Date: Mon, 2 Oct 2023 20:35:37 +0200 Subject: [PATCH] Add support for PowerShell.ShowCodeActionDocumentation (#24) Fixes #13 --- plugin.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/plugin.py b/plugin.py index 39cd6ed..fce55f0 100644 --- a/plugin.py +++ b/plugin.py @@ -92,6 +92,12 @@ def on_pre_server_command(self, command: Mapping[str, Any], done_callback: Calla self._handle_show_references(references) done_callback() return True + + if command_name == 'PowerShell.ShowCodeActionDocumentation': + self._handle_show_rule_documentation(command['arguments'][0]) + done_callback() + return True + return False def m_powerShell_executionStatusChanged(self, params: Any) -> None: @@ -181,3 +187,15 @@ def _handle_show_references(self, references: List[Location]) -> None: LocationPicker(view, session, references, side_by_side=False) else: sublime.status_message('No references found') + + def _handle_show_rule_documentation(self, rule_id: str) -> None: + if not rule_id: + return + + if rule_id.startswith("PS"): + rule_id = rule_id[2:] + + sublime.run_command( + "open_url", + {"url": "https://docs.microsoft.com/powershell/utility-modules/psscriptanalyzer/rules/" + rule_id} + )