简体   繁体   English

如何将实验语言服务器添加到 vscode 的开发容器中?

[英]How do I add the experimental language server to a devcontainer for vscode?

I'm doing a pretty basic devcontainer for terraform work in VSCode on Windows.我正在为 Windows 上的 VSCode 中的 terraform 工作做一个非常基本的 devcontainer。 Every time I start it up or rebuild the container for use, it prompts me to install the experimental language server where I end up picking the latest tag for it (v0.0.9).每次我启动它或重建容器以供使用时,它都会提示我安装实验语言服务器,我最终会在其中选择最新的标签 (v0.0.9)。

I have the following setting configured in my default settings.json file我在默认 settings.json 文件中配置了以下设置

{
    "terraform.languageServer.enabled": true
}

and my .devcontainer/devcontainer.json is taken and minimized from the Azure terraform container.我的 .devcontainer/devcontainer.json 是从 Azure terraform 容器中获取并最小化的。

// For format details, see https://aka.ms/vscode-remote/devcontainer.json or the definition README at
// https://github.com/microsoft/vscode-dev-containers/tree/master/containers/docker-existing-dockerfile
{
    // See https://aka.ms/vscode-remote/devcontainer.json for format details.
    "name": "DevOps Projects IaC With Terraform",
    "context": "..",
    "dockerFile": "Dockerfile",
    "runArgs": [ 
        "-v", "${env:USERPROFILE}/.ssh:/root/.ssh-localhost:ro", 
        "-v", "${env:USERPROFILE}/.aws:/root/.aws:ro"
    ],

    "postCreateCommand": "mkdir -p ~/.ssh && cp -r ~/.ssh-localhost/* ~/.ssh && chmod 700 ~/.ssh && chmod 600 ~/.ssh/*",

    // Add the IDs of any extensions you want installed in the array below.
    "extensions": ["mauve.terraform"]
}

How do I include the experimental language server into my build/devcontainer config?如何将实验语言服务器包含到我的构建/开发容器配置中?

I've been trying to figure out the answer to this for a while, for my own purposes.为了我自己的目的,我一直试图找出这个问题的答案。 I decided today that I was going to figure it out and I believe I have it working (installing terraform, the LSP and the AWS provider) using我今天决定要弄清楚,我相信我可以使用它(安装 terraform、LSP 和 AWS 提供商)

# Terraform, LSP and AWS Provider
ENV TERRAFORM_VERSION=0.12.24
ENV TERRAFORM_LSP_VERSION=0.0.10
ENV TERRAFORM_AWS_PROVIDER_VERSION=2.59.0

RUN wget -c https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_linux_amd64.zip \
    && unzip terraform_${TERRAFORM_VERSION}_linux_amd64.zip \
    && mv terraform /usr/local/bin \
    && wget -c https://releases.hashicorp.com/terraform-provider-aws/${TERRAFORM_AWS_PROVIDER_VERSION}/terraform-provider-aws_${TERRAFORM_AWS_PROVIDER_VERSION}_linux_amd64.zip \
    && unzip terraform-provider-aws_${TERRAFORM_AWS_PROVIDER_VERSION}_linux_amd64.zip \
    && mv terraform-provider-aws_v${TERRAFORM_AWS_PROVIDER_VERSION}* /usr/local/bin \
    && echo "provider \"aws\" {}" >> /usr/local/bin/providers.tf \
    && wget -c https://github.com/juliosueiras/terraform-lsp/releases/download/v${TERRAFORM_LSP_VERSION}/terraform-lsp_${TERRAFORM_LSP_VERSION}_linux_amd64.tar.gz -O - | tar -zx \
    && mv terraform-lsp /usr/local/bin \
    && rm terraform*.zip

because I'm installing this to /usr/local/bin and I'm creating a containerUser which wouldn't have access to install these components, I needed to add the following to the settings section of my devcontainer.json因为我正在将它安装到 /usr/local/bin 并且我正在创建一个无法安装这些组件的containerUser ,所以我需要将以下内容添加到我的 devcontainer.json 的settings部分

        "terraform.indexing": {
            "enabled": false
        },
        "terraform.languageServer": {
            "enabled": true,
            "installCommonProviders": false,
            "pathToBinary": "/usr/local/bin"
        },

Obviously you need to make adjustments if you want other providers, or to install it elsewhere, or different versions of terraform, the LSP or the AWS provider, but they all should be simple changes.显然,如果您想要其他提供商,或者将其安装在其他地方,或者不同版本的 terraform、LSP 或 AWS 提供商,则需要进行调整,但它们都应该是简单的更改。

The latest releases can be found at the following links:最新版本可以在以下链接中找到:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将 Pulumi 添加到我的 GitHub Codespaces / VSCode .NET devcontainer? - How do I add Pulumi to my GitHub Codespaces / VSCode .NET devcontainer? "如何在 VSCode .devcontainer 中指定特定的更漂亮的版本?" - How do I specify a specific prettier version in a VSCode .devcontainer? 如何增加 VSCode DevContainer 中的 CPU 和 RAM? - How Do I Increase the CPU & RAM in a VSCode DevContainer? 如何在 vscode 之外构建和运行 a.devcontainer 文件夹? - How can I build and run a .devcontainer folder outside vscode? 如何在不在 devcontainer.json 中对其进行硬编码的情况下将 mount 绑定到 vscode devcontainer - How can I bind mount to a vscode devcontainer without hard-coding it in devcontainer.json 如何在 VSCode 开发容器中使用 minikube? - How to use minikube in VSCode devcontainer? 扩展时如何在VSCODE上发布LSP语言服务器 - How to publish a LSP language server on VSCODE as we do extension 如何在 devcontainer 中分离强制扩展和个人扩展 - How do I separate mandatory extensions and personal extensions in devcontainer 如何让语言特定命令在 VSCode 中工作? - How do I get language specif commands to work in VSCode? 如何在VSCode扩展名中为语言设置缩进选项? - How do I set indenting options for a language in a VSCode extension?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM