nametake / golangci-lint-langserver

golangci-lint language server
MIT License
221 stars 20 forks source link

Helix Editor #35

Open PotatoesFall opened 11 months ago

PotatoesFall commented 11 months ago

Hi,

https://github.com/helix-editor/helix/ is a great editor and recently added support for multiple language servers. This should finally make it possible to use golangci-lint for diagnostics in the editor.

I'm wondering if anybody has been able to get this working. This is what I have in my languages.toml so far:

[[language]]
name = "go"
auto-format = true
formatter = { command = "goimports" }
language-servers = [
  { name = "golangci-lint-langserver", only-features = ["diagnostics"] },
  { name = "gopls", except-features = ["diagnostics"] },
]

[language-server.gopls]
command = "gopls"

[language-server.golangci-lint-langserver]
command = "golangci-lint-langserver"
config = { command = ["golangci-lint", "run", "--out-format", "json"] }

All my pre-existing config for gopls works just fine, but I'm not getting any diagnostics from golangci-lint.

Official Helix Docs

kranurag7 commented 11 months ago

I copied my config from the following PR on helix repo. https://github.com/helix-editor/helix/pull/8656

I'm also not getting any diagnostic errors. To confirm I disabled gopls in my languages.toml file.

language-servers = [ "golangci-lint-lsp" ]

Now, when I opened a main.go file from one of my project and executed the following commands then I got these messages.

:lsp-workspace-command
No active language servers for this document support workspace commands
:lsp-restart
Language server exited

For full reference, here's what my languages.toml file looks like without adding gopls

[[language]]
name = "go"
scope = "source.go"
injection-regex = "go"
file-types = ["go"]
roots = ["go.work", "go.mod"]
auto-format = true
comment-token = "//"
language-servers = [ "golangci-lint-lsp" ]
# TODO: gopls needs utf-8 offsets?
indent = { tab-width = 4, unit = "\t" }

[language-server.gopls]
command = "gopls"

[language-server.gopls.config.hints]
assignVariableTypes = true
compositeLiteralFields = true
constantValues = true
functionTypeParameters = true
parameterNames = true
rangeVariableTypes = true

[language-server.golangci-lint-lsp]
command = "golangci-lint-langserver"

[language-server.golangci-lint-lsp.config]
command = ["golangci-lint", "run", "--out-format", "json", "--issues-exit-code=1"]
oschwald commented 11 months ago

I also tried using this with helix and similarly did not receive the expected diagnostics. Looking at ~/.cache/helix/helix.log, I see errors such as:

2023-10-25T20:10:42.888 helix_lsp::transport [ERROR] golangci-lint-langserver err <- "golangci-lint-langserver: connections opened\n"
2023-10-25T20:10:42.891 helix_lsp::transport [ERROR] golangci-lint-langserver err <- "panic: runtime error: slice bounds out of range [1:0]\n"
2023-10-25T20:10:42.891 helix_lsp::transport [ERROR] golangci-lint-langserver err <- "\n"
2023-10-25T20:10:42.891 helix_lsp::transport [ERROR] golangci-lint-langserver err <- "goroutine 18 [running]:\n"
2023-10-25T20:10:42.891 helix_lsp::transport [ERROR] golangci-lint-langserver err <- "main.(*langHandler).lint(0xc00011c120, {0xc000152050?, 0x0?})\n"
2023-10-25T20:10:42.891 helix_lsp::transport [ERROR] golangci-lint-langserver err <- "\t/home/greg/MaxMind/go/pkg/mod/github.com/nametake/golangci-lint-langser
ver@v0.0.8/handler.go:57 +0x8d1\n"
2023-10-25T20:10:42.891 helix_lsp::transport [ERROR] golangci-lint-langserver err <- "main.(*langHandler).linter(0xc00011c120)\n"
2023-10-25T20:10:42.891 helix_lsp::transport [ERROR] golangci-lint-langserver err <- "\t/home/greg/MaxMind/go/pkg/mod/github.com/nametake/golangci-lint-langser
ver@v0.0.8/handler.go:122 +0x78\n"
2023-10-25T20:10:42.891 helix_lsp::transport [ERROR] golangci-lint-langserver err <- "created by main.NewHandler in goroutine 1\n"
2023-10-25T20:10:42.891 helix_lsp::transport [ERROR] golangci-lint-langserver err <- "\t/home/greg/MaxMind/go/pkg/mod/github.com/nametake/golangci-lint-langser
ver@v0.0.8/handler.go:20 +0xc9\n"
2023-10-25T20:10:42.891 helix_lsp::transport [ERROR] golangci-lint-langserver err: <- StreamClosed
necromeo commented 9 months ago

Is this still an issue? I have a language.toml that looks just like @kranurag7's and I am getting diagnostics. Enabled all linters for now until, still need to figure out which ones I really need.

Relevant excerpt

[language-server.golangci-lint-lsp]
command = "golangci-lint-langserver"

[language-server.golangci-lint-lsp.config]
command = [
  "golangci-lint",
  "run",
  "--enable-all",
  "--out-format",
  "json",
  "--issues-exit-code=1",
]

[[language]]
name = "go"
auto-format = false
text-width = 100
rulers = [100]
file-types = ["go"]
language-servers = ["gopls", "golangci-lint-lsp"]

Example:

image
oschwald commented 9 months ago

With a config similar to that, it seems to be working for me.

David-Else commented 7 months ago

golangci-lint-langserver is built into Helix by default now: https://github.com/helix-editor/helix/pull/8656 :)