-
Notifications
You must be signed in to change notification settings - Fork 15
Proposal: provide a way to detect NGINX context based on line number #142
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Keeping track of context (I suspect a slice of strings maybe isn't enough) could get difficult. Endline might get you close in some cases but you'll probably still need to do some guessing. I think both these examples will make it tricky for anyone using Crossplane to modify NGINX configs unless we also provide some tooling to manage this. Pointers might sound like a solution, but I suspect it will be difficult too. I think you can traverse the payload to determine what the parent context is. This might be more or less tricky depending on the options set when converting from the NGINX config to the JSON payload. Understanding when you're at an empty line in a block/context could be a little tricky, but you could try checking for gaps between directives/nodes? The suggestion for tracking where a node ends is interesting. I would probably suggest including it for all directives as even some non-block directives may start and end on a different line: log_format compression '$remote_addr - $remote_user [$time_local] '
'"$request" $status $body_bytes_sent '
'"$http_referer" "$http_user_agent" "$gzip_ratio"'; |
Definitely. The LSP is line-oriented, so I was largely using crossplane to learn more about what is going on in and around line N. Suggesting changes would be another can of worms that probably wants a more thoughtful AST, but even those are handled in the LSP as line-oriented text.
I tried that, it was ambiguous based on walking the directive tree alone; lines http {
server {
# A
}
# B
server {
}
}
good call, I didn't think about multi-line directives but that'd probably be a big help. At any rate, this work was for a hackathon so might not get much time, but I wanted to note the friction in case it ends up on a roadmap. |
Is your feature request related to a problem? Please describe
I want a better way to find the NGINX context based on line number.
I was attempting to write a language server for NGINX, using
nginx-go-crossplane
to parse files and then cross-reference withnginx-directive-reference
to drive IDE features like autocomplete and accurate documentation.The problem I have is NGINX directives often re-use a name; if my language server wants to show a tooltip and when the user hovers over a
listen
directive, I don't have a good way to tell if they mean HTTPlisten
, streamlisten
or maillisten
.Sometimes it's possible to walk the
Config.Parsed
tree to detect parent context.Sometimes the user might ask for autocomplete suggestions on a blank line, and all I have to work with is a line number. The
Payload
does not contain enough information to determine NGINX context if there's not a directive on that line.Describe the solution you'd like
Parse
keeps a record of the current NGINX context (blockCtx
), I'd like that information to escape.I think this can be captured with some non-trivial refactoring around
parser.Parse
to return the line number with recursive calls.Describe alternatives you've considered
I tried to recursively walk
Config.Parsed
, keeping track of the last directive whered.Line < x && len(d.Block) > 0
, but this fails to detect when a context ends.From F5 internal prototype:
I considering requesting something easier to implement like:
But doesn't doesn't solve the use case where all I have is a line number.
The text was updated successfully, but these errors were encountered: