An LSP server implementation for Pascal variants that are supported by Free Pascal. It uses CodeTools from Lazarus as backend.
Forked from the original project, but has since been mostly rewritten. This fork adds many new features and fixes several bugs.
- Code completion
- Signature help
- Go to declaration
- Go to definition
- Automatic dependency resolution for
.lpk
and.lpr
files
First, make sure, submodules are loaded:
git submodule update --init --recursive
To compile, open the project file in Lazarus or use the command line:
cd server
lazbuild pasls.lpi
It is recommended to use Free Pascal Compiler version 3.2.0 and Lazarus version 2.0.8 or later, older versions are not officially supported.
For information on how to use the server from Neovim, see client/nvim.
To use the server from lsp-mode
in Emacs, install the separate
lsp-pascal
module.
Full example setup of it is documented in Michalis notes about LSP + Pascal.
Install the VS Code extension from https://github.com/genericptr/pasls-vscode .
Note that the extension settings expose some additional LSP options not understood by this LSP server. But the basic ones (FPC, Lazarus configs and the executable of LSP server) work completely fine with this LSP server.
Any editor that allows you to add custom LSP configurations should work.
In order for the language server to find all the units, it needs to know the following parameters:
- location of the FPC standard library source files
- location of the FPC compiler executable
- location of the Lazarus install directory
- the OS you are compiling for
- the architecture you are compiling for
By default, the server will try to auto-detect these parameters from your Lazarus config. It will search for config files in the following locations (the exact paths will depend on your operating system):
<User settings directory>/lazarus
(e.g./home/user/.config/lazarus
)<User home directory>/.lazarus
(e.g./home/user/.lazarus
)<System settings directory>/lazarus
(e.g./etc/lazarus
)
In addition, you can also specify these parameters manually in one of the following ways:
-
Set the environment variables:
PP
— Path to the FPC compiler executableFPCDIR
— Path of the source code of the FPC standard libraryLAZARUSDIR
— Path of your Lazarus installationFPCTARGET
— Target OS (e.g. Linux, Darwin, ...)FPCTARGETCPU
— Target architecture (e.g. x86_64, AARCH64, ...)
This overrides auto-detected settings.
-
Or specify the locations via LSP
initializationOptions
. How this is done will depend on your client. The format is the following:{ "PP": "", "FPCDIR": "", "LAZARUSDIR": "", "FPCTARGET": "", "FPCTARGETCPU": "" }
This overrides environment variables.
Additional keys in LSP initialization options can be used to influence the LSP server behavior. See the docs of your LSP client (text editor) to know how to pass initialization options.
-
syntaxErrorReportingMode
(integer): Determines how to report syntax errors. Syntax errors indicate that CodeTools cannot understand the surrounding Pascal code well enough to provide any code completion.-
0 (default): Show an error message. This relies on the LSP client (text editor) handling the
window/showMessage
message. Support in various text editor:-
VS Code: works.
-
NeoVim (0.8.0): works, the message is shown for ~1 sec by default.
-
Emacs: works, the message is visible in echo area and the
*Messages*
buffer. You can filter out uselessNo completion found
messages to make it perfect, see https://github.com/michaliskambi/elisp/blob/master/lsp/kambi-pascal-lsp.el for example.
-
-
1: Return a fake completion item with the error message. This works well in VC Code and NeoVim -- while the completion item doesn't really complete anything, but the error message is clearly visible.
-
2: Return an error to the LSP client. Some LSP clients will just hide the error, but some (like Emacs) will show it clearly and prominently.
-
- Renaming of identifiers
- “Find all references”
- Signature help: Highlight active parameter
- Code formatting?
- Signature help does not show all overloads