ray-x / lsp_signature.nvim

LSP signature hint as you type
Apache License 2.0
2.07k stars 57 forks source link

Error when completing `Write([]byte)` writer functions in GO #126

Closed dmbfm closed 2 years ago

dmbfm commented 2 years ago

When programming in golang, whenever I use the Write([]byte) function of the Writer interface I guess this error:

Error executing vim.schedule lua callback: ...er/start/lsp_signature.nvim/lua/lsp_signature_helper.lua:399: malformed pattern (missing ']')

Here is a video of when it happens:

https://user-images.githubusercontent.com/8743306/142300931-7c48fda4-d60c-486f-b1b8-075a888e2a46.mov

And here is the log output:

  documentation = "Write writes the data to the connection as part of an HTTP reply.\n\nIf WriteHeader has not yet been called, Write calls\nWriteHeader(http.StatusOK) before writing the dat
a. If the Header\ndoes not contain a Content-Type line, Write adds a Content-Type set\nto the result of passing the initial 512 bytes of written data to\nDetectContentType. Additionally, if
the total size of all written\ndata is under a few KB and there are no Flush calls, the\nContent-Length header is added automatically.\n\nDepending on the HTTP protocol version and the clien
t, calling\nWrite or WriteHeader may prevent future reads on the\nRequest.Body. For HTTP/1.x requests, handlers should read any\nneeded request body data before writing the response. Once th
e\nheaders have been flushed (due to either an explicit Flusher.Flush\ncall or writing enough data to trigger a flush), the request body\nmay be unavailable. For HTTP/2 requests, the Go HTTP
 server permits\nhandlers to continue to read the request body while concurrently\nwriting the response. However, such behavior may not be supported\nby all HTTP/2 clients. Handlers should r
ead before writing if\npossible to maximize compatibility.\n",
  label = "Write([]byte) (int, error)",
  parameters = { {
      label = "[]byte"
    } }
}
 |3: 0
שׁ ...er/start/lsp_signature.nvim/lua/lsp_signature_helper.lua:144 |1: func |2: Write([]byte) (int, error) |3: {
  label = "[]byte"
}
שׁ ...ck/packer/start/lsp_signature.nvim/lua/lsp_signature.lua:230 |1: md lines trim |2: { "```go", "Write([]byte) (int, error)", "```", "Write writes the data to the connection as part of an
 HTTP reply.", "", "If WriteHeader has not yet been called, Write calls", "WriteHeader(http.StatusOK) before writing the data. If the Header", "does not contain a Content-Type line, Write ad
ds a Content-Type set", "to the result of passing the initial 512 bytes of written data to", "DetectContentType. Additionally, if the total size of all written", "data is under a few KB and
there are no Flush calls, the", "Content-Length header is added automatically.", "", "Depending on the HTTP protocol version and the client, calling", "Write or WriteHeader may prevent futur
e reads on the", "Request.Body. For HTTP/1.x requests, handlers should read any", "needed request body data before writing the response. Once the", "headers have been flushed (due to either
an explicit Flusher.Flush", "call or writing enough data to trigger a flush), the request body", "may be unavailable. For HTTP/2 requests, the Go HTTP server permits", "handlers to continue
to read the request body while concurrently", "writing the response. However, such behavior may not be supported", "by all HTTP/2 clients. Handlers should read before writing if", "possible
to maximize compatibility." }
שׁ ...ck/packer/start/lsp_signature.nvim/lua/lsp_signature.lua:253 |1: label: |2: Write([]byte) (int, error) |3: 0 |4: 1 |5: 0 |6: {
  documentation = "Write writes the data to the connection as part of an HTTP reply.\n\nIf WriteHeader has not yet been called, Write calls\nWriteHeader(http.StatusOK) before writing the dat
a. If the Header\ndoes not contain a Content-Type line, Write adds a Content-Type set\nto the result of passing the initial 512 bytes of written data to\nDetectContentType. Additionally, if
the total size of all written\ndata is under a few KB and there are no Flush calls, the\nContent-Length header is added automatically.\n\nDepending on the HTTP protocol version and the clien
t, calling\nWrite or WriteHeader may prevent future reads on the\nRequest.Body. For HTTP/1.x requests, handlers should read any\nneeded request body data before writing the response. Once th
e\nheaders have been flushed (due to either an explicit Flusher.Flush\ncall or writing enough data to trigger a flush), the request body\nmay be unavailable. For HTTP/2 requests, the Go HTTP
 server permits\nhandlers to continue to read the request body while concurrently\nwriting the response. However, such behavior may not be supported\nby all HTTP/2 clients. Handlers should r
ead before writing if\npossible to maximize compatibility.\n",
  label = "Write([]byte) (int, error)",
  parameters = { {
      label = "[]byte"
    } }
}
שׁ ...er/start/lsp_signature.nvim/lua/lsp_signature_helper.lua:398 |1: line_to_cursor / arg |2:         w.Write(s |3: .*Write([]byte)
Error executing vim.schedule lua callback: ...er/start/lsp_signature.nvim/lua/lsp_signature_helper.lua:399: malformed pattern (missing ']')
שׁ ...ck/packer/start/lsp_signature.nvim/lua/lsp_signature.lua:458 |1: Insert leave cleanup
שׁ ...er/start/lsp_signature.nvim/lua/lsp_signature_helper.lua:285 |1: cleanup vt |2: 23

The line numbers are off in the log because I added a log statement:

image

so that the error is originally on line 398:

local function_on_line = line_to_cursor:match('.*' .. function_name)
ray-x commented 2 years ago

image Strange, I can not reproduce

Do you use latest nvim 0.6.x ? what is you lua version?

dmbfm commented 2 years ago

Sorry, forgot to add this info before! I am using neovim 0.5.1

NVIM v0.5.1
Build type: Release
LuaJIT 2.1.0-beta3
Compilation: clang -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -DNVIM_TS_HAS_SET_MATCH_LIMIT -O2 -DNDEBUG -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -Wshadow -Wconversion -Wmissing-prototypes -Wimplicit-fallthrough -Wvla -fstack-protector-strong -fno-common -fdiagnostics-color=auto -DINCLUDE_GENERATED_DECLARATIONS -D_GNU_SOURCE -DNVIM_MSGPACK_HAS_FLOAT32 -DNVIM_UNIBI_HAS_VAR_FROM -DMIN_LOG_LEVEL=3 -I/tmp/neovim-20210926-83501-wt6eyz/neovim-0.5.1/build/config -I/tmp/neovim-20210926-83501-wt6eyz/neovim-0.5.1/src -I/opt/homebrew/include -I/Library/Developer/CommandLineTools/SDKs/MacOSX11.sdk/usr/include -I/opt/homebrew/opt/gettext/include -I/tmp/neovim-20210926-83501-wt6eyz/neovim-0.5.1/build/src/nvim/auto -I/tmp/neovim-20210926-83501-wt6eyz/neovim-0.5.1/build/include
Compiled by brew@HMBRW-A-001-M1-005.local

Features: +acl +iconv +tui
See ":help feature-compile"

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "/opt/homebrew/Cellar/neovim/0.5.1/share/nvim"

Run :checkhealth for more info
dmbfm commented 2 years ago

Is 0.6.x the recommended version for this plugin?

ray-x commented 2 years ago

I pushed a fix for it. Hope it works

dmbfm commented 2 years ago

Works perfectly now, thanks!!