🧬 RouterOS LSP for better syntax checking & command completion in editors like VSCode & NeoVim

Now Published as VSCode Extension!

The newest (v0.3.4) release now appears in VSCode’s Extension ā€˜Marketplace’, to allow for easy install and update. To install – in Visual Studio Code — use Shift + ⌘ + X to bring up ā€œExtensionsā€ in VSCode, then search for ā€œRouterOS LSPā€ and this plugin will appear. Next, hit the ā€œInstallā€ button, where it will prompt you it’s pre-release from an unverified developer. This method allows the extension to be updated as fixes and new features are add.

Once the LSP is nstalled to VSCode in all case it must configured to use a RouterOS device via REST API to get

/console/inspect

data. In VSCode you can bring up ā€œSettingsā€ using ⌘ + , then search for ā€œRouterOS LSPā€. There the ā€œbaseUrlā€ (https:// — without trailing / or path), ā€œusernameā€, and ā€œpasswordā€ must be set. The README.md explains more on configuration — like using a RouterOS account with less permissions since only

/console/inspect

is used and NO writes are done by the LSP.

Improvements

Made some improvements from the prototype (v0.1.x), so we’re at the 0.3.x chain. As described in #1 post, the RouterOS LSP can be downloaded from GitHub Releases, and the README.md for the project has installation and other details. Also there is new CHANGES.md that details the known issues and has a version changelog.

While other fixes to various behaviors… some notable changes include:

Fidelity to RouterOS Colors

LSP’s semantic tokens are now matched one-to-one with RouterOS ā€œhighlightsā€ used in CLI. So the default color scheme (at least for NeoVim and VSCode) should roughly match RouterOS color scheme. The semantic tokens also let the user customize specific parts like a ā€œcmdā€, ā€œdirā€, ā€œargā€, etc. as desired. It does not yet colorize types like ā€œipā€, ā€œnumā€, ā€œarrayā€, etc yet –

 /console/inspect

does not provide those, so they’d need to be inferred by regex (not done).[/i]

Better NeoVim Support

The provided example Lua script (nvim-routeros-lsp-init.lua) to load LSP into NeoVim has been expanded and ā€œcorrectedā€ in a few places. The example now adds semantic tokens support to use same coloring as VSCode (and RouterOS). It also by default enables ā€œautocompleteā€, which always show the completion options if / : = are typed. This makes NeoVim (nvim) act a bit like RouterOS ā€œhotlockā€ feature. As such, it can be disabled by changing the ā€œhotlockā€ to false in ā€œsettingsā€ at top of the Lua script. Since example setup Lua avoids person preferences (so there is no ⌘+Space configured), to let user customize as needed, completion can always be done using ⌘X then ⌘O (for ā€œomnicompā€) even when ā€œhotlockā€ is disabled.

Logging and Performance Improvements

Completions, syntax checking, and more all make a REST call to RouterOS’s /console/inspect. So reducing the number of calls needed has a big impact on performance. In the current release, the number of calls are reduced, more could be done like caching or avoiding duplicative calls. Also the new release does ā€œcleanupā€ the logs to avoid using large ā€œdumpā€, so easier to trace (including # REST calls). To access the logs in VSCode, use Shift + ⌘ + X to bring up the ā€œOutputā€ panel, and select ā€œRouterOS LSPā€ from dropdown. For NeoVim, see their docs on accessing LSP logs
routeros-colors-in-lsp-on-alpine-armv7-container.png