⬆️ ⬇️

Nginx support in IntelliJ IDEA

idea nginx plugin

I use nginx as front server for my project. The project itself is written in Java in IntelliJ IDEA. I wanted to edit the nginx configs and run nginx right in IDEA. I sat down and wrote a plugin .



Version for Maia (IDEA 9) is also there . I had to collect separately. in a major release, some APIs traditionally changed.



Setup is similar to setting up application servers. First, in the settings we create a server:

Setup of the nginx server in IDEA



When an executable file is selected, it is launched with the -V key and, if it was nginx, the parameters set during compilation are read. We need --conf-path, --pid-path and --prefix. Of these, absolute paths to the config and pid file are constructed, which will eventually be used at startup. If desired, nothing prevents them from changing.

Startup setup is also similar to the application server startup setup:

Setting up nginx launch in IDEA

')

In the console, in addition to the “Rerun” and “Stop” buttons, there appears the “Reload” button, which sends the SIGHUP process on Linux / Mac or does nginx -s reload on Windows. Immediately before reloading the config, I do nginx -t for the given configuration. And if suddenly something went wrong, nginx will report it, indicating where and what happened. The link in the console is clickable and opens the specified file on the specified line. In the current version (0.8.7) I noticed that the line number is sometimes lying. But this is already a nginx problem, not mine. Somehow I will write to Igor Sysoev about it.

Nginx console in IDEA



The tooltip on the previous screenshot says that I know what the nginx config is and what should be in the config and what should not. Configuration files are not visible in the project tree, but they can be opened with shortcut ctrl + shift + n (go to file). All files located next to the configuration file and one folder deeper become accessible by opening with ctrl + shift + n and are regarded as nginx files. It may be necessary to open / mark as files nginx only those files that are listed in include in the root config. But not sure yet what it needs. With the current approach, we must bear in mind that if the nginx configuration file is in your Program Files folder, then nothing good will happen. I hope people usually put all the nginx configs in one folder.

Opening nginx configuration files in IDEA



As mentioned above, the syntax and semantics of the config is taken into account. To do this, I take a bite out of a sish source list of all possible directives, their limitations on the number of arguments, the context in which they can appear, and so on. Auto-completion also works and takes into account the context in which we are.

Autocompletion in the nginx config in IDEA



Among other things, it checks the number of directive arguments, the possibility of opening a child context, folding works (collapsing blocks with arrows on the editor’s left border), comments on ctrl + / works, and maybe something else I forgot.



What is not yet: auto-formatting, inline documentation on ctrl + q, recognition of embedded variables ($ host and so on), opening files specified in include by ctrl + click / ctrl + b, a separate tab next to the console for outputting the log, checking the validity of directive values , something else you need.



What will be done: all that has not been done.



Open source plugin, licensed under Apache 2.0. Lives on code.google.com/p/idea-nginx . Works in Windows / Linux / Mac, that is, wherever IDEA works.



UPD: from the moment of publication tabs for logs are made next to the console, support for embedded variables, viewing documentation (ctrl + q)

Source: https://habr.com/ru/post/66255/



All Articles