sourcegraph / go-langserver

Go language server to add Go support to editors and other tools that use the Language Server Protocol (LSP)
https://sourcegraph.com
MIT License
1.17k stars 89 forks source link

Support alternate linters #314

Closed ckaznocha closed 5 years ago

ckaznocha commented 6 years ago

Hi! Some users of my client are looking to use alternate linters for diagnostics, specifically golangci/golangci-lint. Could multiple linters be supported much like multiple formatters are now supported? I'd be happy to send a PR but I may not be able to get to it for a while.

For reference: https://github.com/ckaznocha/ide-go/issues/31

Thanks!

keegancsmith commented 6 years ago

Yeah this seems like a very reasonable feature request. One potential issue is the code in your editor is not necessarily the code on disk. So a requirement for integrating a linter would be it supporting linting a file, but us sending the contents of it over stdin/etc.

ianlopshire commented 6 years ago

I'm currently working on getting this implemented.

As far as I can tell, the language server doesn't currently implement any linting. The only diagnostics come from type checking errors. I'm not missing anything am I?

vscode-go currently supports golint, gometalinter, megacheck, golangci-lint, and revive. I think gometalinter and golangci-lint would be a good start.

keegancsmith commented 6 years ago

@ianlopshire thanks! Yes there is no support for linters currently. There are two routes you can take here:

Shelling out is likely the easiest and most maintainable approach for now. Unless of course a linter exposes a nice API to use.

ianlopshire commented 6 years ago

@keegancsmith I've started down the shelling out path. From what I can see none of the popular linters will read from stdin. I understand this will prevent linting from being ran on unsaved files, but is there any reason not to implement lint on save (textDocument/didSave)?

My WIP implementation does this and it seems to work, but I want to make sure I'm not going down a dead end.

keegancsmith commented 6 years ago

great. on save seems fine to me.

keegancsmith commented 5 years ago

We have support now for linters, and it is relatively easy to add support for more now. Thanks @ianlopshire!