fejfighter / eglot-tempel

bridge for tempel templates with eglot
GNU General Public License v3.0
52 stars 5 forks source link

Error thrown when expanding completion #10

Closed Mango0x45 closed 2 months ago

Mango0x45 commented 2 months ago

In go-ts-mode when running Eglot with gopls as the language server, almost every expansion (functions that take parameters) cause an error of the form:

tempel--placeholder: Wrong type argument: buffer-or-string-p, 1

I’m not really sure how to further debug this, such as to see what the snippet actually is.

Mango0x45 commented 2 months ago

Ok so after some investigation I noticed this:

(eglot-tempel--convert "CanonicalHeaderKey(${1:})")
; ((p 1 "CanonicalHeaderKey(" ")" q)

And that is clearly wrong; (p …) doesn’t take a number as an argument.

Mango0x45 commented 2 months ago

Looking at this some more, I believe the issue is that the pattern ${1:} matches this rule:

(placeholder (and "${" int ":" anything "}") `(num place -- `(p ,place ,num)))
fejfighter commented 2 months ago

looking at the grammer:

any         ::= tabstop | placeholder | choice | variable | text
tabstop     ::= '$' int | '${' int '}'
placeholder ::= '${' int ':' any '}'
choice      ::= '${' int '|' text (',' text)* '|}'
variable    ::= '$' var | '${' var }'
                | '${' var ':' any '}'
                | '${' var '/' regex '/' (format | text)+ '/' options '}'
format      ::= '$' int | '${' int '}'
                | '${' int ':' '/upcase' | '/downcase' | '/capitalize' '}'
                | '${' int ':+' if '}'
                | '${' int ':?' if ':' else '}'
                | '${' int ':-' else '}' | '${' int ':' else '}'
regex       ::= Regular Expression value (ctor-string)
options     ::= Regular Expression option (ctor-options)
var         ::= [_a-zA-Z] [_a-zA-Z0-9]*
int         ::= [0-9]+
text        ::= .*
if          ::= text
else        ::= text

it's technically possible, we get a place holder with an 'int' and 'any', 'any' could be text and text is '.*'

I just did not expect a place holder to be empty, I'll add a test with that snippet and work from there

Thanks for reporting