terramate-io / terramate

Terramate CLI is an open-source Infrastructure as Code (IaC) Orchestration and Code Generation tool for Terraform, OpenTofu and Terragrunt.
https://terramate.io
Mozilla Public License 2.0
3.24k stars 91 forks source link

[FEATURE] JetBrains plugin #889

Open az-z opened 1 year ago

az-z commented 1 year ago

Is your feature request related to a problem? Please describe. It would be great to have a plugin for JetBrains IDEs.

i4ki commented 1 year ago

Hi @az-z

I have good and bad news =/

I never used the JetBrains IDEs but I looked at how plugins work in the IntelliJ family of IDEs:

IntelliJ IDEA, GoLand, etc

The IntelliJ plugins are based on the Gradle build system and they could be developed using Kotlin, Groovy, or Java. This means that developing a plugin for Terramate will involve coding the parser again in one of these languages and keeping it up to date with Terramate development. As an example, here's the HCL parser implemented in Java for the IntelliJ terraform plugin.

Then, the bad news is that implementing a native IntelliJ plugin is not going to happen anytime soon and the Jetbrains IDEs don't natively support LSP then maybe only if the community contributes one but still very unlikely because of the amount of work needed.

The good news is that in the Jetbrains Marketplace there are some plugins that implement the LSP client, see here: https://plugins.jetbrains.com/search?products=idea&search=lsp and then if they work fine then we can use our Language Server with them.

I tried the LSP Support Plugin and it "worked".

See the screenshot below:

Screenshot_2023-04-03_23-12-37

But after some seconds the "Problems" panel is cleared... I looked at the IDE logs and found this stack trace:

2023-04-03 22:41:42,559 [ 878045] SEVERE - #c.i.i.p.PluginManager - Invalid range specified: (37, 36); 
java.lang.IllegalArgumentException: Invalid range specified: (37, 36); 
    at com.intellij.openapi.util.TextRange.assertProperRange(TextRange.java:231)
    at com.intellij.openapi.util.TextRange.assertProperRange(TextRange.java:226)
    at com.intellij.openapi.util.TextRange.assertProperRange(TextRange.java:222)
    at com.intellij.openapi.util.TextRange.<init>(TextRange.java:41)
    at com.intellij.openapi.util.TextRange.<init>(TextRange.java:30)
    ...
    truncated

so it looks like the Terramate Language Server is sending an invalid range. This never triggers on VSCode then maybe VSCode just handle bad ranges nicely. The same issue happens with GoLand.

I created the issue https://github.com/mineiros-io/terramate-ls/issues/33 and I will investigate the cause when I have time.

Jetbrains Fleet

The Fleet supports LSP as documented here but they don't support custom languages... The languages that they support LSP have their language-servers bundled into Fleet. Maybe in the future they add an option for custom languages and then maybe Terramate will be supported right away.

Syntax Highlight

The Terramate VSCode Extension implements Syntax Highlight using the TextMate Grammar and Jetbrains supports the same format. I tried to just use the same grammar file and it partially applied the highlight, most constructs were not highlighted... It seems the VSCode implementation differs a bit but with some tweaks we can probably make it work with low effort.

If someone wants to check this, what I did was just press CTRL + ALT + S then go to Editor -> TextMate Bundles and then click in + to import a bundle and then select the directory of the cloned vscode-terramate repo. This answer in the Jetbrains issue tracker says that this should work.

This was just an initial investigation for supporting Jetbrains IDEs and I will update this issue when I have more information about the problems I mentioned. Thanks for bringing this to our attention.

i4ki commented 1 year ago

@az-z the problem with terramate-ls only happens with latest (v0.0.7) but works fine with v0.0.6.