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

feat: Add gopls.sh #829

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

feat: Add gopls.sh #829

wants to merge 1 commit into from

Conversation

richardlarocque
Copy link
Contributor

Adds a gopls.sh script that provides a asdf-aware way to start a
gopls LSP server. This script helps my Emacs load and run the right
gopls for any given project.

To my fellow Emacs users, I offer these configs as an example:

(defun find-stencil-root ()
  "Finds the directory that contains stencil.lock"
  ()
  (message "evaluating find-stencil-root")
  (locate-dominating-file "." "stencil.lock"))

(defun stencil-go-setup ()
  "A go-mode hook for Outreach stencil projects"
  ()
  (let
      ((stencil-root (find-stencil-root)))
    (if stencil-root
        (progn
          (setq-local go-command (concat stencil-root ".bootstrap/shell/go.sh"))
          (setq-local gofmt-command (concat stencil-root ".bootstrap/shell/gofmt.sh"))
          (setq-local godoc-command (concat stencil-root ".bootstrap/shell/go.sh doc"))
          (setq-local go-test-command (concat stencil-root ".bootstrap/shell/go.sh test -ldflags '-X github.com/getoutreach/go-outreach/v2/pkg/app.Version=testing -X github.com/getoutreach/gobox/pkg/app.Version=testing' -tags=or_test"))

          (setq-local lsp-go-gopls-server-path (concat stencil-root ".bootstrap/shell/gopls.sh"))
          (setq-local lsp-go-env '((GOFLAGS . "-tags=or_test,or_e2e")))

          (setq-local flycheck-go-test-executable (concat stencil-root ".bootstrap/shell/go.sh") )
          (setq-local flycheck-go-vet-executable (concat stencil-root ".bootstrap/shell/go.sh") )
          (setq-local flycheck-go-gofmt-executable (concat stencil-root ".bootstrap/shell/gofmt.sh") )
          (setq-local flycheck-go-build-executable (concat stencil-root ".bootstrap/shell/go.sh") )
          )
          ()
          )
      )
    )

(add-hook 'go-mode-hook 'stencil-go-setup)

(Note the gopls.sh references in the middle there.)

Folks using a different editor might not benefit from this specific
advice, but I'm hoping the gopls.sh script will be of some use to
them, too.

Adds a `gopls.sh` script that provides a `asdf`-aware way to start a
`gopls` LSP server.  This script helps my Emacs load and run the right
`gopls` for any given project.

To my fellow Emacs users, I offer these configs as an example:
```
(defun find-stencil-root ()
  "Finds the directory that contains stencil.lock"
  ()
  (message "evaluating find-stencil-root")
  (locate-dominating-file "." "stencil.lock"))

(defun stencil-go-setup ()
  "A go-mode hook for Outreach stencil projects"
  ()
  (let
      ((stencil-root (find-stencil-root)))
    (if stencil-root
        (progn
          (setq-local go-command (concat stencil-root ".bootstrap/shell/go.sh"))
          (setq-local gofmt-command (concat stencil-root ".bootstrap/shell/gofmt.sh"))
          (setq-local godoc-command (concat stencil-root ".bootstrap/shell/go.sh doc"))
          (setq-local go-test-command (concat stencil-root ".bootstrap/shell/go.sh test -ldflags '-X github.com/getoutreach/go-outreach/v2/pkg/app.Version=testing -X github.com/getoutreach/gobox/pkg/app.Version=testing' -tags=or_test"))

          (setq-local lsp-go-gopls-server-path (concat stencil-root ".bootstrap/shell/gopls.sh"))
          (setq-local lsp-go-env '((GOFLAGS . "-tags=or_test,or_e2e")))

          (setq-local flycheck-go-test-executable (concat stencil-root ".bootstrap/shell/go.sh") )
          (setq-local flycheck-go-vet-executable (concat stencil-root ".bootstrap/shell/go.sh") )
          (setq-local flycheck-go-gofmt-executable (concat stencil-root ".bootstrap/shell/gofmt.sh") )
          (setq-local flycheck-go-build-executable (concat stencil-root ".bootstrap/shell/go.sh") )
          )
          ()
          )
      )
    )

(add-hook 'go-mode-hook 'stencil-go-setup)
```
(Note the `gopls.sh` references in the middle there.)

Folks using a different editor might not benefit from this specific
advice, but I'm hoping the `gopls.sh` script will be of some use to
them, too.
@richardlarocque richardlarocque requested a review from a team as a code owner October 28, 2024 15:44
Copy link
Member

@malept malept left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a bunch of opinions on this which I will write down in the morning. Marking as "requested changes" so it doesn't accidentally get merged.

Copy link
Member

@malept malept left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I'm generally not inclined to add this for a few reasons:

  • At least at Outreach, gopls is installed/updated every time a new Go version is installed, via functionality in asdf.
  • We shouldn't put the gopls version in the script itself, if we need to track that, it should go into versions.yaml and the script should use the get_tool_version function (see other scripts for its use).
  • Per the script docs, I don't know if we want to add gopls to services' .tool-versions - it would be yet another item for DT to track, particularly when there may be breaking changes, and those changes would only affect a small minority of developers who don't use VSCode (VSCode installs gopls automatically, just for VSCode as I understand it).

@richardlarocque
Copy link
Contributor Author

gopls is installed/updated every time a new Go version is installed, via functionality in asdf.

For whatever reason, this doesn't seem to be working for me. I always have to install and reshim the first time I encounter a new Go in a .tool-version. I can try to track it down next time that happens.

We shouldn't put the gopls version in the script itself

Yeah, fair point. I personally would be OK with @latest, though I could see issues with that, too.

@malept
Copy link
Member

malept commented Oct 29, 2024

gopls is installed/updated every time a new Go version is installed, via functionality in asdf.

For whatever reason, this doesn't seem to be working for me. I always have to install and reshim the first time I encounter a new Go in a .tool-version. I can try to track it down next time that happens.

FWIW this is what it looks like (details omitted) when I install a previously uninstalled Go version:

❯ asdf install golang 1.23.1
Platform 'linux' supported!
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 70.1M  100 70.1M    0     0  49.4M      0  0:00:01  0:00:01 --:--:-- 49.3M
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100    64  100    64    0     0    380      0 --:--:-- --:--:-- --:--:--   383
verifying checksum
~/.asdf/downloads/golang/1.23.1/archive.tar.gz: OK
checksum verified

Installing github.com/go-delve/delve/cmd/dlv@latest go pkg... go: downloading github.com/go-delve/delve v1.23.1
go: downloading [... output truncated ...]
SUCCESS

Installing golang.org/x/tools/gopls@latest go pkg... go: downloading golang.org/x/tools/gopls v0.16.2
go: downloading [... output truncated ...]
SUCCESS

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 this pull request may close these issues.

2 participants