Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: limit executable search to PATH and add error handling for missing executable #42

Merged
merged 2 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Welcome to KCL developing! We hope this plugin enhances your development experie

- **Step 1.** [Install KCL](https://kcl-lang.io/docs/user_docs/getting-started/install) on your system.

- **Step 2.** Install the KCL plugin for IntelliJ IDEA in Marketplace. Preference -> plugins -> Marketplace -> search `KCL` -> install -> restart IDE. This plugin requires the IntelliJ IDEA Ultimate 2023.2+
- **Step 2.** Install the KCL plugin for IntelliJ IDEA in Marketplace. Preference -> plugins -> Marketplace -> search `KCL` -> install -> restart IDE.

- **Step 3.** Open or create a KCL file and begin your KCL tour!

Expand Down
21 changes: 11 additions & 10 deletions src/main/java/io/kusionstack/kcl/KCLLanguageServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@
public class KCLLanguageServer extends ProcessStreamConnectionProvider {

public KCLLanguageServer(Project project) {
String kclLSPPath = findExecutableInPATH("kcl-language-server");
if(kclLSPPath!=null && !kclLSPPath.isEmpty()) {
try {
String kclLSPPath = findExecutableInPATH("kcl-language-server");
super.setCommands(List.of(kclLSPPath));
} else {
} catch (Exception e) {
NotificationGroupManager.getInstance().getNotificationGroup("KCL LSP").createNotification(
"KCL LSP",
"KCL Language Server not found. Make sure it is installed properly (and is available in PATH), and restart the IDE.",
"KCL Language Server not found. Ensure it is installed properly (and is available in PATH), and restart the IDE. "
+ "Note: A path containing a colon ':' may cause issues on some systems.",
NotificationType.ERROR
).notify(project);
LanguageServerManager.getInstance(project).stop("KCLLanguageServerId");
Expand All @@ -38,12 +39,12 @@ private String findExecutableInPATH(String executable) {
// Append '.exe' to the executable name if on Windows, otherwise leave it as is
String executableName = isWindows ? executable + ".exe" : executable;

Optional<File> foundExecutable = envVariablesMap.values().stream()
// Split the PATH by the platform-specific separator (':' for Unix, ';' for Windows)
.flatMap(path -> Stream.of(path.split(File.pathSeparator)))
.map(path -> Path.of(path,executableName).toFile())
.filter(file -> file.exists() && file.canExecute())
.findFirst();
Optional<File> foundExecutable = Stream.of(envVariablesMap.get("PATH"))
// Split the PATH by the platform-specific separator (':' for Unix, ';' for Windows)
.flatMap(path -> Stream.of(path.split(File.pathSeparator)))
.map(path -> Path.of(path,executableName).toFile())
.filter(file -> file.exists() && file.canExecute())
.findFirst();

return foundExecutable.map(File::getPath).orElse(null);
}
Expand Down
Loading