dense-analysis / ale

Check syntax in Vim/Neovim asynchronously and fix files, with Language Server Protocol (LSP) support
BSD 2-Clause "Simplified" License
13.57k stars 1.44k forks source link

Make it easier to determine project root for gopls #4470

Open FlashIvano opened 1 year ago

FlashIvano commented 1 year ago

ale/ale_linters/go/gopls.vim

Add following lines after line 26:

    if empty(l:project_root)
        let l:project_root = getcwd()
    endif
hsanson commented 1 year ago

Note that depending on the language server this may result on multiple language server instances being spawn for every file opened.

w0rp commented 1 year ago

The suggestion isn't right, and we won't be doing it, but there may be something we can do to make gopls work with more projects. Go project structure is even more rigid than most other languages. Could you tell us more about which files you are editing?

FlashIvano commented 1 year ago

A singel .go file is often used to make a simple command tool, because go can be used as a scripting language. Please refer to https://github.com/erning/gorun I think the right judgement sequence is go.work, go.mod, single file.

w0rp commented 1 year ago

@FlashIvano Could we set the project root to the cwd if we detect ^#! as the first line? (A regular expression) Would that be enough?

FlashIvano commented 1 year ago

@FlashIvano Could we set the project root to the cwd if we detect ^#! as the first line? (A regular expression) Would that be enough?

Maybe not appropriate. Because the solution still does not support GOPATH mode.

w0rp commented 1 year ago

What is "GOPATH mode?"