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

vscode-extensions.hashicorp.terraform: Init at 2.3.0 #110505

Closed
wants to merge 1 commit into from

Conversation

andyrichardson
Copy link
Contributor

Motivation for this change
Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS linux)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Ensured that relevant documentation is up to date
  • Fits CONTRIBUTING.md.

@SuperSandro2000 SuperSandro2000 changed the title vscode-extensions.hashicorp.trraform: Init at 2.3.0 vscode-extensions.hashicorp.terraform: Init at 2.3.0 Jan 22, 2021
@SuperSandro2000
Copy link
Member

Please fix the typo in your commit.

@SuperSandro2000
Copy link
Member

This is a semi-automatic executed nixpkgs-review which is checked by a human on a best effort basis and does not build all packages (e.g. lumo, tensorflow or pytorch).
If you have any questions or problems please reach out to SuperSandro2000 on IRC.

Result of nixpkgs-review pr 110505 run on x86_64-linux 1

1 package built:
  • vscode-extensions.hashicorp.terraform

@rhoriguchi
Copy link
Contributor

rhoriguchi commented Jan 23, 2021

I tried this as well but the extension won't really run correctly if you just build it as an extension with no buildInputs. What you are missing is the Terraform Language Server Nix has a package for it.

The syntax highlighting does work but the language features do not and you get an error every time you open VS Code.

image

@rhoriguchi
Copy link
Contributor

rhoriguchi commented Jan 23, 2021

This is what I've tried till now, but still getting an error:

hashicorp.terraform = ((vscode-utils.extensionFromVscodeMarketplace {
  name = "terraform";
  publisher = "hashicorp";
  version = "2.3.0";
  sha256 = "0696q8nr6kb5q08295zvbqwj7lr98z18gz1chf0adgrh476zm6qq";
}).overrideAttrs (oldAttrs: {
  buildInputs = oldAttrs.buildInputs ++ [ pkgs.terraform-ls ];

  meta = with lib; {
    license = licenses.mit;
  };
}));

After going through the source of the extension, I think building from source and replacing these lines with command = "[TERRAFORM LS PATH]" should do the trick.

@rhoriguchi
Copy link
Contributor

rhoriguchi commented Jan 24, 2021

@andyrichardson So had some time today and I figured it out. This is how I got it to work:

hashicorp.terraform = callPackage ./hashicorp-terraform {};

default.nix

{ lib, fetchurl, vscode-utils, terraform-ls }:

vscode-utils.buildVscodeMarketplaceExtension rec {
  mktplcRef = {
    name = "terraform";
    publisher = "hashicorp";
    version = "2.4.0";
  };

  vsix = fetchurl {
    name = "${mktplcRef.publisher}-${mktplcRef.name}.zip";
    url = "https://github.com/hashicorp/vscode-terraform/releases/download/v${mktplcRef.version}/terraform-${mktplcRef.version}.vsix";
    sha256 = "14waz0yv25f4l46y84px2g58qnawbzp1p24zrfjqlxmp99kx009n";
  };

  patches = [ ./fix-terraform-ls.patch ];

  postPatch = ''
    substituteInPlace out/extension.js --replace TERRAFORM-LS-PATH ${terraform-ls}/bin/terraform-ls
  '';

  meta = with lib; { 
    license = licenses.mit; 
  };
}

fix-terraform-ls.patch

diff --git a/out/extension.js b/out/extension.js
index 1de8aab..e2b3a3e 100644
--- a/out/extension.js
+++ b/out/extension.js
@@ -204,19 +204,7 @@ function pathToBinary() {
         if (!_pathToBinaryPromise) {
             let command = vscodeUtils_1.config('terraform').get('languageServer.pathToBinary');
             if (!command) { // Skip install/upgrade if user has set custom binary path
-                const installDir = `${extensionPath}/lsp`;
-                const installer = new languageServerInstaller_1.LanguageServerInstaller();
-                try {
-                    yield installer.install(installDir);
-                }
-                catch (err) {
-                    vscode.window.showErrorMessage(err);
-                    throw err;
-                }
-                finally {
-                    yield installer.cleanupZips(installDir);
-                }
-                command = `${installDir}/terraform-ls`;
+                command = 'TERRAFORM-LS-PATH';
             }
             _pathToBinaryPromise = Promise.resolve(command);
         }

@andyrichardson
Copy link
Contributor Author

@rhoriguchi thanks for helping out on this!

What you are missing is the Terraform Language Server

When users typically install the package to VSCode (without nix) it also doesn't install the language server, no?

While the plugin can optionally integrate with a system-level language server, I'm unsure why it would be required as a build dependency?

@SuperSandro2000
Copy link
Member

When users typically install the package to VSCode (without nix) it also doesn't install the language server, no?

Because if it should work on multiple linux versions you can't easily install it for the package manager. One way around this is to vendor it which has its own problems.

While the plugin can optionally integrate with a system-level language server, I'm unsure why it would be required as a build dependency?

This is a common thing to do in nixpkgs so that we have everything for it to run and you do not need to install something in your user environment.

@rhoriguchi
Copy link
Contributor

rhoriguchi commented Jan 25, 2021

When users typically install the package to VSCode (without nix) it also doesn't install the language server, no?

When you install the extension and you open a .tf file it will try to download the language server. The only way to not make it auto-download, is to manually set the option: terraform.languageServer.pathToBinary. Otherwise, it will always check the installation and will download or update it. The issue with nix is, that the store is read-only so it has no way to install it, which causes that error.


Here are some other extensions that also have the language server bundled:

@andyrichardson
Copy link
Contributor Author

andyrichardson commented Jan 26, 2021

When you install the extension and you open a .tf file it will try to download the language server

Ahh thanks for explaining - so the issue is that it tries to write to our immutable extension dir. That makes sense 👍

I was assuming the language server was external (similar to how TS works)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants