forked from redhat-developer/lsp4ij
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Investigate using OSProcessHandler
Fixes redhat-developer#153 Signed-off-by: azerr <azerr@redhat.com>
- Loading branch information
1 parent
9d1e0fe
commit e6d7463
Showing
3 changed files
with
98 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
src/main/java/com/redhat/devtools/lsp4ij/server/OSProcessStreamConnectionProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package com.redhat.devtools.lsp4ij.server; | ||
|
||
import com.intellij.execution.ExecutionException; | ||
import com.intellij.execution.configurations.GeneralCommandLine; | ||
import com.intellij.execution.impl.ExecutionManagerImpl; | ||
import com.intellij.execution.process.OSProcessHandler; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.io.InputStream; | ||
import java.io.OutputStream; | ||
import java.util.Objects; | ||
|
||
public class OSProcessStreamConnectionProvider implements StreamConnectionProvider { | ||
|
||
private GeneralCommandLine commandLine; | ||
private OSProcessHandler processHandler; | ||
|
||
public OSProcessStreamConnectionProvider(GeneralCommandLine commandLine) { | ||
this.commandLine = commandLine; | ||
} | ||
|
||
public void setCommandLine(GeneralCommandLine commandLine) { | ||
this.commandLine = commandLine; | ||
} | ||
|
||
public GeneralCommandLine getCommandLine() { | ||
return commandLine; | ||
} | ||
|
||
@Override | ||
public void start() throws CannotStartProcessException { | ||
if (this.commandLine == null) { | ||
throw new CannotStartProcessException("Unable to start language server: " + this); | ||
} | ||
try { | ||
processHandler = new OSProcessHandler(commandLine); | ||
} catch (ExecutionException e) { | ||
throw new CannotStartProcessException(e); | ||
} | ||
} | ||
|
||
@Override | ||
public boolean isAlive() { | ||
return processHandler != null && processHandler.isStartNotified() && !processHandler.isProcessTerminated(); | ||
} | ||
|
||
@Override | ||
public InputStream getInputStream() { | ||
return processHandler.getProcess().getInputStream(); | ||
} | ||
|
||
@Override | ||
public OutputStream getOutputStream() { | ||
return processHandler.getProcessInput(); | ||
} | ||
|
||
@Override | ||
public @Nullable InputStream getErrorStream() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public void stop() { | ||
if (processHandler != null && !processHandler.isProcessTerminated()) { | ||
ExecutionManagerImpl.stopProcess(processHandler); | ||
} | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(this.getCommandLine()); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "OSProcessStreamConnectionProvider [commandLine=" + this.getCommandLine() + "]"; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters