An LSP server implementation for Pascal variants that are supported by Free Pascal, including Object Pascal. It uses CodeTools from Lazarus as backend.
https://github.com/michaliskambi/pascal-language-server-genericptr notes:
This a fork of a fork. We add capability to configure using castle-pasls.ini
, in particular to define Castle Game Engine path that will make pasls
aware of CGE units and autocomplete CGE API.
The implementation is still incomplete.
- textDocument
- declaration
- implementation
- references
- signatureHelp
- documentSymbol (only
SymbolInformation
) - documentHighlight
- completion
- inlayHint
- window
- showMessage
- workspace
- symbol
- executeCommand
- diagnostics (incomplete)
Editors can supply initialization options to the server, however each client handles this differently so please refer to your editors LSP plugin for more information.
The follow options are supported:
"initializationOptions":
{
"fpcOptions":
[
"-Fu/path/to",
"-Fi/path/to",
"-dMY_MACRO"
],
"symbolDatabase": "/path/to/symbols.db",
"maximumCompletions": "number",
"overloadPolicy": [1, // duplicate function names appear in the list
2, // after the original definition ignore others
3 // add a suffix which denotes the overload count
],
"program": "pasls.lpr",
... additional booleans listed below
}
fpcOptions
: compiler flags used to specifiy paths, macros etc...symbolDatabase
: if a valid path is provided the server will use an SQL database to store symbol information (recommended for faster documentSymbol queries).maximumCompletions
: the maximum number of completions returned per query. If the maximum is exceeded thenCompletionList.isIncomplete
will be set to true and results will be recomputed as the user types.overloadPolicy
: The preferred method to handle overloaded functions in document symbol requests.
Macros are supported in initialization options. The following macros will be expanded:
$(tmpdir)
- Path to your systems temporary directory.$(root)
- Path to the rootURI as specified by the clients initialize request.
The following macro formats are valid:
$macro
$MACRO
$(macro)
$(MACRO)
Boolean values used in initializationOptions.
// procedure completions with parameters are inserted as snippets
insertCompletionsAsSnippets
// procedure completions with parameters (non-snippet) insert
// empty brackets (and insert as snippet)
insertCompletionProcedureBrackets
// workspaces folders will be added to unit paths (i.e. -Fu)
includeWorkspaceFoldersAsUnitPaths
// workspaces folders will be added to include paths (i.e. -Fi)
includeWorkspaceFoldersAsIncludePaths
// syntax will be checked when file opens or saves
checkSyntax
// syntax errors will be published as diagnostics
publishDiagnostics
// enable workspace symbols
workspaceSymbols
// enable document symbols
documentSymbols
// completions contain a minimal amount of extra information
minimalisticCompletions
// syntax errors as shown in the UI with ‘window/showMessage’
showSyntaxErrors
The LSP initializationOptions described above are in general a better way to provide options for LSP. However... the castle-pasls.ini
is
-
central configuration for both LSP server forks (this one, and based on Philip Zander, https://github.com/castle-engine/pascal-language-server ),
-
central configuration for both VS Code and Emacs, which makes it easier for Michalis who uses both.
Allowed options:
[log]
;; Where to write log (contains request / response JSONs).
;; We will add suffix with process id, like '.pid123' .
;; By default none.
filename=/tmp/pasls-log.txt
[castle]
;; Castle Game Engine location.
;;
;; Set this to make pasls autocomplete CGE API by:
;; 1. knowing paths to all CGE units (derived from this CGE path),
;; 2. using default CGE compilation settings, like -Mobjfpc and -Sh (used by CGE build tool and editor).
;;
;; ( Alternatively to this you can define CASTLE_ENGINE_PATH environment variable,
;; but note that VS Code integration prevents all environment variables from reaching pasls now. )
path=/home/michalis/sources/castle-engine/castle-engine/
[extra_options]
;; Specify as many extra FPC options as you want.
;; Each extra option must have a consecutive number, we start from 1, and stop when
;; an option does not exist (or is an empty string).
option_1=-Fu/home/michalis/sources/castle-engine/castle-engine/tests/code/tester-fpcunit
option_2=-dSOME_DEFINE
option_3=-dSOMETHING_MORE
- Optional properties are not implemented so the JSON payloads are bloated.
documentHighlight
should select the begin/end keywords only.textDocument/codeAction
DocumentSymbol
class for document symbols
To use the server from lsp-mode
in Emacs, install the separate
lsp-pascal
module.
Example settings JSON for the LSP package on macOS.
"pascal-language-server":
{
"command":
[
"/pascal-language-server/lib/x86_64-darwin/pasls"
],
"env":
{
"FPCDIR": "/usr/local/share/fpcsrc",
"FPCTARGET": "darwin",
"FPCTARGETCPU": "x86_64",
"LAZARUSDIR": "/usr/share/lazarus",
"PP": "/usr/local/lib/fpc/3.0.4/ppcx64"
},
"initializationOptions": {
// global options which apply to all projects
},
"languageId": "pascal",
"scopes":
[
"source.pascal"
],
"syntaxes":
[
"Packages/FPC/FPC.sublime-syntax"
]
}
Install the extension and configure the settings accordingly. You must have the actual language installed before the extension will work.
Requires Free Pascal Compiler version 3.2.0 and Lazarus version 2.0.8, open the project file in Lazarus or use the commandline:
lazbuild pasls.lpi