Code Monkey home page Code Monkey logo

Comments (23)

pharrisee avatar pharrisee commented on May 27, 2024 1

It seems it may have something to do with the theme I was using in VSCode. I switched theme (after doing a tad of googling) and the errors have disappeared.

The original theme I was using was the new Dark Modern theme supplied with VSCode. I've switched to using 'Noctis (Obscuro)' and the error messages no longer appear.

So it seems it's not an issue with this extension.

from templ.

pharrisee avatar pharrisee commented on May 27, 2024 1

To be honest, changing the theme has 'fixed' it enough for me to carry on with checking this all out. Thanks for looking at the issue.

from templ.

a-h avatar a-h commented on May 27, 2024 1

9am UK time, I can drop a Google hangout link in here and anyone can join. Otherwise, some convenient time next week?

from templ.

msonawane avatar msonawane commented on May 27, 2024 1

oops it didnt notify me that you have joined i am sorry

from templ.

msonawane avatar msonawane commented on May 27, 2024 1

I can confirm latest binary solves the issues. Thank you @a-h

from templ.

a-h avatar a-h commented on May 27, 2024

Thanks for the issue report, and for taking the time to try out templ!

The textDocument/semanticTokens etc. messages come from VS Code attempting to execute commands on the templ LSP (Language Server Provider). The vscode extension starts the LSP in the background using the templ lsp command.

The Language Server Provider drives autocomplete etc. It could be that the theme is trying to use textDocument/semanticTokens without first checking whether the LSP supports that command. I'll try using that theme and see what happened.

The templ-vscode extension can be configured to get templ lsp to provide loads of information, including structured logs, and a web server that can be used to inspect the internals of the LSP implementation while it's running.

I'll enable logging, and get some information.

Did you have a valid go.mod file in the workspace, or did you create an empty directory and drop a templ file in? Just want to make sure I can reproduce it.

from templ.

pharrisee avatar pharrisee commented on May 27, 2024

I can supply a copy of the whole directory if that helps, but it was a simple go project (complete with go.mod), with a main.go, and a folder called 'templates' that contained the *.templ files.

.
├── Taskfile.yaml
├── custom-context.go
├── go.mod
├── go.sum
├── main.go
├── templates
│   ├── main.templ
│   └── main_templ.go

I use VSCode-insiders within a WSL2 instance on Windows 10. Using the WSL Remote extension for VSCode. The theme I was using was one of the default themes 'Dark Modern' and I switched to 'Noctis' and choose the Obscuro variant.

from templ.

a-h avatar a-h commented on May 27, 2024

I've tried out the standard and VS Code insiders build, but couldn't reproduce the issue you were seeing with the semantic tokens.

Perhaps the insiders build was trying out getting semantic tokens from the LSP, but hadn't yet introduced a check to see whether it was supported.

However, I did find a solid reproduction of this type of error, which I've detailed in #85 - it's described in detail in there, but ultimately, templ wraps gopls with a bit of source location remapping. At the moment, templ is passing some requests (hover, definition etc.) through to gopls, even if templ doesn't know if there's supposed to be Go code at that location, and gopls complains. This results in the error message.

I think a simple filter to make sure that only valid requests are passed down to gopls will remove the error message and reduce confusion. I haven't got my daily driver (neovim) configured to show these errors, hence not minding it!

from templ.

msonawane avatar msonawane commented on May 27, 2024

@a-h this problem is making extension unusable for me. even if i used exact theme (Noctis Obscuro). Not sure if something wrong with my vscode setup. I would love to get this debugged any pointers ?

from templ.

a-h avatar a-h commented on May 27, 2024

I'd be happy to catch up with you on a Google Hangout or similar to investigate. Friday morning UK time is good for me?

from templ.

msonawane avatar msonawane commented on May 27, 2024

perfect please let me know your preferred timings

from templ.

msonawane avatar msonawane commented on May 27, 2024

9 AM UK time is fine thank you

from templ.

a-h avatar a-h commented on May 27, 2024

https://meet.google.com/dne-xtde-ncq

from templ.

a-h avatar a-h commented on May 27, 2024

OK, got to get on with some work. I'm out of the meet.

from templ.

a-h avatar a-h commented on May 27, 2024

No problem, we could try again, same time next week! 😁

from templ.

a-h avatar a-h commented on May 27, 2024

In the meantime, I've updated the VS Code extension to use the latest versions of all the VS Code dependencies. Not sure if that will solve anything, it's just a regular chore to keep the JavaScript dependencies up to date.

from templ.

msonawane avatar msonawane commented on May 27, 2024

I did an update but problem remains. I am attaching debug log below

ERR semantictokens are disabled: Error: semantictokens are disabled
at handleResponse (/home/msonawane/.vscode/extensions/a-h.templ-0.0.8/dist/main.js:2898:48)
at handleMessage (/home/msonawane/.vscode/extensions/a-h.templ-0.0.8/dist/main.js:2678:13)
at processMessageQueue (/home/msonawane/.vscode/extensions/a-h.templ-0.0.8/dist/main.js:2695:17)
at Immediate. (/home/msonawane/.vscode/extensions/a-h.templ-0.0.8/dist/main.js:2667:13)
at process.processImmediate (node:internal/timers:466:21)

from templ.

msonawane avatar msonawane commented on May 27, 2024

ok so disabling semantic highlighting reduces errors

"editor.semanticHighlighting.enabled": false

now the hover errors get fired ( only when I hover over non templ keywords - i.e. templ function bodies , mostly HTML content)

ERR no package metadata for file file:///home/msonawane/work/base/templates/layouts/metatags.templ: Error: no package metadata for file file:///home/msonawane/work/base/templates/layouts/metatags.templ
at handleResponse (/home/msonawane/.vscode/extensions/a-h.templ-0.0.9/dist/main.js:2898:48)
at handleMessage (/home/msonawane/.vscode/extensions/a-h.templ-0.0.9/dist/main.js:2678:13)
at processMessageQueue (/home/msonawane/.vscode/extensions/a-h.templ-0.0.9/dist/main.js:2695:17)
at Immediate. (/home/msonawane/.vscode/extensions/a-h.templ-0.0.9/dist/main.js:2667:13)
at process.processImmediate (node:internal/timers:466:21)

from templ.

msonawane avatar msonawane commented on May 27, 2024

this seems to be not related to any themes. seems extension is firing events when it should not

from templ.

a-h avatar a-h commented on May 27, 2024

I just upgraded gopls to v0.12.2 from v0.12.1 and got the error.

Screenshot 2023-06-19 at 20 27 34

I've got a full log from the templ side: templ.log

And also from the gopls side: gopls.log

This is a salient section of the gopls logging. This is a request/response pair from the LSP library (note the ID of 4 being used to correlate the request/response):

[Trace - 20:27:28.400 PM] Sending request 'textDocument/semanticTokens/range - (4)'.
Params: {"textDocument":{"uri":"file:///Users/adrian/github.com/a-h/templ/generator/test-import/template.templ"},"range":{"start":{"line":0,"character":0},"end":{"line":24,"character":1}}}

[Error - Received] 20:27:28.401 PM #4 semantictokens are disabled

The first thing that happens in the LSP set up is that the editor sends an init request to the LSP with its capabilities, and the server responds with what it can do.

The server is saying that it can do "semanticTokensProvider" stuff:

{
  "capabilities": {
    "textDocumentSync": {
      "openClose": true,
      "change": 2,
      "save": {}
    },
    "completionProvider": {
      "triggerCharacters": [
        "."
      ]
    },
    "hoverProvider": true,
    "signatureHelpProvider": {
      "triggerCharacters": [
        "(",
        ","
      ]
    },
    "definitionProvider": true,
    "typeDefinitionProvider": true,
    "implementationProvider": true,
    "referencesProvider": true,
    "documentHighlightProvider": true,
    "documentSymbolProvider": true,
    "codeActionProvider": {
      "codeActionKinds": [
        "quickfix",
        "refactor.extract",
        "refactor.rewrite",
        "source.fixAll",
        "source.organizeImports"
      ]
    },
    "codeLensProvider": {},
    "documentLinkProvider": {},
    "workspaceSymbolProvider": true,
    "documentFormattingProvider": true,
    "renameProvider": {
      "prepareProvider": true
    },
    "foldingRangeProvider": true,
    "selectionRangeProvider": true,
    "executeCommandProvider": {
      "commands": [
        "gopls.add_dependency",
        "gopls.add_import",
        "gopls.apply_fix",
        "gopls.check_upgrades",
        "gopls.edit_go_directive",
        "gopls.fetch_vulncheck_result",
        "gopls.gc_details",
        "gopls.generate",
        "gopls.go_get_package",
        "gopls.list_imports",
        "gopls.list_known_packages",
        "gopls.mem_stats",
        "gopls.regenerate_cgo",
        "gopls.remove_dependency",
        "gopls.reset_go_mod_diagnostics",
        "gopls.run_go_work_command",
        "gopls.run_govulncheck",
        "gopls.run_tests",
        "gopls.start_debugging",
        "gopls.test",
        "gopls.tidy",
        "gopls.toggle_gc_details",
        "gopls.update_go_sum",
        "gopls.upgrade_dependency",
        "gopls.vendor",
        "gopls.workspace_stats"
      ]
    },
    "callHierarchyProvider": true,
    "semanticTokensProvider": {
      "legend": {
        "tokenTypes": [
          "namespace",
          "type",
          "class",
          "enum",
          "interface",
          "struct",
          "typeParameter",
          "parameter",
          "variable",
          "property",
          "enumMember",
          "event",
          "function",
          "method",
          "macro",
          "keyword",
          "modifier",
          "comment",
          "string",
          "number",
          "regexp",
          "operator",
          "decorator"
        ],
        "tokenModifiers": [
          "declaration",
          "definition",
          "readonly",
          "static",
          "deprecated",
          "abstract",
          "async",
          "modification",
          "documentation",
          "defaultLibrary"
        ]
      },
      "range": true,
      "full": true
    },
    "inlayHintProvider": {},
    "workspace": {
      "workspaceFolders": {
        "supported": true,
        "changeNotifications": "workspace/didChangeWorkspaceFolders"
      }
    }
  },
  "serverInfo": {
    "name": "gopls",
    "version": "{\"GoVersion\":\"go1.20.1\",\"Path\":\"golang.org/x/tools/gopls\",\"Main\":{\"Path\":\"golang.org/x/tools/gopls\",\"Version\":\"v0.12.2\",\"Sum\":\"h1:s4mznBqCHVHeuTYjxGYJhsW3Wp4FYon8YAqiJlwlpTY=\",\"Replace\":null},\"Deps\":[{\"Path\":\"github.com/BurntSushi/toml\",\"Version\":\"v1.2.1\",\"Sum\":\"h1:9F2/+DoOYIOksmaJFPw1tGFy1eDnIJXg+UHjuD8lTak=\",\"Replace\":null},{\"Path\":\"github.com/google/go-cmp\",\"Version\":\"v0.5.9\",\"Sum\":\"h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=\",\"Replace\":null},{\"Path\":\"github.com/sergi/go-diff\",\"Version\":\"v1.1.0\",\"Sum\":\"h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=\",\"Replace\":null},{\"Path\":\"golang.org/x/exp\",\"Version\":\"v0.0.0-20220722155223-a9213eeb770e\",\"Sum\":\"h1:+WEEuIdZHnUeJJmEUjyYC2gfUMj69yZXw17EnHg/otA=\",\"Replace\":null},{\"Path\":\"golang.org/x/exp/typeparams\",\"Version\":\"v0.0.0-20221212164502-fae10dda9338\",\"Sum\":\"h1:2O2DON6y3XMJiQRAS1UWU+54aec2uopH3x7MAiqGW6Y=\",\"Replace\":null},{\"Path\":\"golang.org/x/mod\",\"Version\":\"v0.10.0\",\"Sum\":\"h1:lFO9qtOdlre5W1jxS3r/4szv2/6iXxScdzjoBMXNhYk=\",\"Replace\":null},{\"Path\":\"golang.org/x/sync\",\"Version\":\"v0.2.0\",\"Sum\":\"h1:PUR+T4wwASmuSTYdKjYHI5TD22Wy5ogLU5qZCOLxBrI=\",\"Replace\":null},{\"Path\":\"golang.org/x/sys\",\"Version\":\"v0.8.0\",\"Sum\":\"h1:EBmGv8NaZBZTWvrbjNoL6HVt+IVy3QDQpJs7VRIw3tU=\",\"Replace\":null},{\"Path\":\"golang.org/x/text\",\"Version\":\"v0.9.0\",\"Sum\":\"h1:2sjJmO8cDvYveuX97RDLsxlyUxLl+GHoLxBiRdHllBE=\",\"Replace\":null},{\"Path\":\"golang.org/x/tools\",\"Version\":\"v0.9.4-0.20230601215739-41a7dc76dd8f\",\"Sum\":\"h1:rZCNEwRXLwl4xnXOEYY7jTuTh3+xNnsq8IfB2idOhD0=\",\"Replace\":null},{\"Path\":\"golang.org/x/vuln\",\"Version\":\"v0.0.0-20230110180137-6ad3e3d07815\",\"Sum\":\"h1:A9kONVi4+AnuOr1dopsibH6hLi1Huy54cbeJxnq4vmU=\",\"Replace\":null},{\"Path\":\"honnef.co/go/tools\",\"Version\":\"v0.4.2\",\"Sum\":\"h1:6qXr+R5w+ktL5UkwEbPp+fEvfyoMPche6GkOpGHZcLc=\",\"Replace\":null},{\"Path\":\"mvdan.cc/gofumpt\",\"Version\":\"v0.4.0\",\"Sum\":\"h1:JVf4NN1mIpHogBj7ABpgOyZc65/UUOkKQFkoURsz4MM=\",\"Replace\":null},{\"Path\":\"mvdan.cc/xurls/v2\",\"Version\":\"v2.4.0\",\"Sum\":\"h1:tzxjVAj+wSBmDcF6zBB7/myTy3gX9xvi8Tyr28AuQgc=\",\"Replace\":null}],\"Settings\":[{\"Key\":\"-buildmode\",\"Value\":\"exe\"},{\"Key\":\"-compiler\",\"Value\":\"gc\"},{\"Key\":\"CGO_ENABLED\",\"Value\":\"1\"},{\"Key\":\"CGO_CFLAGS\",\"Value\":\"\"},{\"Key\":\"CGO_CPPFLAGS\",\"Value\":\"\"},{\"Key\":\"CGO_CXXFLAGS\",\"Value\":\"\"},{\"Key\":\"CGO_LDFLAGS\",\"Value\":\"\"},{\"Key\":\"GOARCH\",\"Value\":\"arm64\"},{\"Key\":\"GOOS\",\"Value\":\"darwin\"}],\"Version\":\"v0.12.1\"}"
  }
}

Later on, the templ logs clearly show that it's sending a semantic tokens request over to the LSP:

{"level":"info","ts":"2023-06-19T20:27:28+01:00","caller":"proxy/server.go:885","msg":"client -> server: SemanticTokensFull"}
{"level":"info","ts":"2023-06-19T20:27:28+01:00","caller":"proxy/server.go:887","msg":"client -> server: SemanticTokensFull end"}

And the LSP logs say that it shouldn't be!

[Trace - 20:27:28.402 PM] Sending request 'textDocument/semanticTokens/full - (5)'.
Params: {"textDocument":{"uri":"file:///Users/adrian/github.com/a-h/templ/generator/test-import/template.templ"}}

[Error - Received] 20:27:28.402 PM #5 semantictokens are disabled

So... something is likely going wrong in the negotiation, or the proxying of the information back to the LSP.

One way to deal with things is to rip out semantic token responses here:

func (p *Server) Initialize(ctx context.Context, params *lsp.InitializeParams) (result *lsp.InitializeResult, err error) {
p.Log.Info("client -> server: Initialize")
defer p.Log.Info("client -> server: Initialize end")
result, err = p.Target.Initialize(ctx, params)
if err != nil {
p.Log.Error("Initialize failed", zap.Error(err))
}
// Add the '<' and '{' trigger so that we can do snippets for tags.
if result.Capabilities.CompletionProvider == nil {
result.Capabilities.CompletionProvider = &lsp.CompletionOptions{}
}
result.Capabilities.CompletionProvider.TriggerCharacters = append(result.Capabilities.CompletionProvider.TriggerCharacters, "{", "<")
// Remove all the gopls commands.
if result.Capabilities.ExecuteCommandProvider == nil {
result.Capabilities.ExecuteCommandProvider = &lsp.ExecuteCommandOptions{}
}
result.Capabilities.ExecuteCommandProvider.Commands = []string{}
result.Capabilities.DocumentFormattingProvider = true
return result, err
}

Or, to not pass on the request to gopls here, and return a default response:

func (p *Server) SemanticTokensFull(ctx context.Context, params *lsp.SemanticTokensParams) (result *lsp.SemanticTokens, err error) {
p.Log.Info("client -> server: SemanticTokensFull")
defer p.Log.Info("client -> server: SemanticTokensFull end")
return p.Target.SemanticTokensFull(ctx, params)
}

But that's not getting at the real problem.

I noticed that the URI here has a .templ file extension, not a .go file extension... i.e. the filename hasn't been re-written for gopls like it is in the other requests:

isTemplURI, params.TextDocument.URI = convertTemplToGoURI(params.TextDocument.URI)

So... it might be as simple as doing that.

from templ.

a-h avatar a-h commented on May 27, 2024

Passing the Go file name didn't make any difference:

[Trace - 21:02:03.286 PM] Sending request 'textDocument/semanticTokens/full - (7)'.
Params: {"textDocument":{"uri":"file:///Users/adrian/github.com/a-h/templ/generator/test-import/template_templ.go"}}

[Error - Received] 21:02:03.286 PM #7 semantictokens are disabled

So... it's clear I've got to wipe out the request completely. I also figured out that templ is sometimes passing the templ file location on to gopls if the editor is hovering over HTML sections - it doesn't ignore the response like it should.

Easy fixes, I think. I'll look into this again, but time to stop for the day for now.

from templ.

a-h avatar a-h commented on May 27, 2024

Hi @pharrisee / @msonawane, the VS Code theme did make a difference to me, the new theme seems to do something with semantic tokens, while the old one didn't.

Anyway, I've released version v0.2.304 of the templ CLI with some minor amends which I think will stop the noisy and pointless errors. No update to the VS Code extension is required, since it just uses the CLI to do its work.

I would like, at some point, the VS Code extension to check that the latest version of the templ CLI is being used.

from templ.

pharrisee avatar pharrisee commented on May 27, 2024

Anyway, I've released version v0.2.304 of the templ CLI with some minor amends which I think will stop the noisy and pointless errors. No update to the VS Code extension is required, since it just uses the CLI to do its work.

Thanks for looking at this @a-h, I'll give the new version a go this morning.

from templ.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.