asp-lsp
A VSCode extension for asp-lsp, a language server for answer set programming.
Features
Installation
- Open Visual Studio Code.
- Go to the Extensions view by clicking on the Extensions icon in the Activity Bar on the side of the window or by pressing
Ctrl+Shift+X
.
- Search for
asp-lsp
.
- Click
Install
to install the extension.
How To Use
- Open a
.lp
file or create a new one in your workspace.
- The language server should start automatically with all available features
Feature Examples
Code Completion
The language server currently supports keyword completions for directives such as #show
, #const
and #minimize
as well as completion for previously declared predicates.
Given a predicate such as:
example(1,2,3,4).
When trying to insert it elsewhere the code completion first offers a selection of possible completion candidates.
After selecting a predicate, the completion inserts a fitting template that allows to quickly insert arguments by using TAB
to jump from one to the next.
Hover
In order to use the hover
feature for predicates one first has to write doc strings
that provide the wanted information.
Doc Strings
To define a doc string
for a predicate, first a multi-line comment using %*
and *%
has to be created. The first content of the comment has to be a #
followed by the predicate's full signature (including the dot!). It is advised to follow the signature with a general description of the predicate. Lastly #parameters
(or a valid markdown header for Parameters
) on a single line opens up the parameter descriptions. Each parameter is described by their name followed by :
and a description.
A full example may look as follows:
%*
#example_predicate(A,B,C).
This is an example predicate used for the illustration of doc strings.
#parameters
- A : The first argument/parameter of the predicate.
- B : Another parameter of this example predicate.
- C : The last parameter in this example.
*%
After this doc string is defined anywhere in the .lp
file, simply hovering over any example_predicate/3
will show the information.
Hovering over an argument/parameter shows the corresponding informaton.
Diagnostics
The language server is also capable of finding syntax errors.
Safety
When defining rules, the language server will continuously check whether the variables used in the statement are safe or not.
Goto
Since ASP allows for multiple declarations of the same predicate, goto definition shows all occurrences of the predicate in the head. Similarly, goto reference shows all occurrences of the predicate in the body.
Issues, Requests Or Questions
If you have any issues, requests, questions or suggestions, feel free to contact me directly or open an issue on github.