vim-go icon indicating copy to clipboard operation
vim-go copied to clipboard

adding strings in multiple lines in var or const block statement breaks Go syntax highlighting

Open paskozdilar opened this issue 10 months ago • 1 comments

I've opened an issue on NeoVim repository, and I was directed to open an issue here.

The same issue also exists on Vim. Vim ./runtime/syntax/go.vim is (allegedly) up-to-date with vim-go, but I don't know how to verify that since injecting the go.vim file from vim-go into vim repository causes errors. I assume Vim does some kind of transformations on it?


Anyways, here's the details of the issue:

The following Go snippet breaks syntax highlighting in Vim:

package main

var (
	host  string
	usage string = "" +
		"\"\""
)

func main() {}

This can be reproduced in a Docker container by downloading the latest nightly Vim AppImage:

FROM ubuntu:24.04

RUN apt-get -y update && apt-get -y install curl

WORKDIR /app

RUN curl -LO https://github.com/vim/vim-appimage/releases/download/v9.1.1106/Vim-v9.1.1106.glibc2.29-x86_64.AppImage

RUN chmod u+x Vim-v9.1.1106.glibc2.29-x86_64.AppImage

RUN ./Vim-v9.1.1106.glibc2.29-x86_64.AppImage --appimage-extract

RUN echo 'package main' >> main.go
RUN echo '' >> main.go
RUN echo 'var (' >> main.go
RUN echo '	host  string' >> main.go
RUN echo '	usage string = "" +' >> main.go
RUN echo '		"\"\""' >> main.go
RUN echo ')' >> main.go
RUN echo '' >> main.go
RUN echo 'func main() {}' >> main.go

CMD ["/app/squashfs-root/AppRun", "main.go"]

Running docker build . -t test && docker run --rm -it test shows the following screen:

Image

The statement func main() {} and everything after it is completely devoid of syntax highlighting.

paskozdilar avatar Feb 13 '25 10:02 paskozdilar

That's interesting. Strangely, there are no syntax highlighting problems if this is done without using a var or const block.

bhcleek avatar Mar 10 '25 01:03 bhcleek