nginx.vim
nginx.vim copied to clipboard
Embedding LUA breaks the syntax highlighting
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:
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
ngxLuaregion 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).
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?
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).
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.
I can confirm this issue. I'll look into it when I find the time, pull requests welcome!
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.