Skip to content

Commit

Permalink
select linter executable on Mac will not follow symbol link
Browse files Browse the repository at this point in the history
  • Loading branch information
Yupeng Wang committed Apr 4, 2023
1 parent 9c98c8d commit 1add66a
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 20 deletions.
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,3 @@
.gradle
build/
project/

gradle.properties
8 changes: 4 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
plugins {
id 'java'
id 'org.jetbrains.intellij' version '1.13.1'
id 'org.jetbrains.kotlin.jvm' version '1.8.0'
id 'org.jetbrains.intellij' version '1.13.3'
id 'org.jetbrains.kotlin.jvm' version '1.8.20'
}

static def gitTag() {
Expand Down Expand Up @@ -32,9 +32,9 @@ repositories {

// See https://github.com/JetBrains/gradle-intellij-plugin/
intellij {
version = '223.8836.41'
version = '231.8109.175'
type = 'IU'
plugins = ['org.jetbrains.plugins.go:223.8836.7']
plugins = ['org.jetbrains.plugins.go:231.8109.175']
updateSinceUntilBuild = false
}

Expand Down
4 changes: 4 additions & 0 deletions change-notes.htm
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
<p><strong>1.6.5 (2023-04-05)</strong></p>
<ul>
<li>select linter executable on Mac will not follow symbol link</li>
</ul>
<p><strong>1.6.4 (2023-03-12)</strong></p>
<ul>
<li>support conf + executable in path without config plugin</li>
Expand Down
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
org.gradle.jvmargs=-Xmx1g
20 changes: 6 additions & 14 deletions src/main/java/com/ypwang/plugin/form/GoLinterConfigurable.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.intellij.openapi.application.ModalityState;
import com.intellij.openapi.fileChooser.FileChooser;
import com.intellij.openapi.fileChooser.FileChooserDescriptor;
import com.intellij.openapi.fileChooser.FileChooserDescriptorFactory;
import com.intellij.openapi.options.SearchableConfigurable;
import com.intellij.openapi.options.ShowSettingsUtil;
import com.intellij.openapi.progress.ProcessCanceledException;
Expand All @@ -15,7 +16,6 @@
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.DialogBuilder;
import com.intellij.openapi.ui.JBPopupMenu;
import com.intellij.openapi.util.Condition;
import com.intellij.openapi.util.Disposer;
import com.intellij.openapi.util.Pair;
import com.intellij.openapi.vfs.LocalFileSystem;
Expand All @@ -32,7 +32,6 @@
import com.ypwang.plugin.UtilitiesKt;
import com.ypwang.plugin.model.GoLinter;
import com.ypwang.plugin.platform.Platform;
import com.ypwang.plugin.platform.Windows;
import kotlin.Unit;
import org.apache.commons.lang.StringUtils;
import org.jetbrains.annotations.NotNull;
Expand Down Expand Up @@ -374,7 +373,7 @@ private void initializeLinters() {
allLinters.clear();
enabledLinters.clear();

if (selectedLinter != null && new File(selectedLinter).canExecute()) {
if (selectedLinter != null && platform.canExecute(selectedLinter)) {
try {
List<String> arguments = new ArrayList<>();
arguments.add(platform.toRunningOSPath(selectedLinter));
Expand Down Expand Up @@ -581,23 +580,16 @@ private void linterSelected(ActionEvent e) {
}

private void linterChoose() {
FileChooserDescriptor fileChooserDescriptor = new FileChooserDescriptor(true, false, false, false, false, false);

Condition<VirtualFile> filter;
if (platform instanceof Windows)
filter = file -> "exe".equalsIgnoreCase(file.getExtension());
else
filter = file -> platform.canExecute(file.getPath());
fileChooserDescriptor.withFileFilter(filter);

String hintPath = (String) linterChooseComboBox.getSelectedItem();
if (hintPath == null || hintPath.isEmpty()) {
hintPath = platform.defaultPath();
}

VirtualFile file = FileChooser.chooseFile(fileChooserDescriptor, GoLinterConfigurable.this.settingPanel, null,
VirtualFile file = FileChooser.chooseFile(
platform.adjustLinterExeChooser(FileChooserDescriptorFactory.createSingleFileNoJarsDescriptor()),
this.settingPanel,
null,
LocalFileSystem.getInstance().findFileByPath(hintPath));

if (file != null) {
// because `file.getPath()` returns linux path, seems weird on windows
String systemPath = Paths.get(file.getPath()).toString();
Expand Down
3 changes: 3 additions & 0 deletions src/main/kotlin/com/ypwang/plugin/platform/Platform.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import com.goide.project.GoProjectLibrariesService
import com.goide.sdk.GoSdkService
import com.goide.vgo.configuration.VgoProjectSettings
import com.intellij.execution.wsl.WslPath
import com.intellij.openapi.fileChooser.FileChooserDescriptor
import com.intellij.openapi.project.Project
import com.intellij.openapi.util.SystemInfo
import com.intellij.openapi.vfs.VirtualFileManager
Expand Down Expand Up @@ -199,4 +200,6 @@ abstract class Platform(protected val project: Project) {
.map { Paths.get(it, linterName()).toString() }
.firstOrNull { canExecute(it) } ?: ""
}
open fun adjustLinterExeChooser(initial: FileChooserDescriptor): FileChooserDescriptor =
initial.also { it.withFileFilter { vf -> this.canExecute(vf.path) } }
}
4 changes: 4 additions & 0 deletions src/main/kotlin/com/ypwang/plugin/platform/UnixLike.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.ypwang.plugin.platform

import com.intellij.openapi.fileChooser.FileChooserDescriptor
import com.intellij.openapi.project.Project
import com.ypwang.plugin.model.GithubRelease
import org.apache.commons.compress.archivers.tar.TarArchiveInputStream
Expand Down Expand Up @@ -45,4 +46,7 @@ open class Linux(project: Project) : UnixLikePlatform(project) {

class Mac(project: Project) : UnixLikePlatform(project) {
override fun getPlatformSpecificBinName(meta: GithubRelease): String = "${LinterName}-${meta.name.substring(1)}-darwin-${arch()}.tar.gz"
override fun adjustLinterExeChooser(initial: FileChooserDescriptor): FileChooserDescriptor {
return super.adjustLinterExeChooser(initial).also { it.isForcedToUseIdeaFileChooser = true }
}
}
3 changes: 3 additions & 0 deletions src/main/kotlin/com/ypwang/plugin/platform/Windows.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.ypwang.plugin.platform

import com.intellij.openapi.fileChooser.FileChooserDescriptor
import com.intellij.openapi.project.Project
import com.ypwang.plugin.model.GithubRelease
import java.io.FileInputStream
Expand Down Expand Up @@ -40,4 +41,6 @@ class Windows(project: Project) : Platform(project) {
}.toString()
override fun linterName(): String = "$LinterName.exe"
override fun defaultPath(): String = System.getenv("PUBLIC")
override fun adjustLinterExeChooser(initial: FileChooserDescriptor): FileChooserDescriptor =
initial.also { it.withFileFilter { vf -> "exe".equals(vf.extension, ignoreCase = true) } }
}

0 comments on commit 1add66a

Please sign in to comment.