zed icon indicating copy to clipboard operation
zed copied to clipboard

LSPs attaching to wrong file types

Open bloveless opened this issue 5 months ago • 3 comments

Summary

When editing proto or yaml files in a go monolith I'm getting errors from golangci-lint. I assume that the golangci-lint extension shouldn't be running on those files nor outputting errors from the go LSP.

Description

I've installed to golangci-lint extension. I had to add some configuration to the extension to be able to run it against golangci-lint v2.

    "golangci-lint": {
      "initialization_options": {
        "command": ["golangci-lint", "run", "--output.json.path=stdout", "--show-stats=false", "--issues-exit-code=1"]
      }
    },

I've also tried explicitly removing the extension from proto

    "Proto": {
      "format_on_save": "off",
      "language_servers": ["!golangci-lint", "..."],
      "formatter": {
        "external": {
          "arguments": ["format", "{buffer_path}"],
          "command": "buf"
        }
      }
    },

I've also tried to disable proto files from the golang ci lint config in both the linters and formatters section

linters:
  ...
  exclusions:
    paths:
      - "proto/*"
      - ".*\\.proto$"

formatters:
  ...
  exclusions:
    paths:
      - "proto/*"
      - ".*\\.proto$"

If I disable the extension then I don't get any errors. I also noticed that if I start working in a proto file then I can exit it to my hearts content without this issue appearing. As soon as I switch to a go file, presumably the golangci-lint lsp starts, and if I go back to a proto file then I'll again see error output from golangci-lint.

In the following screenshot you can see the error attached to a proto file. That error comes from golangci-lint and it is correct. There are no go files in that directory only a proto file.

Image

Same issue with yaml files ironically this error is on the golangci lint config yaml.

Image

I can reproduce the error by running the golangci-lint command directly in the cli in the root of the project (no go files there)

Image

Or in a proto directory (again no go files there)

Image

Expected Behavior: No golangci-lint errors are shown in proto or yaml files.

Actual Behavior: Errors are shown. I've never noticed this with any other LSP so I wonder if it something specific to golangci-lint or v2?

Zed Version and System Specs

Zed: v0.189.5 (Zed Preview) OS: macOS 15.5.0 Memory: 32 GiB Architecture: aarch64

bloveless avatar Jun 03 '25 20:06 bloveless

I think it's a problem with golangci-lint in general, see this issue with the golangci-lint zed extension.

MrPointer avatar Jun 03 '25 20:06 MrPointer

Funny I didn't look in the golangci-lint zed extension issues list. I'm still curious though aren't LSPs attached to specific files instead of the entire workspace? Even if golangci-lint doesn't like directories that don't have go files in them, should zed still be reporting the error? I suppose that is why I felt like it made sense to live in the main zed repo.

Or maybe I don't understand how LSPs work and that they do attach to the entire workspace and are responsible for filtering files on their own?

bloveless avatar Jun 03 '25 20:06 bloveless

Yeah, this sounds like an upstream LSP issue. I've seen something similar with the OmniSharp LSP:

  • https://github.com/zed-extensions/csharp/issues/1

Can you provide a minimal repository with files and steps that trigger this behavior? Make sure to include any Zed extensions you have installed and .zed/settings.json inside the project with relevant settings.

notpeter avatar Jun 03 '25 20:06 notpeter

This is about as simple as possible. To reproduce the error all I did was clicked on a go file then clicked on a proto file. I'll also include my settings.json here.

golangci-repo.zip

// Zed settings
//
// For information on how to configure Zed, see the Zed
// documentation: https://zed.dev/docs/configuring-zed
//
// To see all of Zed's default settings without changing your
// custom settings, run the `open default settings` command
// from the command palette or from `Zed` application menu.
// For reference: https://romanzipp.com/blog/must-have-zed-settings
{
  "auto_install_extensions": {
    "catppuccin-icons": true,
    "golangci-lint": true
  },
  "minimap": {
    "show": "auto",
    "thumb": "always",
    "thumb_border": "none"
  },
  "theme": {
    "dark": "Gruvbox Dark Soft",
    "light": "Gruvbox Light Soft",
    "mode": "system"
  },
  "icon_theme": "Catppuccin Frappé",
  "vim_mode": true,
  "vim": {
    "use_smartcase_find": true,
    "use_system_clipboard": "always"
  },
  "buffer_font_family": "Fira Code",
  "buffer_font_size": 12,
  "buffer_line_height": {
    "custom": 2
  },
  "buffer_font_features": {
    // disable ligatures
    "calt": false
  },
  "ui_font_family": "Fira Code",
  "ui_font_features": {
    // disable ligatures
    "calt": false
  },
  "ui_font_size": 12,
  "agent_font_size": 13,
  "show_whitespaces": "selection",
  "preferred_line_length": 120,
  "wrap_guides": [120],
  "tab_size": 4,
  "tabs": {
    "file_icons": true,
    "git_status": true,
    "show_diagnostics": "all"
  },
  "use_multiline_find": true,
  "vertical_scroll_margin": 15,
  "tab_bar": {
    "show": true,
    "show_nav_history_buttons": false
  },
  "features": {
    "edit_prediction_provider": "copilot"
  },
  "show_edit_predictions": true,
  "edit_predictions": {
    "enabled_in_text_threads": false,
    "mode": "subtle"
  },
  "agent": {
    "always_allow_tool_actions": true,
    "default_model": {
      "model": "claude-3.7-sonnet",
      "provider": "copilot_chat"
    },
    "version": "2"
  },
  "outline_panel": {
    "dock": "right"
  },
  "bottom_dock_layout": "contained",
  "project_panel": {
    "indent_size": 10
  },
  "inline_code_actions": false,
  "terminal": {
    "shell": {
      "program": "/opt/homebrew/bin/fish"
    }
  },
  "file_types": {
    "Blade": ["*.blade.php"],
    "Helm": [
      "**/templates/**/*.tpl",
      "**/templates/**/*.yaml",
      "**/templates/**/*.yml",
      "**/helmfile.d/**/*.yaml",
      "**/helmfile.d/**/*.yml"
    ],
    "SQL": ["ddl", "dml"]
  },
  "languages": {
    "Go": {
      "language_servers": ["gopls", "golangci-lint"]
    },
    "JSON": {
      "prettier": {
        "allowed": false
      },
      "tab_size": 2
    },
    "JSONC": {
      "tab_size": 2
    },
    "JavaScript": {
      "formatter": {
        "external": {
          "arguments": ["prettier", "--stdin-filepath", "{buffer_path}"],
          "command": "npx"
        }
      }
    },
    "Markdown": {
      // do not remove any trailing whitespace since line breaks in
      // lists (without adding a new punctuation) rely on whitespaces.
      "remove_trailing_whitespace_on_save": false,
      // Wrap text according to the previously defined preferred line length.
      "soft_wrap": "preferred_line_length"
    },
    "PHP": {
      "prettier": {
        "allowed": false
      }
    },
    "Proto": {
      "format_on_save": "off",
      "formatter": {
        "external": {
          "arguments": ["format", "{buffer_path}"],
          "command": "buf"
        }
      }
    },
    "SQL": {
      "format_on_save": "off"
    },
    "YAML": {
      "tab_size": 2
    }
  },
  "lsp": {
    "golangci-lint": {
      "initialization_options": {
        "command": ["golangci-lint", "run", "--output.json.path=stdout", "--show-stats=false", "--issues-exit-code=1"]
      }
    },
    "gopls": {
      "initialization_options": {
        "gofumpt": true,
        "local": "github.com/shadowglass-xyz,github.com/bloveless"
      }
    }
  }
}

Installed extensions

html
catppuccin
toml
dockerfile
php
git-firefly
sql
tokyo-night
make
scss
terraform
elixir
xml
zig
catppuccin-icons
docker-compose
dart
kotlin
nord
golangci-lint
proto
rose-pine-theme
blade
colored-zed-icons-theme
codebook

bloveless avatar Jun 04 '25 05:06 bloveless

Hi there! 👋 We're working to clean up our issue tracker by closing older bugs that might not be relevant anymore. If you are able to reproduce this issue in the latest version of Zed, please let us know by commenting on this issue, and it will be kept open. If you can't reproduce it, feel free to close the issue yourself. Otherwise, it will close automatically in 14 days. Thanks for your help!

github-actions[bot] avatar Nov 19 '25 11:11 github-actions[bot]

not stale

notpeter avatar Nov 19 '25 19:11 notpeter