Minimal VS Code extension for OpenResty and Nginx configuration files with embedded Lua highlighting.
This extension is declarative only. It contributes a language id, TextMate grammar, language configuration, snippets, and an example config. There is no TypeScript or JavaScript runtime.
Features
- Recognizes
*.conffiles and common Nginx config folder patterns. - Highlights Nginx/OpenResty comments with
#. - Highlights embedded Lua comments with
--inside*_by_lua_block { ... },*_by_lua '...', and*_by_lua "..."regions. - Uses a separate embedded language configuration for Lua regions, so editor comment commands can use
--inside Lua while regular config regions use#. - Covers common OpenResty directives such as
lua_package_path,lua_package_cpath,lua_shared_dict,lua_code_cache, and*_by_lua_file. - Covers regular Nginx blocks such as
events,http,server,location,upstream,stream,map, andtypes. - Provides snippets for common OpenResty server, Lua phase, shared dictionary, package path, and upstream patterns.
Notes
TextMate grammars cannot fully parse Nginx brace nesting or Lua syntax. The grammar deliberately uses conservative region detection:
- Lua block regions start on directives like
content_by_lua_block {. - Lua block regions end on a line whose first non-space token is
}. - Inline Lua string regions start on directives like
rewrite_by_lua '...'oraccess_by_lua "...".
If a separate Lua extension is installed, VS Code can use its source.lua grammar inside embedded Lua regions. Without one, this extension still highlights Lua comments and common escapes in those regions.
Development
Open this folder in VS Code and run the Run Extension launch configuration. In the Extension Development Host, open examples/nginx.conf and make sure the language mode is OpenResty.
Example
See examples/nginx.conf.