Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Editor Setup instructions for Vim + vim-go #3056

Closed
bcspragu opened this issue Jan 23, 2022 · 2 comments · Fixed by #3057
Closed

Editor Setup instructions for Vim + vim-go #3056

bcspragu opened this issue Jan 23, 2022 · 2 comments · Fixed by #3057

Comments

@bcspragu
Copy link
Contributor

(I removed all the template questions because this isn't a bug)

Hi there!

I recently configured my Vim setup to work with the new-ish rules_go packages driver, and I wanted to update the Editor setup wiki page with instructions.

I figured I'd check in first to see 1) if that was a welcome contribution, and 2) how to go about submitting a wiki PR/contribution. I came across these suggestions in searching around.

It's also worth noting that this is my first foray into Vimscript, and it's likely hideous to someone more familiar with it.

The TL;DR:

.vimrc update
function! MaybeSetGoPackagesDriver()
  " Start at the current directory and see if there's a WORKSPACE file in the
  " current directory or any parent. If we find one, check if there's a
  " gopackagesdriver.sh in a tools/ directory, and point our
  " GOPACKAGESDRIVER env var at it.
  let l:dir = getcwd()
  while l:dir != "/"
    if filereadable(simplify(join([l:dir, 'WORKSPACE'], '/')))
      let l:maybe_driver_path = simplify(join([l:dir, 'tools/gopackagesdriver.sh'], '/'))
      if filereadable(l:maybe_driver_path)
        let $GOPACKAGESDRIVER = l:maybe_driver_path
        break
      end
    end
    let l:dir = fnamemodify(l:dir, ':h')
  endwhile
endfunction

call MaybeSetGoPackagesDriver()

" See https://github.com/golang/tools/blob/master/gopls/doc/settings.md
let g:go_gopls_settings = {
  \ 'build.directoryFilters': [
    \ '-bazel-bin',
    \ '-bazel-out',
    \ '-bazel-testlogs',
    \ '-bazel-mypkg',
  \ ],
  \ 'ui.completion.usePlaceholders': v:true,
  \ 'ui.semanticTokens': v:true,
  \ 'ui.codelenses': {
    \ 'gc_details': v:false,
    \ 'regenerate_cgo': v:false,
    \ 'generate': v:false,
    \ 'test': v:false,
    \ 'tidy': v:false,
    \ 'upgrade_dependency': v:false,
    \ 'vendor': v:false,
  \ },
\ }
@achew22
Copy link
Member

achew22 commented Jan 24, 2022

We do have a new /docs directory that I, for one, would be happy to see this added to. Of course, only if you're interested.

@bcspragu
Copy link
Contributor Author

Sounds good, I've created a PR to add that to docs/go/editors/. This does mean editor documentation is fragmented between the wiki and the docs/ directory though, we'll likely want to either merge these docs into the wiki, or move the existing editor setup wiki page to docs/ (and leave a link to docs/ on the wiki page, to not break existing links)

achew22 pushed a commit that referenced this issue Feb 4, 2022
* Add editor setup instructions for Vim + vim-go

Addresses #3056 by adding
basic instructions to get `gopls` working with autogenerated Bazel
files. Tested locally and working for protobuf as well as custom Bazel
rules + macros that generate `go_library` targets.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants