Skip to content

Commit

Permalink
feat: Hermit support
Browse files Browse the repository at this point in the history
This piggy backs on the Hermit plugin to get the correct FTL version.
  • Loading branch information
stuartwdouglas committed Aug 30, 2024
1 parent f095c2f commit 0153a47
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
2 changes: 1 addition & 1 deletion extensions/intellij/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ tasks {

patchPluginXml {
sinceBuild.set("241")
untilBuild.set("241.*")
untilBuild.set("242.*")
}

signPlugin {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@ import com.intellij.execution.configurations.GeneralCommandLine
import com.intellij.execution.process.OSProcessHandler
import com.intellij.execution.process.ProcessAdapter
import com.intellij.execution.process.ProcessEvent
import com.intellij.ide.DataManager
import com.intellij.openapi.project.Project
import com.intellij.openapi.util.Key
import com.intellij.openapi.vfs.VirtualFile
import com.intellij.openapi.wm.ToolWindowManager
import com.intellij.platform.lsp.api.LspServerNotificationsHandler
import com.intellij.platform.lsp.api.ProjectWideLspServerDescriptor
import com.intellij.tools.ToolsCustomizer
import xyz.block.ftl.intellij.toolWindow.FTLMessagesToolWindowFactory
import java.util.concurrent.CompletableFuture
import java.util.regex.Pattern

class FTLLspServerDescriptor(project: Project) : ProjectWideLspServerDescriptor(project, "FTL") {
Expand All @@ -26,13 +30,46 @@ class FTLLspServerDescriptor(project: Project) : ProjectWideLspServerDescriptor(
generalCommandLine.setWorkDirectory(project.basePath)
displayMessageInToolWindow("LSP Server Command: " + generalCommandLine.commandLineString)
displayMessageInToolWindow("Working Directory: " + generalCommandLine.workDirectory)
try {
// Hermit support, we need to get the environment variables so we use the correct FTL
val result = CompletableFuture<GeneralCommandLine>()
runOnEDT {
val toolWindow = ToolWindowManager.getInstance(project).getToolWindow("FTL")
if (toolWindow != null) {
val dataContext = DataManager.getInstance().getDataContext(toolWindow.component)
val customizeCommandLine =
ToolsCustomizer.customizeCommandLine(generalCommandLine, dataContext)
result.complete(customizeCommandLine)
}
}
val res = result.get()
return if (res != null) res else generalCommandLine
} catch (e: Exception) {
displayMessageInToolWindow("Failed to customize LSP Server Command: " + e.message)
}
return generalCommandLine
}

override fun startServerProcess(): OSProcessHandler {
displayMessageInToolWindow("Starting FTL LSP Server")
val processHandler = super.startServerProcess()
processHandler.addProcessListener(object : ProcessAdapter() {

override fun startNotified(event: ProcessEvent) {
super.startNotified(event)
displayMessageInToolWindow("LSP Started")
}

override fun processTerminated(event: ProcessEvent) {
super.processTerminated(event)
displayMessageInToolWindow("LSP Terminated")
}

override fun processWillTerminate(event: ProcessEvent, willBeDestroyed: Boolean) {
super.processWillTerminate(event, willBeDestroyed)
displayMessageInToolWindow("LSP Will Terminate")
}

override fun onTextAvailable(event: ProcessEvent, outputType: Key<*>) {
val message = event.text.trim()
if (message.isNotBlank()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class FTLSettingsConfigurable : Configurable {
override fun apply() {
val state = AppSettings.getInstance().state
state.lspServerPath = mySettingsComponent?.getLspServerPath() ?: "ftl"
state.lspServerArguments = mySettingsComponent?.getLspServerArguments() ?: "--recreate --lsp"
state.lspServerArguments = mySettingsComponent?.getLspServerArguments() ?: " dev --recreate --lsp"
state.lspServerStopArguments = mySettingsComponent?.getLspServerStopArguments() ?: "serve --stop"
}

Expand Down

0 comments on commit 0153a47

Please sign in to comment.