Skip to content

Instantly share code, notes, and snippets.

@yasudacloud
Created July 14, 2023 13:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yasudacloud/c7c80f1a2f09fc135c96d57d10c0bc69 to your computer and use it in GitHub Desktop.
Save yasudacloud/c7c80f1a2f09fc135c96d57d10c0bc69 to your computer and use it in GitHub Desktop.
ex) IntelliJ LSP Plugin for Terraform
package com.example.demo1
import com.intellij.execution.configurations.GeneralCommandLine
import com.intellij.openapi.project.Project
import com.intellij.openapi.vfs.VirtualFile
import com.intellij.platform.lsp.api.*
class FooLspServerSupportProvider : LspServerSupportProvider {
override fun fileOpened(
project: Project,
file: VirtualFile,
serverStarter: LspServerSupportProvider.LspServerStarter
) {
if (file.extension == "tf") {
serverStarter.ensureServerStarted(FooLspServerDescriptor(project))
}
}
}
private class FooLspServerDescriptor(project: Project) : ProjectWideLspServerDescriptor(project, "Foo") {
override val lspGoToDefinitionSupport = false
override fun isSupportedFile(file: VirtualFile) = file.extension == "tf"
override fun createCommandLine(): GeneralCommandLine {
val commandLine = GeneralCommandLine()
commandLine.withExePath("terraform-ls")
commandLine.addParameters(
"serve",
)
return commandLine
}
override fun getLanguageId(file: VirtualFile): String {
return "terraform"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment