Skip to content

nvs lsp

nvs lsp is the language server that gives an editor its errors, completions and colours for Novis code.

Your editor starts it. In a terminal it prints nothing and looks like it has stopped. It takes no arguments.

The server reports the errors that nvs check reports. It shows the documentation of the name under the cursor and finds where that name is declared. It completes methods, constants, enum cases, keywords and variables, and it gives the outline of a file.

It offers quick fixes (edits that repair an error). One fix rewrites (int)$x to $x as int. It also renames, moves, inlines and deletes code. If the new code would not compile, it changes nothing.

The server watches the .nvs files of your project. When a file changes, the server checks that file and the files that use a changed declaration. When the server starts on a project that did not change, it checks no file.

When you type, the server stops its work on the old text and checks the new text.

Good to know: while a file has a syntax error, the server reports only that error.

Examples

What your editor knows

<?nvs
// The document you have open while `nvs lsp` is running: each comment points at
// something the editor can tell you about the line under it.
final class Receipt
{
public string $customer = '';
public int $cents = 0;
// Hover over `Core\Str::padEnd` and the editor shows its signature and what
// it does, read from the compiler itself. There is no stub file to install.
public function line(): string
{
return Core\Str::padEnd($this->customer, 12)
. Core\Str::format('%d cents', $this->cents);
}
// Type `$this->` inside a method and the completion list is this class's own
// members: the editor resolved the receiver rather than matching on text.
public function shout(): string
{
return Core\Str::upper($this->line());
}
}
var $receipt = new Receipt();
$receipt->customer = 'Ada';
$receipt->cents = 1250;
// Ctrl-click `Receipt` and go-to-definition lands on the class above. The same
// click works across files, wherever a `require` reached the declaration.
echo $receipt->line(), "\n";
echo $receipt->shout(), "\n";
Output
Ada 1250 cents
ADA 1250 CENTS

Changelog

VersionChange
0.0.6Class name completion suggests only the Core classes and the classes in the folders that your program's autoload lines name. In a file that no program loads, it suggests every class.
0.0.6When you rename a property, the name that initProperty, onPropertyGet, onPropertySet and beforePropertySet compare as a string changes too. Find references lists that string.
0.0.6A rename can move a class to another namespace. Write its full new name, such as Shop\Billing\Cart. Every use line changes, and the file moves to the folder that autoload reads for the new name.
0.0.6When you move a class file to another folder with nvs code move or in the editor, the class gets the name that its new path gives. nvs code rename --from <file> does a list of renames in one change.
0.0.6Every rename and move is checked before it changes a file. If the new code would not compile, nothing changes, and you see the error.
0.0.6The editor greys out a declaration that nothing uses, and Delete unused deletes it. Inline variable, Inline this call and Inline method replace a variable or a call with its value.
0.0.6Three new editor actions ask you for text first. They change the parameters of a method, move a member to another class, and extract an interface. nvs code signature, nvs code move and nvs code extract interface do the same.
0.0.6Three code lenses show what recorded requests did. Above a route handler, a lens shows the requests and their p50 duration, and above a Core\Debug::dump call, the newest value. Above a throw, it shows how often it was thrown and when it was thrown last.
0.0.6At a match arm, a key of an array<Status, T> and an argument of an enum type, completion lists the enum's cases first. At an arm and at a key, it lists only the cases you have not written yet. A quick fix adds the arms that a match is missing.
0.0.6In a class, completion lists the methods of the parent classes that you can override. When you choose one, the editor writes the whole method. Its body calls parent::name(...) with the same parameters.
0.0.6In a doc comment, go to definition, hover, completion, find references and rename work on each @see target, @example path and @throws class. When you move a file or a folder, each @see and @example path to it changes. If a @see heading is not in the file, the quick fix changes it to the most similar heading.
0.0.6The warning W1036 shows a Core\Str::slice that cuts off a prefix or a suffix after Core\Str::startsWith or Core\Str::endsWith tested it. It names Core\Str::afterPrefix or Core\Str::beforeSuffix, which do both in one call. When the cut is the first line inside the if, the editor offers a fix that writes the call for you.
0.0.6Inside the name you pass to Core\Config::set or Core\Config::restore, the editor lists the settings a request may change. The hover on a name says how a request may change that setting.
0.0.6After an edit, the editor checks fewer files. A change inside a method body or a comment checks only the file you edit. A change to a method also checks the subclasses, and for a public method the files that call it.
0.0.6In the VS Code Explorer, a file that declares one attribute shows the letter A. Its tooltip is "This file declares an attribute."
0.0.6Inside #[Name(, the editor shows the fields of the attribute declaration as signature help. Each field shows its doc comment.
0.0.6An attribute that nothing declares has the quick fix Declare the attribute. It writes an attribute declaration in the same file, with a field for each key you wrote.
0.0.6The editor colours the words class, method, property and parameter after on in an attribute declaration. Each field name has the colour of a property name.
0.0.6The outline lists each attribute declaration and its fields. The body of an attribute declaration folds.
0.0.6The editor completes attribute and repeatable at file level and in a class or interface body. It also completes the type of each field in an attribute declaration.
0.0.6Go to definition, find references, highlight and rename work on the fields of an attribute declaration. They also work on each key in a #[Name(key: …)] use.
0.0.6nvs code order moves an attribute declaration in a class to the top of the class, with the enum and type declarations. Order class members in the editor does the same.