Perl Navigator Language Server
Perl Navigator is an actively developed Language Server Protocol (LSP) implementation providing advanced code intelligence for Perl. Currently at version 0.8.20, it is designed to work across various operating systems (Windows, macOS, Linux) and integrates with popular editors supporting LSP, such as VS Code, Neovim, Emacs, and Sublime Text. It offers features like syntax checking, smart context-aware autocompletion, 'Go To Definition' (including core and installed modules), code formatting via Perl::Tidy, Perl::Critic static analysis, and imports cleanup via perlimports. A key differentiator is its broad Perl version compatibility, working back to Perl 5.8, and its robust parsing capabilities for modern Perl features and class builders like Moo/Moose/Object::Pad. While the core server is written in TypeScript and Node.js, its primary function is to enhance the Perl development experience through editor integration, not to be consumed as a JavaScript/TypeScript library directly.
Common errors
-
command not found: perlnavigator
cause The `perlnavigator` executable is not in your system's PATH, or the global npm install failed or was not performed.fixRun `sudo npm install -g perlnavigator-server` to install globally, or ensure the installation directory is added to your system's PATH environment variable. If installing from source, ensure `npx tsc` was run in the `server/` directory and your editor configuration points to the correct `server/out/server.js` path. -
No Syntax Highlighting, nor Code completion. Also the imported Scalar Package is not recognised.
cause The Perl Navigator server is running but cannot find your Perl executable or is not correctly resolving Perl modules due to incorrect include paths.fixVerify and set the `perlnavigator.perlPath` setting in your editor's LSP configuration to the absolute path of your Perl executable. Also, add directories containing your project's Perl modules to `perlnavigator.includePaths` (e.g., `"perlnavigator.includePaths": ["$workspaceFolder/lib", "/path/to/cpan_modules"]`). -
Perl::Critic diagnostics or Perl::Tidy formatting not working, or 'perlimports' does not clean up code.
cause The Perl modules `Perl::Critic`, `Perl::Tidy`, or `perlimports` are either not installed on your system or the Perl Navigator configuration for their profiles is incorrect.fixInstall the necessary Perl modules via CPAN (e.g., `cpanm Perl::Critic Perl::Tidy perlimports`). Additionally, check your editor's LSP settings for `perlnavigator.perlcriticEnabled`, `perlnavigator.perlcriticProfile`, `perlnavigator.perltidyProfile`, and `perlnavigator.perlimportsProfile` to ensure they are enabled and point to valid profile files if custom ones are used.
Warnings
- gotcha Perl Navigator is a Language Server, an executable application, not a traditional JavaScript/TypeScript library designed for programmatic imports into other Node.js projects. Its interaction model is via the Language Server Protocol (LSP) through editor integrations. Attempting to `import` or `require` symbols directly from the `perlnavigator-server` package will likely result in unexpected behavior or errors, as its main export is the server's entry point, not a library API.
- gotcha For features like static analysis (Perl::Critic), code formatting (Perl::Tidy), and imports cleanup (perlimports), the corresponding Perl modules are NOT bundled with `perlnavigator-server`. These modules must be installed separately via CPAN on your system for Perl Navigator to utilize them.
- gotcha If Perl is installed in a non-standard location or if you are using a Perl environment manager (like `perlbrew`), you might need to explicitly configure the `perlnavigator.perlPath` setting in your editor's LSP client. The server might fail to find your Perl executable, leading to non-functional language features.
- gotcha When developing in environments with specialized Perl setups, such as Docker containers or complex multi-root workspaces, Perl Navigator might not find custom modules. It's crucial to correctly configure `perlnavigator.perlPath` and `perlnavigator.includePaths` to reflect the Perl environment and module directories within your project.
- gotcha The `perlimports` feature, used for cleaning up imports, requires the file you are working on to be saved to disk for accurate results due to implementation limitations. Real-time updates for `perlimports` diagnostics might not occur until after a save action.
- gotcha If you are installing Perl Navigator from source by cloning the GitHub repository, merely running `npm install` in the root might not be sufficient. The TypeScript source code for the server (`server/src/server.ts`) needs to be compiled to JavaScript (`server/out/server.js`) using `npx tsc` within the `server/` directory before the server executable is available.
Install
-
npm install perlnavigator-server -
yarn add perlnavigator-server -
pnpm add perlnavigator-server
Quickstart
{
"languageserver": {
"perl": {
"command": "perlnavigator",
"args": ["--stdio"],
"filetypes": ["perl", "cperl", "pl", "pm", "t", "cgi", "psgi"],
"rootPatterns": [
"cpanfile",
"META.json",
"META.yml",
".git",
"perlnavigator.json"
],
"settings": {
"perlnavigator.perlPath": "/usr/bin/perl",
"perlnavigator.includePaths": ["$workspaceFolder/lib"],
"perlnavigator.perlcriticEnabled": true
}
}
}
}