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

lsp: Request textDocument/hover failed on Cyrillic characters #482

Closed
koddr opened this issue Feb 1, 2024 · 5 comments
Closed

lsp: Request textDocument/hover failed on Cyrillic characters #482

koddr opened this issue Feb 1, 2024 · 5 comments
Labels
bug Something isn't working lsp NeedsInvestigation Issue needs some investigation before being fixed

Comments

@koddr
Copy link

koddr commented Feb 1, 2024

Hi, @a-h

I've encountered a bug in the VS Code extension (latest, v0.0.19).

If you drag the cursor over a string with Cyrillic characters (runes?) in *.templ file, an error pops up:

Request textDocument/hover failed.
Message: rune error
Code: 0 

Any text in another language does not cause such trouble.

Look this small screencast to understand:

2024-02-01.15.25.53.mov

What can I do to prevent this error from appearing? 🤔

@joerdav
Copy link
Collaborator

joerdav commented Feb 1, 2024

We do have a troubleshooting section, that should help you gather some vital information when investigating this.

https://templ.guide/commands-and-tools/ide-support#troubleshooting-1

@joerdav joerdav changed the title bug(vscode extension): Request textDocument/hover failed on Cyrillic characters vscode: Request textDocument/hover failed on Cyrillic characters Feb 1, 2024
@joerdav joerdav added bug Something isn't working vscode WaitingForMoreInfo labels Feb 1, 2024
@koddr
Copy link
Author

koddr commented Feb 1, 2024

@joerdav, yep, of course.

go: v1.21.6
templ: v0.2.543
vscode-templ: v0.0.19

vscode:

Version: 1.86.0
Commit: 05047486b6df5eb8d44b2ecd70ea3bdf775fd937
Date: 2024-01-31T10:29:11.933Z
Electron: 27.2.3
ElectronBuildId: 26495564
Chromium: 118.0.5993.159
Node.js: 18.17.1
V8: 11.8.172.18-electron.0
OS: Darwin arm64 22.6.0

uname -a:

Darwin User.local 22.6.0 Darwin Kernel Version 22.6.0: 
Tue Nov  7 21:42:27 PST 2023; root:xnu-8796.141.3.702.9~2/RELEASE_ARM64_T8103 arm64

which go gopls templ:

/opt/homebrew/bin/go
/Users/user/go/bin/gopls
/Users/user/go/bin/templ

cat vscode-gopls.txt:

[Trace - 19:19:23.124 PM] Sending notification 'textDocument/didOpen'.
Params: {"textDocument":{"uri":"file:///Users/user/Code/koddr/oau-core/templates/pages/index_templ.go","languageId":"templ","version":1,"text":"// Code generated by templ - DO NOT EDIT.\n\npackage pages\n\n//lint:file-ignore SA4006 This context is only used if a nested component is present.\n\nimport \"github.com/a-h/templ\"\nimport \"context\"\nimport \"io\"\nimport \"bytes\"\n\nimport (\n\t\"github.com/koddr/oau-core/templates/views\"\n\t\"github.com/koddr/oau-core/templates/components/ui\"\n\t\"github.com/koddr/oau-core/templates/components/forms\"\n\t\"github.com/koddr/oau-core/templates/components/fields\"\n)\n\nfunc IndexMetaTags(keywords, description string) templ.Component {\n\treturn templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) {\n\t\ttempl_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer)\n\t\tif !templ_7745c5c3_IsBuffer {\n\t\t\ttempl_7745c5c3_Buffer = templ.GetBuffer()\n\t\t\tdefer templ.ReleaseBuffer(templ_7745c5c3_Buffer)\n\t\t}\n\t\tctx = templ.InitializeContext(ctx)\n\t\ttempl_7745c5c3_Var1 := templ.GetChildren(ctx)\n\t\tif templ_7745c5c3_Var1 == nil {\n\t\t\ttempl_7745c5c3_Var1 = templ.NopComponent\n\t\t}\n\t\tctx = templ.ClearChildren(ctx)\n\t\t\t\t_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(\"\u003cmeta name=\\\"keywords\\\" content=\\\"\")\n\t\tif templ_7745c5c3_Err != nil {\n\t\t\treturn templ_7745c5c3_Err\n\t\t}\n\t\t_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(keywords))\n\t\tif templ_7745c5c3_Err != nil {\n\t\t\treturn templ_7745c5c3_Err\n\t\t}\n\t\t\t\t_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(\"\\\"\u003e\u003cmeta name=\\\"description\\\" content=\\\"\")\n\t\tif templ_7745c5c3_Err != nil {\n\t\t\treturn templ_7745c5c3_Err\n\t\t}\n\t\t_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(description))\n\t\tif templ_7745c5c3_Err != nil {\n\t\t\treturn templ_7745c5c3_Err\n\t\t}\n\t\t\t\t_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(\"\\\"\u003e\")\n\t\tif templ_7745c5c3_Err != nil {\n\t\t\treturn templ_7745c5c3_Err\n\t\t}\n\t\tif !templ_7745c5c3_IsBuffer {\n\t\t\t_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteTo(templ_7745c5c3_W)\n\t\t}\n\t\treturn templ_7745c5c3_Err\n\t})\n}\n\nfunc IndexPageContent(options *Options[views.IndexContentView]) templ.Component {\n\treturn templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) {\n\t\ttempl_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer)\n\t\tif !templ_7745c5c3_IsBuffer {\n\t\t\ttempl_7745c5c3_Buffer = templ.GetBuffer()\n\t\t\tdefer templ.ReleaseBuffer(templ_7745c5c3_Buffer)\n\t\t}\n\t\tctx = templ.InitializeContext(ctx)\n\t\ttempl_7745c5c3_Var2 := templ.GetChildren(ctx)\n\t\tif templ_7745c5c3_Var2 == nil {\n\t\t\ttempl_7745c5c3_Var2 = templ.NopComponent\n\t\t}\n\t\tctx = templ.ClearChildren(ctx)\n\t\t\t\t_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(\"\u003carticle class=\\\"prose\\\"\u003e\u003ch1\u003e\")\n\t\tif templ_7745c5c3_Err != nil {\n\t\t\treturn templ_7745c5c3_Err\n\t\t}\n\t\ttempl_7745c5c3_Var3 := `Garlic bread with cheese: What the science tells us`\n\t\t_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var3)\n\t\tif templ_7745c5c3_Err != nil {\n\t\t\treturn templ_7745c5c3_Err\n\t\t}\n\t\t\t\t_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(\"\u003c/h1\u003e\u003cp\u003e\")\n\t\tif templ_7745c5c3_Err != nil {\n\t\t\treturn templ_7745c5c3_Err\n\t\t}\n\t\ttempl_7745c5c3_Var4 := `For years parents have espoused the health benefits of eating garlic bread with cheese to their`\n\t\t_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var4)\n\t\tif templ_7745c5c3_Err != nil {\n\t\t\treturn templ_7745c5c3_Err\n\t\t}\n\t\t\t\t_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(\" \")\n\t\tif templ_7745c5c3_Err != nil {\n\t\t\treturn templ_7745c5c3_Err\n\t\t}\n\t\ttempl_7745c5c3_Var5 := `children, with the food earning such an iconic status in our culture that kids will often dress`\n\t\t_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var5)\n\t\tif templ_7745c5c3_Err != nil {\n\t\t\treturn templ_7745c5c3_Err\n\t\t}\n\t\t\t\t_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(\" \")\n\t\tif templ_7745c5c3_Err != nil {\n\t\t\treturn templ_7745c5c3_Err\n\t\t}\n\t\ttempl_7745c5c3_Var6 := `up as warm, cheesy loaf for Halloween.`\n\t\t_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var6)\n\t\tif templ_7745c5c3_Err != nil {\n\t\t\treturn templ_7745c5c3_Err\n\t\t}\n\t\t\t\t_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(\"\u003c/p\u003e\u003cp\u003e\")\n\t\tif templ_7745c5c3_Err != nil {\n\t\t\treturn templ_7745c5c3_Err\n\t\t}\n\t\ttempl_7745c5c3_Var7 := `But a recent study shows that the celebrated appetizer may be linked to a series of rabies cases`\n\t\t_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var7)\n\t\tif templ_7745c5c3_Err != nil {\n\t\t\treturn templ_7745c5c3_Err\n\t\t}\n\t\t\t\t_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(\" \")\n\t\tif templ_7745c5c3_Err != nil {\n\t\t\treturn templ_7745c5c3_Err\n\t\t}\n\t\ttempl_7745c5c3_Var8 := `springing up around the country.`\n\t\t_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var8)\n\t\tif templ_7745c5c3_Err != nil {\n\t\t\treturn templ_7745c5c3_Err\n\t\t}\n\t\t\t\t_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(\"\u003c/p\u003e\u003cdiv\u003e\")\n\t\tif templ_7745c5c3_Err != nil {\n\t\t\treturn templ_7745c5c3_Err\n\t\t}\n\t\ttempl_7745c5c3_Err = ui.ThemeSwitcher().Render(ctx, templ_7745c5c3_Buffer)\n\t\tif templ_7745c5c3_Err != nil {\n\t\t\treturn templ_7745c5c3_Err\n\t\t}\n\t\t\t\t_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(\"\u003c/div\u003e\u003cdiv\u003e\")\n\t\tif templ_7745c5c3_Err != nil {\n\t\t\treturn templ_7745c5c3_Err\n\t\t}\n\t\ttempl_7745c5c3_Err = forms.Auth(\u0026forms.AuthFormOptions{\n\t\t\t\tEndpoint: \"/api/v1/user/login\",\n\t\t\t\tTarget:   \"#result\",\n\t\t\t\tFields: []templ.Component{\n\t\t\t\t\tfields.Input(\u0026fields.InputOptions{\n\t\t\t\t\t\tID:          \"code\",\n\t\t\t\t\t\tName:        \"code\",\n\t\t\t\t\t\tType:        \"text\",\n\t\t\t\t\t\tPlaceholder: \"Введите регистрационный код\",\n\t\t\t\t\t\tLabel: \u0026fields.InputLabelOptions{\n\t\t\t\t\t\t\tText:     \"Регистрационный код\",\n\t\t\t\t\t\t\tHelpText: \"16-ти значный код регистрации, который вы можете найти в вашей коробке с базовой игрой.\",\n\t\t\t\t\t\t},\n\t\t\t\t\t\tIsRequired: true,\n\t\t\t\t\t}),\n\t\t\t\t\tfields.Input(\u0026fields.InputOptions{\n\t\t\t\t\t\tID:          \"email\",\n\t\t\t\t\t\tName:        \"email\",\n\t\t\t\t\t\tType:        \"email\",\n\t\t\t\t\t\tPlaceholder: \"Адрес email\",\n\t\t\t\t\t\tLabel: \u0026fields.InputLabelOptions{\n\t\t\t\t\t\t\tText:     \"Email\",\n\t\t\t\t\t\t\tHelpText: \"Адрес вашей действующей электронной почты.\",\n\t\t\t\t\t\t},\n\t\t\t\t\t\tIsRequired: true,\n\t\t\t\t\t}),\n\t\t\t\t},\n\t\t\t\tSubmitButton: fields.Button(\u0026fields.ButtonOptions{\n\t\t\t\t\tState: \"btn-primary\",\n\t\t\t\t\tType:  \"submit\",\n\t\t\t\t\tText:  \"Войти\",\n\t\t\t\t\tLoading: \u0026fields.ButtonLoadingOptions{\n\t\t\t\t\t\tVariant: \"loading-spinner\",\n\t\t\t\t\t\tSize:    \"loading-sm\",\n\t\t\t\t\t},\n\t\t\t\t}),\n\t\t\t}).Render(ctx, templ_7745c5c3_Buffer)\n\t\tif templ_7745c5c3_Err != nil {\n\t\t\treturn templ_7745c5c3_Err\n\t\t}\n\t\t\t\t_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(\"\u003cdiv id=\\\"result\\\"\u003e\u003c/div\u003e\u003c/div\u003e\u003c/article\u003e\")\n\t\tif templ_7745c5c3_Err != nil {\n\t\t\treturn templ_7745c5c3_Err\n\t\t}\n\t\tif !templ_7745c5c3_IsBuffer {\n\t\t\t_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteTo(templ_7745c5c3_W)\n\t\t}\n\t\treturn templ_7745c5c3_Err\n\t})\n}\n"}}

[Trace - 19:19:23.145 PM] Sending request 'textDocument/codeAction - (2)'.
Params: {"textDocument":{"uri":"file:///Users/user/Code/koddr/oau-core/templates/pages/index_templ.go"},"context":{"diagnostics":[]},"range":{"start":{"line":0,"character":0},"end":{"line":0,"character":0}}}

[Trace - 19:19:23.146 PM] Received response 'textDocument/codeAction - (2)' in 1ms.
Result: null

[Trace - 19:19:23.206 PM] Received notification 'textDocument/publishDiagnostics'.
Params: {"uri":"file:///Users/user/Code/user/oau-core/templates/pages/index_templ.go","version":1,"diagnostics":[]}

[Trace - 19:19:23.380 PM] Sending request 'textDocument/codeAction - (3)'.
Params: {"textDocument":{"uri":"file:///Users/user/Code/koddr/oau-core/templates/pages/index_templ.go"},"context":{"diagnostics":[]},"range":{"start":{"line":59,"character":16},"end":{"line":59,"character":16}}}

[Trace - 19:19:23.380 PM] Received response 'textDocument/codeAction - (3)' in 0ms.
Result: null

[Trace - 19:19:23.521 PM] Sending request 'textDocument/codeLens - (4)'.
Params: {"textDocument":{"uri":"file:///Users/user/Code/koddr/oau-core/templates/pages/index_templ.go"}}

[Trace - 19:19:23.521 PM] Received response 'textDocument/codeLens - (4)' in 0ms.
Result: null

[Trace - 19:19:24.619 PM] Sending request 'textDocument/codeAction - (5)'.
Params: {"textDocument":{"uri":"file:///Users/user/Code/koddr/oau-core/templates/pages/index_templ.go"},"context":{"diagnostics":[]},"range":{"start":{"line":59,"character":16},"end":{"line":59,"character":16}}}

[Trace - 19:19:24.620 PM] Received response 'textDocument/codeAction - (5)' in 0ms.
Result: null

[Trace - 19:19:25.534 PM] Sending request 'textDocument/hover - (6)'.
Params: {"textDocument":{"uri":"file:///Users/user/Code/koddr/oau-core/templates/pages/index_templ.go"},"position":{"line":145,"character":42}}

[Error - Received] 19:19:25.537 PM #6 rune error

[Trace - 19:19:28.169 PM] Sending request 'textDocument/hover - (7)'.
Params: {"textDocument":{"uri":"file:///Users/user/Code/koddr/oau-core/templates/pages/index_templ.go"},"position":{"line":148,"character":76}}

[Error - Received] 19:19:28.170 PM #7 rune error

cat vscode-templ.txt:

{"level":"info","ts":"2024-02-01T19:16:58+03:00","caller":"lspcmd/main.go:75","msg":"lsp: starting up..."}
{"level":"info","ts":"2024-02-01T19:16:58+03:00","caller":"lspcmd/main.go:82","msg":"lsp: starting gopls..."}
{"level":"info","ts":"2024-02-01T19:16:58+03:00","caller":"lspcmd/main.go:94","msg":"creating client"}
{"level":"info","ts":"2024-02-01T19:16:58+03:00","caller":"lspcmd/main.go:99","msg":"creating proxy"}
{"level":"info","ts":"2024-02-01T19:16:58+03:00","caller":"lspcmd/main.go:104","msg":"creating templ server"}
{"level":"info","ts":"2024-02-01T19:16:58+03:00","caller":"lspcmd/main.go:115","msg":"starting debug http server","addr":"localhost:7575"}
{"level":"info","ts":"2024-02-01T19:16:58+03:00","caller":"lspcmd/main.go:124","msg":"listening"}
{"level":"info","ts":"2024-02-01T19:16:58+03:00","caller":"proxy/server.go:165","msg":"client -> server: Initialize"}
{"level":"info","ts":"2024-02-01T19:16:58+03:00","caller":"proxy/server.go:191","msg":"client -> server: Initialize end"}
{"level":"info","ts":"2024-02-01T19:16:58+03:00","caller":"proxy/server.go:195","msg":"client -> server: Initialized"}
{"level":"info","ts":"2024-02-01T19:16:58+03:00","caller":"proxy/server.go:197","msg":"client -> server: Initialized end"}
{"level":"info","ts":"2024-02-01T19:16:58+03:00","caller":"proxy/client.go:40","msg":"client <- server: WorkDoneProgressCreate"}
{"level":"info","ts":"2024-02-01T19:16:58+03:00","caller":"proxy/server.go:225","msg":"client -> server: SetTrace"}
{"level":"info","ts":"2024-02-01T19:16:58+03:00","caller":"proxy/server.go:227","msg":"client -> server: SetTrace end"}
{"level":"info","ts":"2024-02-01T19:16:59+03:00","caller":"proxy/server.go:225","msg":"client -> server: SetTrace"}
{"level":"info","ts":"2024-02-01T19:16:59+03:00","caller":"proxy/server.go:227","msg":"client -> server: SetTrace end"}
{"level":"info","ts":"2024-02-01T19:16:59+03:00","caller":"proxy/server.go:225","msg":"client -> server: SetTrace"}
{"level":"info","ts":"2024-02-01T19:16:59+03:00","caller":"proxy/server.go:227","msg":"client -> server: SetTrace end"}
{"level":"info","ts":"2024-02-01T19:16:59+03:00","caller":"proxy/client.go:36","msg":"client <- server: Progress"}
{"level":"info","ts":"2024-02-01T19:16:59+03:00","caller":"proxy/client.go:126","msg":"client <- server: Configuration"}
{"level":"info","ts":"2024-02-01T19:16:59+03:00","caller":"proxy/server.go:225","msg":"client -> server: SetTrace"}
{"level":"info","ts":"2024-02-01T19:16:59+03:00","caller":"proxy/server.go:227","msg":"client -> server: SetTrace end"}
{"level":"info","ts":"2024-02-01T19:16:59+03:00","caller":"proxy/client.go:45","msg":"client <- server: LogMessage","message":"2024/02/01 19:16:59 go info for /Users/viktorsostak/Code/koddr/oau-core\n(go dir /Users/user/Code/koddr/oau-core)\n(go version go version go1.21.6 darwin/arm64)\n(valid build configuration = true)\n(build flags: [])\n(selected go env: [GO111MODULE=, GOCACHE=/Users/viktorsostak/Library/Caches/go-build, GOFLAGS=, GOMODCACHE=/Users/user/go/pkg/mod, GOPATH=/Users/viktorsostak/go, GOPRIVATE=, GOROOT=/opt/homebrew/Cellar/go/1.21.6/libexec, GOWORK=])\n\n"}
{"level":"info","ts":"2024-02-01T19:16:59+03:00","caller":"proxy/server.go:225","msg":"client -> server: SetTrace"}
{"level":"info","ts":"2024-02-01T19:16:59+03:00","caller":"proxy/server.go:227","msg":"client -> server: SetTrace end"}
{"level":"info","ts":"2024-02-01T19:17:00+03:00","caller":"proxy/client.go:45","msg":"client <- server: LogMessage","message":"2024/02/01 19:17:00 go/packages.Load #1\n\tsnapshot=0\n\tdirectory=file:///Users/viktorsostak/Code/koddr/oau-core\n\tquery=[/Users/user/Code/koddr/oau-core/... builtin]\n\tpackages=16\n"}
{"level":"info","ts":"2024-02-01T19:17:01+03:00","caller":"proxy/client.go:45","msg":"client <- server: LogMessage","message":"2024/02/01 19:17:00 go/packages.Load #1: updating metadata for 245 packages\n"}
{"level":"info","ts":"2024-02-01T19:17:01+03:00","caller":"proxy/client.go:36","msg":"client <- server: Progress"}
{"level":"info","ts":"2024-02-01T19:17:01+03:00","caller":"proxy/client.go:111","msg":"client <- server: RegisterCapability"}
{"level":"info","ts":"2024-02-01T19:17:01+03:00","caller":"proxy/client.go:111","msg":"client <- server: RegisterCapability"}
{"level":"info","ts":"2024-02-01T19:19:23+03:00","caller":"proxy/server.go:559","msg":"client -> server: DidOpen","uri":"file:///Users/user/Code/koddr/oau-core/templates/pages/index.templ"}
{"level":"info","ts":"2024-02-01T19:19:23+03:00","caller":"proxy/server.go:583","msg":"setting source map cache contents","uri":"file:///Users/user/Code/koddr/oau-core/templates/pages/index.templ"}
{"level":"info","ts":"2024-02-01T19:19:23+03:00","caller":"proxy/server.go:590","msg":"client -> server: DidOpen end"}
{"level":"info","ts":"2024-02-01T19:19:23+03:00","caller":"proxy/server.go:231","msg":"client -> server: CodeAction"}
{"level":"info","ts":"2024-02-01T19:19:23+03:00","caller":"proxy/server.go:259","msg":"client -> server: CodeAction end"}
{"level":"info","ts":"2024-02-01T19:19:23+03:00","caller":"proxy/server.go:660","msg":"client -> server: DocumentSymbol"}
{"level":"info","ts":"2024-02-01T19:19:23+03:00","caller":"proxy/server.go:664","msg":"client -> server: DocumentSymbol end"}
{"level":"info","ts":"2024-02-01T19:19:23+03:00","caller":"proxy/client.go:50","msg":"client <- server: PublishDiagnostics"}
{"level":"info","ts":"2024-02-01T19:19:23+03:00","caller":"proxy/server.go:631","msg":"client -> server: DocumentLink","uri":"file:///Users/user/Code/koddr/oau-core/templates/pages/index.templ"}
{"level":"info","ts":"2024-02-01T19:19:23+03:00","caller":"proxy/server.go:633","msg":"client -> server: DocumentLink end"}
{"level":"info","ts":"2024-02-01T19:19:23+03:00","caller":"proxy/server.go:231","msg":"client -> server: CodeAction"}
{"level":"info","ts":"2024-02-01T19:19:23+03:00","caller":"proxy/server.go:259","msg":"client -> server: CodeAction end"}
{"level":"info","ts":"2024-02-01T19:19:23+03:00","caller":"proxy/server.go:263","msg":"client -> server: CodeLens"}
{"level":"info","ts":"2024-02-01T19:19:23+03:00","caller":"proxy/server.go:276","msg":"client -> server: CodeLens end"}
{"level":"info","ts":"2024-02-01T19:19:23+03:00","caller":"proxy/server.go:674","msg":"client -> server: FoldingRanges"}
{"level":"info","ts":"2024-02-01T19:19:23+03:00","caller":"proxy/server.go:678","msg":"client -> server: FoldingRanges end"}
{"level":"info","ts":"2024-02-01T19:19:24+03:00","caller":"proxy/server.go:231","msg":"client -> server: CodeAction"}
{"level":"info","ts":"2024-02-01T19:19:24+03:00","caller":"proxy/server.go:259","msg":"client -> server: CodeAction end"}
{"level":"info","ts":"2024-02-01T19:19:24+03:00","caller":"proxy/server.go:631","msg":"client -> server: DocumentLink","uri":"file:///Users/user/Code/koddr/oau-core/templates/pages/index.templ"}
{"level":"info","ts":"2024-02-01T19:19:24+03:00","caller":"proxy/server.go:633","msg":"client -> server: DocumentLink end"}
{"level":"info","ts":"2024-02-01T19:19:25+03:00","caller":"proxy/server.go:712","msg":"client -> server: Hover"}
{"level":"info","ts":"2024-02-01T19:19:25+03:00","caller":"proxy/server.go:71","msg":"updatePosition: found","uri":"file:///Users/user/Code/koddr/oau-core/templates/pages/index.templ","fromTempl":"38:42","toGo":"145:42"}
{"level":"info","ts":"2024-02-01T19:19:25+03:00","caller":"proxy/server.go:723","msg":"client -> server: Hover end"}
{"level":"info","ts":"2024-02-01T19:19:28+03:00","caller":"proxy/server.go:712","msg":"client -> server: Hover"}
{"level":"info","ts":"2024-02-01T19:19:28+03:00","caller":"proxy/server.go:71","msg":"updatePosition: found","uri":"file:///Users/user/Code/koddr/oau-core/templates/pages/index.templ","fromTempl":"41:76","toGo":"148:76"}
{"level":"info","ts":"2024-02-01T19:19:28+03:00","caller":"proxy/server.go:723","msg":"client -> server: Hover end"}

@joerdav joerdav added NeedsInvestigation Issue needs some investigation before being fixed and removed WaitingForMoreInfo labels Feb 1, 2024
@joerdav joerdav changed the title vscode: Request textDocument/hover failed on Cyrillic characters lsp: Request textDocument/hover failed on Cyrillic characters Feb 1, 2024
@joerdav joerdav added lsp and removed vscode labels Feb 1, 2024
@a-h
Copy link
Owner

a-h commented Feb 5, 2024

I can reproduce it with Chinese too.

Hovering over the Chinese text in var happyBirthday = "生日快乐" causes a "rune error" too.

Since the underlying error is a *jsonrpc2.Error and the message isn't in templ, I figured it must be deeper in the stack and tracked it to gopls: https://cs.opensource.google/go/x/tools/+/master:gopls/internal/golang/hover.go;drc=c3f60b7871c6c0f1f49094d63dcf73622a1d1ea0;l=630

From what I can see so far, it looks like our RangeWriter is using UTF8 positions, when the LSP expects "somewhat" UTF16 positions. Since we're using UTF8 positions, we have 3 bytes per rune, which means gopls starts grabbing weird slices of bytes and doesn't like it.

I think the RangeWriter is writing the "end" of its byte sequence position, rather than the start of its position, or something like that.

@a-h
Copy link
Owner

a-h commented Apr 22, 2024

In Neovim, it's possible to enable additional logging with :lua vim.lsp.set_log_level("DEBUG").

With that in place, you can use :LspLog to see what's going on.

My test file is:

package main

var nihao = "你好"

var 你好 = "nihao"

I'm putting the cursor on (ni) on the last line and using gr (go to reference).

Here's the log data:

[DEBUG][2024-04-22 10:48:10] .../lua/vim/lsp.lua:1391	"LSP[gopls]"	"client.request"	2	"textDocument/references"	{  context = {    includeDeclaration = true  },  position = {    character = 5,    line = 4  },  textDocument = {    uri = "file:///home/adrian-hesketh/lsptest/main.go"  }}	<function 1>	1
[DEBUG][2024-04-22 10:48:10] .../vim/lsp/rpc.lua:284	"rpc.send"	{  id = 3,  jsonrpc = "2.0",  method = "textDocument/references",  params = {    context = {      includeDeclaration = true    },    position = {      character = 5,      line = 4    },    textDocument = {      uri = "file:///home/adrian-hesketh/lsptest/main.go"    }  }}
[DEBUG][2024-04-22 10:48:10] .../vim/lsp/rpc.lua:387	"rpc.receive"	{  id = 3,  jsonrpc = "2.0",  result = { {      range = {        ["end"] = {          character = 6,          line = 4        },        start = {          character = 4,          line = 4        }      },      uri = "file:///home/adrian-hesketh/lsptest/main.go"    } }}

The interesting bit is the rpc.send which shows where Neovim thinks my cursor is:

position = {      character = 5,      line = 4    }

The next character along is char 6, on line 4. So gopls is happily using cursor positions, not byte positions. I suspect then, that the RangeWriter needs to stop counting the size of bytes it's written out, and count the number of runes it has output instead.

@a-h
Copy link
Owner

a-h commented Apr 30, 2024

I think I've resolved this in #712 - care to test out the branch and check that it properly resolves it for you @koddr?

@a-h a-h closed this as completed in d120e33 May 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working lsp NeedsInvestigation Issue needs some investigation before being fixed
Projects
None yet
Development

No branches or pull requests

3 participants