From 1dbeee27e2a2da704cf4f221fdfbe76e6f4c7673 Mon Sep 17 00:00:00 2001 From: keli Date: Mon, 5 Sep 2022 10:55:05 +0800 Subject: [PATCH 1/9] stop validating executable when applying the Configurable to allow reference from PATH (such as pwsh) --- .../powershell/lang/lsp/ide/settings/PowerShellConfigurable.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/com/intellij/plugin/powershell/lang/lsp/ide/settings/PowerShellConfigurable.java b/src/main/java/com/intellij/plugin/powershell/lang/lsp/ide/settings/PowerShellConfigurable.java index dab00a5b..9bb2eac2 100644 --- a/src/main/java/com/intellij/plugin/powershell/lang/lsp/ide/settings/PowerShellConfigurable.java +++ b/src/main/java/com/intellij/plugin/powershell/lang/lsp/ide/settings/PowerShellConfigurable.java @@ -68,7 +68,6 @@ public void apply() throws ConfigurationException { boolean isEnabled = getPSJpanel().getIsUseLanguageServer(); LSPInitMain lspInitMain = ApplicationManager.getApplication().getComponent(LSPInitMain.class); LSPInitMain.PowerShellInfo powerShellInfo = lspInitMain.getState(); - FormUIUtil.validatePowerShellExecutablePath(powerShellExePath); String powerShellVersion = getPSJpanel().getPowerShellVersionValue(); if (StringUtil.isEmpty(powerShellVersion)) throw new ConfigurationException("Can not detect PowerShell version"); String editorServicesVersion; From ad6b936f4c30a3640c5d1faea3cac01a7a0c923d Mon Sep 17 00:00:00 2001 From: keli Date: Mon, 5 Sep 2022 11:21:45 +0800 Subject: [PATCH 2/9] update powershell version everytime when the text field changed (not only when changed with the file chooser) --- .../PowerShellExecutableChooserPanel.java | 44 ++++++++++++------- 1 file changed, 29 insertions(+), 15 deletions(-) diff --git a/src/main/java/com/intellij/plugin/powershell/lang/lsp/ide/settings/PowerShellExecutableChooserPanel.java b/src/main/java/com/intellij/plugin/powershell/lang/lsp/ide/settings/PowerShellExecutableChooserPanel.java index 2a3c6c52..2293529b 100644 --- a/src/main/java/com/intellij/plugin/powershell/lang/lsp/ide/settings/PowerShellExecutableChooserPanel.java +++ b/src/main/java/com/intellij/plugin/powershell/lang/lsp/ide/settings/PowerShellExecutableChooserPanel.java @@ -15,6 +15,8 @@ import org.jetbrains.concurrency.CancellablePromise; import javax.swing.*; +import javax.swing.event.DocumentEvent; +import javax.swing.event.DocumentListener; public class PowerShellExecutableChooserPanel extends JComponent { private final Logger LOG = Logger.getInstance(getClass()); @@ -29,23 +31,35 @@ public PowerShellExecutableChooserPanel(@Nullable String executablePath) { } private void createUIComponents() { + JBTextField textField = new JBTextField(0); + textField.getDocument().addDocumentListener(new DocumentListener() { + @Override + public void insertUpdate(DocumentEvent e) { + String powerShellExePath = textField.getText(); + updatePowerShellVersionLabel(powerShellExePath); + } + + @Override + public void removeUpdate(DocumentEvent e) { + String powerShellExePath = textField.getText(); + updatePowerShellVersionLabel(powerShellExePath); + } + + @Override + public void changedUpdate(DocumentEvent e) { + } + }); + FileChooserDescriptor fileChooserDescriptor = new FileChooserDescriptor(true, false, false, false, false, false) { + @Override + public void validateSelectedFiles(VirtualFile @NotNull [] files) throws Exception { + if (files.length <= 0) return; + String powerShellExePath = files[0].getCanonicalPath(); + FormUIUtil.validatePowerShellExecutablePath(powerShellExePath); + } + }; psExecutablePathTextFieldChooser = FormUIUtil.createTextFieldWithBrowseButton( MessagesBundle.INSTANCE.message("powershell.executable.path.dialog.text"), - new JBTextField(0), - new FileChooserDescriptor(true, false, false, false, false, false) { - @Override - public void validateSelectedFiles(VirtualFile @NotNull [] files) throws Exception { - if (files.length <= 0) return; - String powerShellExePath = files[0].getCanonicalPath(); - FormUIUtil.validatePowerShellExecutablePath(powerShellExePath); - CancellablePromise versionPromise = PSLanguageHostUtils.INSTANCE.getPowerShellVersion(powerShellExePath); - versionPromise.onError(throwable -> { - LOG.warn("Exception when getting PowerShell version: ", throwable); - setPowerShellVersionLabelValue(null); - }).onSuccess(version -> setPowerShellVersionLabelValue(version) - ); - } - }); + textField, fileChooserDescriptor); } private void updatePowerShellVersionLabel(@NotNull String powerShellExePath) { From de164e1a691a5b4e4c6db60c3dc1bc485775d4ec Mon Sep 17 00:00:00 2001 From: keli Date: Mon, 5 Sep 2022 11:33:51 +0800 Subject: [PATCH 3/9] stop validating executable path when using the file chooser. It is eventually validated through the version checking. --- .../powershell/lang/lsp/ide/settings/FormUIUtil.java | 7 ------- .../ide/settings/PowerShellExecutableChooserPanel.java | 10 +--------- 2 files changed, 1 insertion(+), 16 deletions(-) diff --git a/src/main/java/com/intellij/plugin/powershell/lang/lsp/ide/settings/FormUIUtil.java b/src/main/java/com/intellij/plugin/powershell/lang/lsp/ide/settings/FormUIUtil.java index 55b33106..638d8678 100644 --- a/src/main/java/com/intellij/plugin/powershell/lang/lsp/ide/settings/FormUIUtil.java +++ b/src/main/java/com/intellij/plugin/powershell/lang/lsp/ide/settings/FormUIUtil.java @@ -12,7 +12,6 @@ import com.intellij.plugin.powershell.lang.lsp.languagehost.PowerShellExtensionError; import com.intellij.ui.components.JBTextField; import com.intellij.util.ui.UIUtil; -import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -41,12 +40,6 @@ public static String getEditorServicesVersion(@NotNull final String editorServic return editorServicesVersion; } - @Contract("null -> fail") - public static void validatePowerShellExecutablePath(@Nullable String powerShellExePath) throws ConfigurationException { - if (!FileUtil.exists(powerShellExePath)) - throw new ConfigurationException("Path to PowerShell executable does not exist: '" + powerShellExePath + "'."); - } - public static TextFieldWithBrowseButton createTextFieldWithBrowseButton(@NotNull String description, JBTextField field, FileChooserDescriptor fileChooserDescriptor) { TextFieldWithBrowseButton textFieldWithBrowseButton = new TextFieldWithBrowseButton(field); fileChooserDescriptor.withShowHiddenFiles(true); diff --git a/src/main/java/com/intellij/plugin/powershell/lang/lsp/ide/settings/PowerShellExecutableChooserPanel.java b/src/main/java/com/intellij/plugin/powershell/lang/lsp/ide/settings/PowerShellExecutableChooserPanel.java index 2293529b..4b789411 100644 --- a/src/main/java/com/intellij/plugin/powershell/lang/lsp/ide/settings/PowerShellExecutableChooserPanel.java +++ b/src/main/java/com/intellij/plugin/powershell/lang/lsp/ide/settings/PowerShellExecutableChooserPanel.java @@ -5,7 +5,6 @@ import com.intellij.openapi.fileChooser.FileChooserDescriptor; import com.intellij.openapi.ui.TextFieldWithBrowseButton; import com.intellij.openapi.util.text.StringUtil; -import com.intellij.openapi.vfs.VirtualFile; import com.intellij.plugin.powershell.ide.MessagesBundle; import com.intellij.plugin.powershell.lang.lsp.LSPInitMain; import com.intellij.plugin.powershell.lang.lsp.languagehost.PSLanguageHostUtils; @@ -49,14 +48,7 @@ public void removeUpdate(DocumentEvent e) { public void changedUpdate(DocumentEvent e) { } }); - FileChooserDescriptor fileChooserDescriptor = new FileChooserDescriptor(true, false, false, false, false, false) { - @Override - public void validateSelectedFiles(VirtualFile @NotNull [] files) throws Exception { - if (files.length <= 0) return; - String powerShellExePath = files[0].getCanonicalPath(); - FormUIUtil.validatePowerShellExecutablePath(powerShellExePath); - } - }; + FileChooserDescriptor fileChooserDescriptor = new FileChooserDescriptor(true, false, false, false, false, false); psExecutablePathTextFieldChooser = FormUIUtil.createTextFieldWithBrowseButton( MessagesBundle.INSTANCE.message("powershell.executable.path.dialog.text"), textField, fileChooserDescriptor); From b285ed0fc7fbc12c5ace03bf4cd2f4feba033b17 Mon Sep 17 00:00:00 2001 From: Friedrich von Never Date: Wed, 23 Aug 2023 23:10:18 +0200 Subject: [PATCH 4/9] (#89) Roll back the PowerShell executable file validation --- .../powershell/lang/lsp/ide/settings/FormUIUtil.java | 7 +++++++ .../lang/lsp/ide/settings/PowerShellConfigurable.java | 1 + 2 files changed, 8 insertions(+) diff --git a/src/main/java/com/intellij/plugin/powershell/lang/lsp/ide/settings/FormUIUtil.java b/src/main/java/com/intellij/plugin/powershell/lang/lsp/ide/settings/FormUIUtil.java index 638d8678..55b33106 100644 --- a/src/main/java/com/intellij/plugin/powershell/lang/lsp/ide/settings/FormUIUtil.java +++ b/src/main/java/com/intellij/plugin/powershell/lang/lsp/ide/settings/FormUIUtil.java @@ -12,6 +12,7 @@ import com.intellij.plugin.powershell.lang.lsp.languagehost.PowerShellExtensionError; import com.intellij.ui.components.JBTextField; import com.intellij.util.ui.UIUtil; +import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -40,6 +41,12 @@ public static String getEditorServicesVersion(@NotNull final String editorServic return editorServicesVersion; } + @Contract("null -> fail") + public static void validatePowerShellExecutablePath(@Nullable String powerShellExePath) throws ConfigurationException { + if (!FileUtil.exists(powerShellExePath)) + throw new ConfigurationException("Path to PowerShell executable does not exist: '" + powerShellExePath + "'."); + } + public static TextFieldWithBrowseButton createTextFieldWithBrowseButton(@NotNull String description, JBTextField field, FileChooserDescriptor fileChooserDescriptor) { TextFieldWithBrowseButton textFieldWithBrowseButton = new TextFieldWithBrowseButton(field); fileChooserDescriptor.withShowHiddenFiles(true); diff --git a/src/main/java/com/intellij/plugin/powershell/lang/lsp/ide/settings/PowerShellConfigurable.java b/src/main/java/com/intellij/plugin/powershell/lang/lsp/ide/settings/PowerShellConfigurable.java index 9bb2eac2..dab00a5b 100644 --- a/src/main/java/com/intellij/plugin/powershell/lang/lsp/ide/settings/PowerShellConfigurable.java +++ b/src/main/java/com/intellij/plugin/powershell/lang/lsp/ide/settings/PowerShellConfigurable.java @@ -68,6 +68,7 @@ public void apply() throws ConfigurationException { boolean isEnabled = getPSJpanel().getIsUseLanguageServer(); LSPInitMain lspInitMain = ApplicationManager.getApplication().getComponent(LSPInitMain.class); LSPInitMain.PowerShellInfo powerShellInfo = lspInitMain.getState(); + FormUIUtil.validatePowerShellExecutablePath(powerShellExePath); String powerShellVersion = getPSJpanel().getPowerShellVersionValue(); if (StringUtil.isEmpty(powerShellVersion)) throw new ConfigurationException("Can not detect PowerShell version"); String editorServicesVersion; From 1dba3527106533b87571a52fe7d7ed83bc4935e3 Mon Sep 17 00:00:00 2001 From: Friedrich von Never Date: Wed, 23 Aug 2023 23:20:43 +0200 Subject: [PATCH 5/9] (#89) FormUIUtil: convert to Kotlin --- build.gradle | 4 +- .../lang/lsp/ide/settings/FormUIUtil.java | 65 ---------------- .../lang/lsp/ide/settings/FormUIUtil.kt | 75 +++++++++++++++++++ .../ide/settings/PowerShellConfigurable.java | 4 - .../run/MyRunConfigurationTemplateProvider.kt | 2 +- .../ide/run/PowerShellRunConfiguration.kt | 4 +- 6 files changed, 80 insertions(+), 74 deletions(-) delete mode 100644 src/main/java/com/intellij/plugin/powershell/lang/lsp/ide/settings/FormUIUtil.java create mode 100644 src/main/java/com/intellij/plugin/powershell/lang/lsp/ide/settings/FormUIUtil.kt diff --git a/build.gradle b/build.gradle index 94cf6d42..7cb47d36 100644 --- a/build.gradle +++ b/build.gradle @@ -55,8 +55,8 @@ tasks.withType(JavaCompile).all { } tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all { kotlinOptions { - apiVersion = '1.3' - languageVersion = '1.3' + apiVersion = '1.4' + languageVersion = '1.4' jvmTarget = '1.8' } } diff --git a/src/main/java/com/intellij/plugin/powershell/lang/lsp/ide/settings/FormUIUtil.java b/src/main/java/com/intellij/plugin/powershell/lang/lsp/ide/settings/FormUIUtil.java deleted file mode 100644 index 55b33106..00000000 --- a/src/main/java/com/intellij/plugin/powershell/lang/lsp/ide/settings/FormUIUtil.java +++ /dev/null @@ -1,65 +0,0 @@ -package com.intellij.plugin.powershell.lang.lsp.ide.settings; - -import com.intellij.openapi.application.ApplicationManager; -import com.intellij.openapi.fileChooser.FileChooserDescriptor; -import com.intellij.openapi.fileChooser.FileChooserFactory; -import com.intellij.openapi.options.ConfigurationException; -import com.intellij.openapi.ui.TextComponentAccessor; -import com.intellij.openapi.ui.TextFieldWithBrowseButton; -import com.intellij.openapi.util.io.FileUtil; -import com.intellij.openapi.util.text.StringUtil; -import com.intellij.plugin.powershell.lang.lsp.LSPInitMain; -import com.intellij.plugin.powershell.lang.lsp.languagehost.PowerShellExtensionError; -import com.intellij.ui.components.JBTextField; -import com.intellij.util.ui.UIUtil; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import javax.swing.*; - -import static com.intellij.plugin.powershell.lang.lsp.languagehost.PSLanguageHostUtils.INSTANCE; - -public class FormUIUtil { - - public static String getEditorServicesVersion(@NotNull final String editorServicesDir) throws ConfigurationException { - if (!FileUtil.exists(editorServicesDir)) - throw new ConfigurationException("Editor Services directory '" + editorServicesDir + "' does not exist."); - String editorServicesVersion; - try { - editorServicesVersion = INSTANCE.getEditorServicesModuleVersion(INSTANCE.getPSExtensionModulesDir(editorServicesDir)); - } catch (PowerShellExtensionError e) { - PowerShellConfigurable.LOG.warn("Error detecting PowerShell Editor Services module version: " + e.getMessage(), e); - throw new ConfigurationException("Can not detect Editor Services module version" + e.getMessage()); - } - if (StringUtil.isEmpty(editorServicesVersion)) - throw new ConfigurationException("Can not detect Editor Services module version"); - - String startupScript = INSTANCE.getEditorServicesStartupScript(editorServicesDir); - if (StringUtil.isEmpty(startupScript)) - throw new ConfigurationException("Can not find Editor Services startup script"); - return editorServicesVersion; - } - - @Contract("null -> fail") - public static void validatePowerShellExecutablePath(@Nullable String powerShellExePath) throws ConfigurationException { - if (!FileUtil.exists(powerShellExePath)) - throw new ConfigurationException("Path to PowerShell executable does not exist: '" + powerShellExePath + "'."); - } - - public static TextFieldWithBrowseButton createTextFieldWithBrowseButton(@NotNull String description, JBTextField field, FileChooserDescriptor fileChooserDescriptor) { - TextFieldWithBrowseButton textFieldWithBrowseButton = new TextFieldWithBrowseButton(field); - fileChooserDescriptor.withShowHiddenFiles(true); - JTextField textField = textFieldWithBrowseButton.getChildComponent(); - textField.setDisabledTextColor(UIUtil.getLabelDisabledForeground()); - textFieldWithBrowseButton.addBrowseFolderListener(description, null, null, fileChooserDescriptor, TextComponentAccessor.TEXT_FIELD_WHOLE_TEXT); - FileChooserFactory.getInstance().installFileCompletion(textField, fileChooserDescriptor, true, null); - return textFieldWithBrowseButton; - } - - @Nullable - public static String getGlobalSettingsExecutablePath() { - return ApplicationManager.getApplication().getComponent(LSPInitMain.class).getState().getPowerShellExePath(); - } - -} diff --git a/src/main/java/com/intellij/plugin/powershell/lang/lsp/ide/settings/FormUIUtil.kt b/src/main/java/com/intellij/plugin/powershell/lang/lsp/ide/settings/FormUIUtil.kt new file mode 100644 index 00000000..dfba5d7b --- /dev/null +++ b/src/main/java/com/intellij/plugin/powershell/lang/lsp/ide/settings/FormUIUtil.kt @@ -0,0 +1,75 @@ +package com.intellij.plugin.powershell.lang.lsp.ide.settings + +import com.intellij.openapi.application.ApplicationManager +import com.intellij.openapi.fileChooser.FileChooserDescriptor +import com.intellij.openapi.fileChooser.FileChooserFactory +import com.intellij.openapi.options.ConfigurationException +import com.intellij.openapi.ui.TextComponentAccessor +import com.intellij.openapi.ui.TextFieldWithBrowseButton +import com.intellij.openapi.util.io.FileUtil +import com.intellij.openapi.util.text.StringUtil +import com.intellij.plugin.powershell.lang.lsp.LSPInitMain +import com.intellij.plugin.powershell.lang.lsp.languagehost.PSLanguageHostUtils.getEditorServicesModuleVersion +import com.intellij.plugin.powershell.lang.lsp.languagehost.PSLanguageHostUtils.getEditorServicesStartupScript +import com.intellij.plugin.powershell.lang.lsp.languagehost.PSLanguageHostUtils.getPSExtensionModulesDir +import com.intellij.plugin.powershell.lang.lsp.languagehost.PowerShellExtensionError +import com.intellij.ui.components.JBTextField +import com.intellij.util.ui.UIUtil +import org.jetbrains.annotations.Contract + +object FormUIUtil { + + @JvmStatic + @Throws(ConfigurationException::class) + fun getEditorServicesVersion(editorServicesDir: String): String { + if (!FileUtil.exists(editorServicesDir)) throw ConfigurationException( + "Editor Services directory '$editorServicesDir' does not exist." + ) + val editorServicesVersion: String + try { + editorServicesVersion = getEditorServicesModuleVersion(getPSExtensionModulesDir(editorServicesDir)) + } catch (e: PowerShellExtensionError) { + PowerShellConfigurable.LOG.warn( + "Error detecting PowerShell Editor Services module version: " + e.message, + e + ) + throw ConfigurationException("Can not detect Editor Services module version" + e.message) + } + if (StringUtil.isEmpty(editorServicesVersion)) throw ConfigurationException("Can not detect Editor Services module version") + val startupScript = getEditorServicesStartupScript(editorServicesDir) + if (StringUtil.isEmpty(startupScript)) throw ConfigurationException("Can not find Editor Services startup script") + return editorServicesVersion + } + + @Contract("null -> fail") + @JvmStatic + fun validatePowerShellExecutablePath(powerShellExePath: String?) { + if (!FileUtil.exists(powerShellExePath)) throw ConfigurationException( + "Path to PowerShell executable does not exist: '$powerShellExePath'." + ) + } + + @JvmStatic + fun createTextFieldWithBrowseButton( + description: String, + field: JBTextField?, + fileChooserDescriptor: FileChooserDescriptor + ): TextFieldWithBrowseButton { + val textFieldWithBrowseButton = TextFieldWithBrowseButton(field) + fileChooserDescriptor.withShowHiddenFiles(true) + val textField = textFieldWithBrowseButton.childComponent + textField.setDisabledTextColor(UIUtil.getLabelDisabledForeground()) + textFieldWithBrowseButton.addBrowseFolderListener( + description, + null, + null, + fileChooserDescriptor, + TextComponentAccessor.TEXT_FIELD_WHOLE_TEXT + ) + FileChooserFactory.getInstance().installFileCompletion(textField, fileChooserDescriptor, true, null) + return textFieldWithBrowseButton + } + + val globalSettingsExecutablePath: String? + get() = ApplicationManager.getApplication().getComponent(LSPInitMain::class.java).state.powerShellExePath +} diff --git a/src/main/java/com/intellij/plugin/powershell/lang/lsp/ide/settings/PowerShellConfigurable.java b/src/main/java/com/intellij/plugin/powershell/lang/lsp/ide/settings/PowerShellConfigurable.java index dab00a5b..769495a4 100644 --- a/src/main/java/com/intellij/plugin/powershell/lang/lsp/ide/settings/PowerShellConfigurable.java +++ b/src/main/java/com/intellij/plugin/powershell/lang/lsp/ide/settings/PowerShellConfigurable.java @@ -79,10 +79,6 @@ public void apply() throws ConfigurationException { getPSJpanel().setEditorServicesVersionLabelValue(null); throw e; } - if (editorServicesVersion == null) { - getPSJpanel().setEditorServicesVersionLabelValue(null); - throw new ConfigurationException("Can not validate PowerShell extension"); - } } else { editorServicesVersion = null; } diff --git a/src/main/kotlin/com/intellij/plugin/powershell/ide/run/MyRunConfigurationTemplateProvider.kt b/src/main/kotlin/com/intellij/plugin/powershell/ide/run/MyRunConfigurationTemplateProvider.kt index a7a12c54..89db965a 100644 --- a/src/main/kotlin/com/intellij/plugin/powershell/ide/run/MyRunConfigurationTemplateProvider.kt +++ b/src/main/kotlin/com/intellij/plugin/powershell/ide/run/MyRunConfigurationTemplateProvider.kt @@ -9,7 +9,7 @@ import com.intellij.plugin.powershell.lang.lsp.ide.settings.FormUIUtil class MyRunConfigurationTemplateProvider : RunConfigurationTemplateProvider { override fun getRunConfigurationTemplate(factory: ConfigurationFactory, runManager: RunManagerImpl): RunnerAndConfigurationSettingsImpl? { val templateConfiguration = factory.createTemplateConfiguration(runManager.project, runManager) as? PowerShellRunConfiguration ?: return null - templateConfiguration.executablePath = FormUIUtil.getGlobalSettingsExecutablePath() + templateConfiguration.executablePath = FormUIUtil.globalSettingsExecutablePath return RunnerAndConfigurationSettingsImpl(runManager, templateConfiguration, true) } } \ No newline at end of file diff --git a/src/main/kotlin/com/intellij/plugin/powershell/ide/run/PowerShellRunConfiguration.kt b/src/main/kotlin/com/intellij/plugin/powershell/ide/run/PowerShellRunConfiguration.kt index e52980ed..1c5ab752 100644 --- a/src/main/kotlin/com/intellij/plugin/powershell/ide/run/PowerShellRunConfiguration.kt +++ b/src/main/kotlin/com/intellij/plugin/powershell/ide/run/PowerShellRunConfiguration.kt @@ -31,7 +31,7 @@ class PowerShellRunConfiguration(project: Project, configurationFactory: Configu var scriptParameters: String = "" private var commandOptions: String? = null var environmentVariables: EnvironmentVariablesData = EnvironmentVariablesData.DEFAULT - var executablePath: String? = FormUIUtil.getGlobalSettingsExecutablePath() + var executablePath: String? = FormUIUtil.globalSettingsExecutablePath override fun getConfigurationEditor(): SettingsEditor = PowerShellRunSettingsEditor(project, this) @@ -60,7 +60,7 @@ class PowerShellRunConfiguration(project: Project, configurationFactory: Configu this.workingDirectory = workingDirectory } environmentVariables = EnvironmentVariablesData.readExternal(element) - executablePath = if (StringUtil.isEmpty(exePath)) FormUIUtil.getGlobalSettingsExecutablePath() else exePath + executablePath = if (StringUtil.isEmpty(exePath)) FormUIUtil.globalSettingsExecutablePath else exePath } @Throws(WriteExternalException::class) From 2b8f46103eaf6c4fb6610f27d69c0911b3b1925b Mon Sep 17 00:00:00 2001 From: Friedrich von Never Date: Wed, 23 Aug 2023 23:21:25 +0200 Subject: [PATCH 6/9] PowerShellRunConfiguration: clean up warnings --- .../plugin/powershell/ide/run/PowerShellRunConfiguration.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/com/intellij/plugin/powershell/ide/run/PowerShellRunConfiguration.kt b/src/main/kotlin/com/intellij/plugin/powershell/ide/run/PowerShellRunConfiguration.kt index 1c5ab752..7e53e553 100644 --- a/src/main/kotlin/com/intellij/plugin/powershell/ide/run/PowerShellRunConfiguration.kt +++ b/src/main/kotlin/com/intellij/plugin/powershell/ide/run/PowerShellRunConfiguration.kt @@ -36,7 +36,7 @@ class PowerShellRunConfiguration(project: Project, configurationFactory: Configu override fun getConfigurationEditor(): SettingsEditor = PowerShellRunSettingsEditor(project, this) @Throws(ExecutionException::class) - override fun getState(executor: Executor, environment: ExecutionEnvironment): RunProfileState? = + override fun getState(executor: Executor, environment: ExecutionEnvironment): RunProfileState = PowerShellScriptCommandLineState(this, environment) @Throws(InvalidDataException::class) From 481c97553b28104ceb51aad9fa2c0f307f0d4f47 Mon Sep 17 00:00:00 2001 From: Friedrich von Never Date: Wed, 23 Aug 2023 23:33:59 +0200 Subject: [PATCH 7/9] (#89) Settings: validate the executables in PATH --- .../lang/lsp/ide/settings/FormUIUtil.kt | 17 +++++++--- .../messages/MessagesBundle.properties | 31 +++++++++++-------- 2 files changed, 31 insertions(+), 17 deletions(-) diff --git a/src/main/java/com/intellij/plugin/powershell/lang/lsp/ide/settings/FormUIUtil.kt b/src/main/java/com/intellij/plugin/powershell/lang/lsp/ide/settings/FormUIUtil.kt index dfba5d7b..bc81b6c3 100644 --- a/src/main/java/com/intellij/plugin/powershell/lang/lsp/ide/settings/FormUIUtil.kt +++ b/src/main/java/com/intellij/plugin/powershell/lang/lsp/ide/settings/FormUIUtil.kt @@ -1,5 +1,6 @@ package com.intellij.plugin.powershell.lang.lsp.ide.settings +import com.intellij.execution.configurations.PathEnvironmentVariableUtil import com.intellij.openapi.application.ApplicationManager import com.intellij.openapi.fileChooser.FileChooserDescriptor import com.intellij.openapi.fileChooser.FileChooserFactory @@ -8,6 +9,7 @@ import com.intellij.openapi.ui.TextComponentAccessor import com.intellij.openapi.ui.TextFieldWithBrowseButton import com.intellij.openapi.util.io.FileUtil import com.intellij.openapi.util.text.StringUtil +import com.intellij.plugin.powershell.ide.MessagesBundle import com.intellij.plugin.powershell.lang.lsp.LSPInitMain import com.intellij.plugin.powershell.lang.lsp.languagehost.PSLanguageHostUtils.getEditorServicesModuleVersion import com.intellij.plugin.powershell.lang.lsp.languagehost.PSLanguageHostUtils.getEditorServicesStartupScript @@ -43,10 +45,17 @@ object FormUIUtil { @Contract("null -> fail") @JvmStatic - fun validatePowerShellExecutablePath(powerShellExePath: String?) { - if (!FileUtil.exists(powerShellExePath)) throw ConfigurationException( - "Path to PowerShell executable does not exist: '$powerShellExePath'." - ) + fun validatePowerShellExecutablePath(powerShellExePath: String) { + val exists = if (FileUtil.isAbsolute(powerShellExePath)) { + FileUtil.exists(powerShellExePath) + } else { + PathEnvironmentVariableUtil.findExecutableInPathOnAnyOS(powerShellExePath) != null + } + if (!exists) { + throw ConfigurationException( + MessagesBundle.message("settings.errors.executable-not-found", powerShellExePath) + ) + } } @JvmStatic diff --git a/src/main/resources/messages/MessagesBundle.properties b/src/main/resources/messages/MessagesBundle.properties index 4a9ed028..85602ef2 100644 --- a/src/main/resources/messages/MessagesBundle.properties +++ b/src/main/resources/messages/MessagesBundle.properties @@ -1,20 +1,25 @@ -wrapping.catch,type.list=Catch type list -wrapping.attribute.argument=Attribute arguments -wrapping.pipeline=Pipeline -wrapping.block.parameters=Block parameters - code.style.align.multiline=Align when multiline -settings.powershell=PowerShell +editor.services.inspection=PSScriptAnalyzer + +powershell.download.link=https://github.com/powershell/powershell#get-powershell +powershell.editor.services.download.link=https://github.com/PowerShell/PowerShellEditorServices/releases powershell.editor.services.path.dialog.text=Select folder powershell.executable.path.dialog.text=Select PowerShell executable -powershell.extension.path.form.label=PowerShell Editor Services: powershell.extension.path.form.description=Here you can specify the path to PowerShellEditorServices package. -ps.editor.services.detected.version.label=Version: -powershell.vs.code.extension.install.link=https://github.com/PowerShell/vscode-powershell#installing-the-extension -powershell.editor.services.download.link=https://github.com/PowerShell/PowerShellEditorServices/releases -powershell.download.link=https://github.com/powershell/powershell#get-powershell +powershell.extension.path.form.label=PowerShell Editor Services: powershell.install.message=\nPowerShell executable not found in PATH. Install -vs.code.powershell.extension.configure.message=\nWould you like to install PowerShell VSCode extension to get more rich PowerShell Editor assistance? \nIf extension is installed, you can specify the path manually in Settings. +powershell.vs.code.extension.install.link=https://github.com/PowerShell/vscode-powershell#installing-the-extension + +ps.editor.services.detected.version.label=Version: + +settings.errors.executable-not-found=PowerShell executable "{0}" could not be found. settings.powershell.lsp.is.enabled.box.text=Integrate Editor with PowerShell EditorServices host -editor.services.inspection=PSScriptAnalyzer \ No newline at end of file +settings.powershell=PowerShell + +vs.code.powershell.extension.configure.message=\nWould you like to install PowerShell VSCode extension to get more rich PowerShell Editor assistance? \nIf extension is installed, you can specify the path manually in Settings. + +wrapping.attribute.argument=Attribute arguments +wrapping.block.parameters=Block parameters +wrapping.catch,type.list=Catch type list +wrapping.pipeline=Pipeline From 1e6a56cc96348ee43fea5d7df2edcd84850cf167 Mon Sep 17 00:00:00 2001 From: Friedrich von Never Date: Wed, 23 Aug 2023 23:44:21 +0200 Subject: [PATCH 8/9] (#89) Settings: version validation should only set version if the executable path is actual --- .../settings/PowerShellExecutableChooserPanel.java | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/intellij/plugin/powershell/lang/lsp/ide/settings/PowerShellExecutableChooserPanel.java b/src/main/java/com/intellij/plugin/powershell/lang/lsp/ide/settings/PowerShellExecutableChooserPanel.java index 4b789411..c781c697 100644 --- a/src/main/java/com/intellij/plugin/powershell/lang/lsp/ide/settings/PowerShellExecutableChooserPanel.java +++ b/src/main/java/com/intellij/plugin/powershell/lang/lsp/ide/settings/PowerShellExecutableChooserPanel.java @@ -57,12 +57,18 @@ public void changedUpdate(DocumentEvent e) { private void updatePowerShellVersionLabel(@NotNull String powerShellExePath) { CancellablePromise versionPromise = PSLanguageHostUtils.INSTANCE.getPowerShellVersion(powerShellExePath); versionPromise.onError(throwable -> { - LOG.warn("Exception when getting PowerShell version: ", throwable); - setPowerShellVersionLabelValue(null); - }).onSuccess(this::setPowerShellVersionLabelValue); + LOG.debug("Exception when getting PowerShell version: ", throwable); + if (getExecutablePath().equals(powerShellExePath)) { + setPowerShellVersionLabelValue(null); + } + }).onSuccess(version -> { + if (getExecutablePath().equals(powerShellExePath)) { + setPowerShellVersionLabelValue(version); + } + }); } - public String getExecutablePath() { + public @NotNull String getExecutablePath() { return psExecutablePathTextFieldChooser.getText().trim(); } From 2961c1d4b1f6b9cf804065527c6d3215741c4353 Mon Sep 17 00:00:00 2001 From: Friedrich von Never Date: Wed, 23 Aug 2023 23:48:42 +0200 Subject: [PATCH 9/9] (#89) Docs: document the addition --- src/main/resources/META-INF/plugin.xml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml index b01557fd..abd54c2a 100644 --- a/src/main/resources/META-INF/plugin.xml +++ b/src/main/resources/META-INF/plugin.xml @@ -15,7 +15,8 @@
Unreleased
-: Upgrade PSScriptAnalyzer from 1.17.1 to 1.19.0;
-
K: Add indents for array elements when formatting.
+
K: Add indents for array elements when formatting;
+
Y: Allow entering the executables from PATH in the plugin settings.
2.0.10 update
· Fixing 76 Exception thrown when plugin is enabled but no powershell is found in the path ;