Skip to content

Bug: Kotlin Language Server interferes with edit_file tool causing data loss and file reversions #44

@phreed

Description

@phreed

Bug Report: Kotlin Language Server interferes with edit_file tool causing data loss and file reversions

Summary:
When the Kotlin Language Server is enabled, Zed's edit_file tool exhibits severe malfunctioning behavior on build.gradle.kts files, causing unwanted changes, data loss, and file reversions to cached/stale versions.

Environment:

  • OS: Linux
  • File type: build.gradle.kts (Kotlin Gradle build script)
  • LSP: kotlin-language-server configured in .zed/settings.json

Reproduction Steps:

  1. Open a project with a build.gradle.kts file
  2. Configure Kotlin Language Server in .zed/settings.json:
    {
      "lsp": {
        "kotlin-language-server": {
          "settings": {
            "compiler": {
              "jvm": {
                "target": "17"
              }
            }
          }
        }
      }
    }
  3. Make manual changes to build.gradle.kts (e.g., replace hardcoded dependency versions with Gradle version catalog references)
  4. Attempt any edit using edit_file tool, even adding a simple comment

Expected Behavior:
The edit_file tool should make only the requested changes to the current file state on disk.

Actual Behavior:

  • The tool reverts all manual changes back to an old cached version
  • Makes massive unwanted modifications (e.g., changing plugin versions, reverting dependency references, adding unrequested code)
  • Sometimes reports "No edits were made" when changes should have been applied
  • Completely ignores the current file state on disk

Key Evidence:

  • File on disk: kotlin("multiplatform") version "2.2.0" (current)
  • After edit_file: kotlin("multiplatform") version "2.1.0" (reverted to old version)
  • Manual version catalog changes: Completely reverted to hardcoded versions
  • Other Kotlin files: edit_file works normally on regular .kt source files

Workaround Discovered:
Setting "enable_language_server": false in .zed/settings.json completely resolves the issue. With LSP disabled, edit_file works correctly and makes only the requested changes.

Root Cause Analysis:
The Kotlin Language Server appears to maintain its own cached version of build.gradle.kts files and interferes with file editing operations, overriding changes with stale data.

Impact:

  • Critical data loss risk: Manual work gets silently reverted
  • Development workflow disruption: Cannot reliably edit Gradle build files
  • Tool unreliability: edit_file becomes unusable for Kotlin projects with LSP enabled

Expected Fix:
The edit_file tool should either:

  1. Coordinate with LSP servers to ensure file state consistency, or
  2. Temporarily disable LSP interference during editing operations, or
  3. Always read the actual file state from disk rather than from LSP caches

This appears to be a critical integration issue between Zed's editing tools and language server protocol implementation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions