Comments (23)
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.
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.
9am UK time, I can drop a Google hangout link in here and anyone can join. Otherwise, some convenient time next week?
from templ.
oops it didnt notify me that you have joined i am sorry
from templ.
I can confirm latest binary solves the issues. Thank you @a-h
from templ.
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.
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.
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.
@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.
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.
perfect please let me know your preferred timings
from templ.
9 AM UK time is fine thank you
from templ.
https://meet.google.com/dne-xtde-ncq
from templ.
OK, got to get on with some work. I'm out of the meet.
from templ.
No problem, we could try again, same time next week! 😁
from templ.
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.
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.
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.
this seems to be not related to any themes. seems extension is firing events when it should not
from templ.
I just upgraded gopls
to v0.12.2 from v0.12.1 and got the error.
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:
templ/cmd/templ/lspcmd/proxy/server.go
Lines 163 to 182 in 66651f5
Or, to not pass on the request to gopls
here, and return a default response:
templ/cmd/templ/lspcmd/proxy/server.go
Lines 884 to 888 in 66651f5
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:
templ/cmd/templ/lspcmd/proxy/server.go
Line 754 in 66651f5
So... it might be as simple as doing that.
from templ.
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.
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.
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)
- zTemplUnsafeCSSPropertyValue - Unable to use dynamic background-image css component HOT 2
- event listeners for scripts HOT 2
- Proxy server hot-reloading does not play nice with htmx HOT 4
- templ generate custom name pattern HOT 3
- generator: Allow more than just strings in templ expressions HOT 6
- Spread under attribute HOT 7
- Spread JS event map HOT 2
- Rendering JSON HOT 2
- I want use a-h/templ to write a go code template for my gogen program. How to write curly braces without them being recognized as variables? HOT 3
- Is what I want possible, or do I need to rethink how I'm doing it?
- cannot use functions that return strings inside style property HOT 1
- Install as nix flake HOT 9
- bug: backslashes in constant string attributes cannot be generated HOT 3
- feature: go:build tags support? HOT 1
- parser: Error with slice literal on v0.2.639 HOT 1
- lsp: Inlay Hint Support
- dynamic rendering based on server html files HOT 1
- Jetbrains GoLand - Slow LSP HOT 1
- proposal: ability to render simple text HOT 5
- bug: passing arrays to templates HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from templ.