nginx.vim icon indicating copy to clipboard operation
nginx.vim copied to clipboard

Embedding LUA breaks the syntax highlighting

Open zambotn opened this issue 2 years ago • 4 comments
trafficstars

When I am embedding LUA code in nginx.conf highlights breaks.

pid /tmp/nginx.pid;

daemon off;

worker_processes 48;

worker_rlimit_nofile 20821;

worker_shutdown_timeout 240s ;

events {
	multi_accept        on;
	worker_connections  16384;
	use                 epoll;
}

http {
	lua_package_path "/etc/nginx/lua/?.lua;;";
	
	lua_shared_dict balancer_ewma 10M;
	lua_shared_dict balancer_ewma_last_touched_at 10M;
	lua_shared_dict balancer_ewma_locks 1M;
	lua_shared_dict certificate_data 20M;
	lua_shared_dict certificate_servers 5M;
	lua_shared_dict configuration_data 20M;
	lua_shared_dict ocsp_response_cache 5M;
	
	server {
		listen 127.0.0.1:10247;
		
		access_log off;
		
        content_by_lua_block {
            ngx.say('Hey!')
	}
    }
	
	# TCP services
	
	# UDP services
	
}

using VimR Version 0.43.0 (20221115.195322), which itself is using NeoVim 0.8.1 is rendered as follow:

immagine

there are different problems and I don't know if they are related or not:

  • closed parenthesis is always grouped as luaParenError.

  • It looks like the ngxLua region starts but doesn't end with the matching } (i.e. the lines starting with # in the NGINX part, later on, are not marked as comments).

zambotn avatar Dec 15 '22 12:12 zambotn

Hey, thanks for the report. I can confirm your example breaks syntax highlighting.

Can you check whether this problem persists with the upstream vim plugin?

chr4 avatar Dec 15 '22 15:12 chr4

It does work properly in the upstream vim plugin you sent me, although it doesn't provide Lua syntax and keeps using nginx one (in the image you can see no LUA code is highlighted, and the Lua comment is not highlighted as a comment).

immagine

I am not a Vim syntax guru, but my feeling (so it can be a wrong feeling) is that the issue is generating because ngxLua, luaError and luaTableBlock all ends with } and the priority is given to the later matching one (so the one inside the Lua syntax?). I didn't study the Vim syntax and I have not much time to do so in those days. I rembember there is the keepend option but it will stop matching to the first match, unless extend is used on contained elements, which we cannot control since those elements are in the Lua syntax.

zambotn avatar Dec 16 '22 09:12 zambotn

I can confirm this issue. I'll look into it when I find the time, pull requests welcome!

chr4 avatar Dec 31 '22 14:12 chr4

In my case, changing end=+}+me=s-1 into end=+^\s*}\s*$+me=s-1 and adding keepend looks satisfactory as my Nginx config are well formatted and I don't use braces in my Lua code.

At least this restores Nginx syntax highlighting after the Lua block, but closing parentheses are still highlighted in red inside the Lua block.

iBug avatar Sep 23 '24 15:09 iBug