An LSP server implementation for Pascal variants that are supported by Free Pascal, including Object Pascal. It uses CodeTools from Lazarus as backend.
The implementation is still incomplete.
- textDocument
- declaration
- implementation
- references
- signatureHelp
- documentSymbol
- Only
SymbolInformation
is implemented
- Only
- documentHighlight
- completion
- window
- showMessage
- workspace
- symbol
- diagnostics
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"
],
"options":
{
"name": "string|number|boolean"
},
"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"
}
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.options.
// 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
- 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