meanmail-dev / nginx-intellij-plugin

Intellij Plugin for Nginx configuration file
https://meanmail.dev/plugin/7
MIT License
56 stars 6 forks source link

Allow Language Injection #2

Closed boppy closed 2 years ago

boppy commented 3 years ago

Is your feature request related to a problem? Please describe. If one uses openresty, there is a possibility to include Lua-Scripts into the config file with access_by_lua_block {} (and others). Those parts are parsed as default nginx-config.

Describe the solution you'd like It would be great if the plugin would realize a language injection (or allow them with a comment or similar) and would disable nginx-language checks and - ideally - highlight the injected language (with Lua-Plugin installed). Currently, the last line of a lua_block is always considered syntactically incorrect, because of the missing ;.

Describe alternatives you've considered Always use _lua_by_file directives and external lua files that get correctly highlighted if the Lua-Plugin is installed.

Additional context Full List of directives from lua-nginx-module:

Reduced config example:

server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    server_name _;

    set $my_nginx_var "";

    location / {
        access_by_lua_block {
            local redis = require "resty.redis"
            local red = redis:new()
            red:set_timeout(200)
            local ok, err = red:connect("127.0.0.1", 6379)
            if not ok then
                return
            end

            local access_num, err = red:incr("access_" .. ngx.var.remote_addr)

            if (not access_num or access_num >= 10) then
                ngx.var.my_nginx_var = "deny"
                return
            end
            ngx.var.my_nginx_var = "allow"
            red:expire("access_" .. ngx.var.remote_addr, 16*3600)
        }
    }
}
meanmail commented 2 years ago

@boppy Add support content_by_lua_block, rewrite_by_lua_block, access_by_lua_block. You can try this in version 2021.3