Skip to content

lsp-terraform.el fails to compile with recent lsp-mode due to keyword style mismatch #4805

Open
@StepaniaH

Description

@StepaniaH

Thank you for the bug report

  • I am using the latest version of lsp-mode related packages.
  • I checked FAQ and Troubleshooting sections
  • You may also try reproduce the issue using clean environment using the following command: M-x lsp-start-plain

Bug description

Environment:

  • Emacs Version: GNU Emacs 30.1
  • Operating System: macOS Sequoia Version 15.5
  • lsp-mode version: lsp-mode-20250531.74

Problem Description:
The clients/lsp-terraform.el file fails to byte-compile with recent versions of lsp-mode. This issue was not present in older versions of lsp-mode with the same lsp-terraform.el file.

Error Messages:
The compilation errors consistently follow a pattern where a hyphenated keyword is reported as "Unknown key," while the "Available keys" list suggests an underscored version of the same keyword is expected.

Examples of errors encountered:

  1. In construct-tf-module (around line 305 of lsp-terraform.el):
    Error: Unknown key: :docs-link. Available keys: (:name :docs_link :version :source_type :dependent_modules)
    (Initially, this also included errors for :source-type and :dependent-modules with the same pattern, where "Available keys" showed the underscored versions like :source_type, :dependent_modules if the pattern is consistent).

  2. In lsp-terraform-ls--providers-to-tf-package (around line 313 of lsp-terraform.el, after fixing the above):
    Error: Unknown key: :provider-requirements. Available keys: (:v :provider_requirements :installed_providers)
    (And likely for :installed-providers becoming :installed_providers if the pattern holds).

It appears this pattern (hyphenated keyword used, underscored keyword expected) applies to several multi-word keys within lsp-defun destructuring forms for &terraform-ls:* types.

Suspected Cause:
Given that lsp-terraform.el has been stable for a long time, these new compilation errors suggest a recent change in lsp-mode's core. This change likely affects how lsp-mode (particularly the lsp-defun macro or its underlying type validation system) keywordizes, parses, or expects multi-word keys from language server interactions or internal type definitions for terraform-ls. The system now seems to expect underscores for these specific keys instead of hyphens.

Impact:

  • lsp-terraform.el fails to compile.
  • LSP support for Terraform is unavailable.
  • A non-compiling client file can also lead to broader lsp-mode instability (e.g., unrelated UI errors were observed that resolved once this client's loading was prevented by fixing these compilation issues locally).

Proposed Solution / Next Steps:
I have a local fix that involves systematically updating these hyphenated keywords in lsp-terraform.el (within lsp-defun parameter destructuring for &terraform-ls:* types) to their underscored versions, and also updating the corresponding local variable names. This resolves all observed compilation errors for lsp-terraform.el.

I will submit a Pull Request with these changes shortly to make lsp-terraform.el compatible with the current lsp-mode core.

Steps to reproduce

  1. Ensure you are using a recent version of lsp-mode 20250531.742
  2. Have the standard lsp-mode package installed, which includes clients/lsp-terraform.el.
  3. Attempt to byte-compile clients/lsp-terraform.el. This can be done by:
    • Navigating to the lsp-mode installation directory (e.g., ~/.config/emacs/elpa/lsp-mode-[VERSION]/) and running M-x byte-compile-file on clients/lsp-terraform.el.
    • Or, observing the *Compile-Log* buffer after a fresh installation or update of lsp-mode which triggers automatic compilation.
  4. Check the *Compile-Log* buffer for compilation errors related to lsp-terraform.el.

Expected behavior

  • The clients/lsp-terraform.el file should compile successfully without any "Unknown key" errors.
  • If the terraform-ls language server is installed and configured, LSP functionality for Terraform (.tf) files should be available and working correctly.
  • The lsp-mode package as a whole should load and operate stably, without issues caused by a non-compiling client file.

Which Language Server did you use?

This error This error affected the overall compilation of lsp-mode, although I do not actually use lsp-terraform.

OS

MacOS

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions