chr4 / nginx.vim

Improved nginx vim plugin (incl. syntax highlighting)
449 stars 41 forks source link

Embedding LUA breaks the syntax highlighting #24

Open zambotn opened 1 year ago

zambotn commented 1 year ago

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:

chr4 commented 1 year ago

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?

zambotn commented 1 year ago

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.

chr4 commented 1 year ago

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