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

x/tools/gopls: spurious errors from template files (umbrella issue) #50602

Closed
achamoux opened this issue Dec 20, 2021 · 19 comments
Closed

x/tools/gopls: spurious errors from template files (umbrella issue) #50602

achamoux opened this issue Dec 20, 2021 · 19 comments
Labels
FrozenDueToAge gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@achamoux
Copy link

VSCode_error_in_packages_golang-1-17

What version of Go, VS Code & VS Code Go extension are you using?

Version Information
  • Run go version to get version of Go from the VS Code integrated terminal.
  • Run gopls -v version to get version of Gopls from the VS Code integrated terminal.
  • Run code -v or code-insiders -v to get version of VS Code or VS Code Insiders.
  • Check your installed extensions to get the version of the VS Code Go extension
  • Run Ctrl+Shift+P (Cmd+Shift+P on Mac OS) > Go: Locate Configured Go Tools command.

Share the Go related settings you have added/edited

Run Preferences: Open Settings (JSON) command to open your settings.json file.
Share all the settings with the go. or ["go"] or gopls prefixes.

Describe the bug

A clear and concise description of what the bug.
A clear and concise description of what you expected to happen.

Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. See error

Screenshots or recordings

If applicable, add screenshots or recordings to help explain your problem.

I'm using Go 1.17 in Windows 10 64

@zeripath
Copy link

Development of Gitea is also affected by this. Is there any way of excluding linting of individual template files or even directories? We have some template files which aren't even intended to be go templates and it's even linting files within vendor and probably in node_modules.


Unfortunately:

"gopls": {
  "build.directoryFilters": ["-node_modules", "-nogopls/these/are/not/for/you"]
},

Is ignored by the template linter and disappointingly it seems like the only solution at present to prevent missing other more serious go errors is to simply turn off template linting through:

 "gopls": {
    "build.templateExtensions": [],
  },

@findleyr
Copy link
Contributor

Hi, for now yes the best solution is to turn off template linting, as you have found. We will prioritize fixing this for the next release (both honoring the directoryFilters, and fixing the spurious 'empty buffer' errors)

CC @pjweinbgo

@findleyr
Copy link
Contributor

And I should also add: apologies for the breakage.

@butuzov
Copy link

butuzov commented Dec 25, 2021

the other possible way is to disable template association using files.associations

"files.associations": {
    "path/*tmpl": "plaintext"
}

p.s. the templates in questions used for tests and intentionally empty, if that helps to triage the bug.

@hyangah
Copy link
Contributor

hyangah commented Jan 4, 2022

cc @pjweinb

@findleyr findleyr changed the title Jan 4, 2022
@findleyr
Copy link
Contributor

findleyr commented Jan 4, 2022

Renamed this to be a parent issue tracking spurious errors from template files. Leaving it in vscode-go because I suspect there may be some vscode changes required as well.

@pjweinbgo
Copy link
Contributor

pjweinbgo commented Jan 4, 2022 via email

@findleyr
Copy link
Contributor

findleyr commented Jan 4, 2022

@pjweinbgo yes the errors are coming from gopls. It intersects with vscode-go in the mutually conflicting configuration: files.associations and gopls' build.templateExtensions.

I think it's worth leaving this here to track the overarching problem of improving the resolution of template files in vscode, but don't feel strongly.

@gopherbot
Copy link

Change https://golang.org/cl/375874 mentions this issue: gopls: change the default value for templateExtensions to be empty

@gopherbot
Copy link

Change https://golang.org/cl/376037 mentions this issue: package.json: change go template file default to empty and rename language id

@gopherbot
Copy link

Change https://golang.org/cl/376854 mentions this issue: /internal/template: identify template files by the templateExtensions option

@gopherbot
Copy link

Change https://golang.org/cl/376854 mentions this issue: internal/template: identify template files by the templateExtensions option

@gopherbot
Copy link

Change https://golang.org/cl/378354 mentions this issue: internal/lsp: find templates based on file kind

@gopherbot
Copy link

Change https://golang.org/cl/378355 mentions this issue: internal/lsp/template: remove the skipTemplate guard

@findleyr
Copy link
Contributor

Not entirely resolved yet: the CL stack above enabled setting the default templateExtensions to [].

@gopherbot
Copy link

Change https://golang.org/cl/378314 mentions this issue: internal/lsp: honor the file kind provided by clients for overlays

@gopherbot
Copy link

Change https://golang.org/cl/378394 mentions this issue: gopls/internal/regtest: add regression tests for template diagnostics

gopherbot referenced this issue in golang/tools Jan 13, 2022
Honor the file kind provided by clients for overlays, by passing the
FileHandle into View.FileKind and checking for overlays.

For golang/vscode-go#1957

Change-Id: I4a767cb64dc5205f1d10c3126a2cbe67c21a34e4
Reviewed-on: https://go-review.googlesource.com/c/tools/+/378314
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Suzy Mueller <suzmue@golang.org>
gopherbot referenced this issue in golang/tools Jan 13, 2022
Now that we honor the template file kind provided by LSP clients, we
need to use this to derive the set of active templates.

For golang/vscode-go#1957

Change-Id: If0883b2acff746fe6d187124b939f3a2d0e0d4f2
Reviewed-on: https://go-review.googlesource.com/c/tools/+/378354
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
Reviewed-by: Suzy Mueller <suzmue@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
gopherbot referenced this issue in golang/tools Jan 13, 2022
Having the explicit skipTemplate guard should not be necessary, since
with templateExtensions empty we should not detect any templates that
the user did not ask for. Remove it

For golang/vscode-go#1957

Change-Id: Idbe30bc61f47ed405d98fdb029f44a0841769ad0
Reviewed-on: https://go-review.googlesource.com/c/tools/+/378355
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
Reviewed-by: Suzy Mueller <suzmue@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
gopherbot referenced this issue in golang/tools Jan 13, 2022
There is no standard for go template file extensions, and users may not
want this functionality. Make template support opt-in by changing the
default value of templateExtensions to be [].

Updates golang/vscode-go#1957

Change-Id: I7e37d22b1bc63d8300634b3b0394b4036b43fa49
Reviewed-on: https://go-review.googlesource.com/c/tools/+/375874
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
Reviewed-by: Suzy Mueller <suzmue@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
@findleyr
Copy link
Contributor

Transferring this to the Go issue tracker for milestone tracking.

@findleyr findleyr transferred this issue from golang/vscode-go Jan 14, 2022
@findleyr findleyr added this to the gopls/v0.7.5 milestone Jan 14, 2022
@findleyr findleyr added gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository. labels Jan 14, 2022
@findleyr findleyr changed the title gopls: spurious errors from template files (umbrella issue) x/tools/gopls: spurious errors from template files (umbrella issue) Jan 14, 2022
@pjweinb
Copy link

pjweinb commented Jan 14, 2022 via email

@golang golang locked and limited conversation to collaborators Jan 14, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository.
Projects
None yet
Development

No branches or pull requests

8 participants