Skip to content

The editor extension

The Novis extension for VS Code colours .nvs files. It also shows errors while you type and completes the names of variables and methods. When the mouse pointer is over a method, it shows the documentation of that method. It renames methods and variables, fixes errors and writes code for you. It shows how often a method is used and where a value came from. It gets all of this from nvs lsp, the language server that is part of the nvs program.

Each code example with an editor around it on this page shows the real result that nvs lsp returned for the code in it.

When you type the name of a class, the editor suggests the classes that your program can load. These are the Core classes and the classes in the folders that your program’s autoload lines name. For example, a program that loads only the Shop namespace does not get the classes of the Blog namespace. To use them, add an autoload line for Blog. A file that no program loads gets every class.

In a string that is converted with as property<User>, the editor suggests the names of the public properties of User. Here it suggests email and name. The private property $passwordHash is not in the list.

How it looks in your editorA recording from the Novis editor extension. You cannot type here.
What this recording shows
  1. Type em. A list of suggestions opens. It shows email.
  2. Press Enter to choose email.

A name that User does not have gets a red underline. When the mouse pointer is over it, the editor shows the error.

How it looks in your editorA recording from the Novis editor extension. You cannot type here.
What this recording shows
  1. Type emial. A list of suggestions opens. It shows no suggestions.
  2. Point at the red underline. The error says: User has no public property $emial The error code is E0405.

nvs check reports the same error:

<?nvs
class User
{
public string $name = 'Ada';
public string $email = 'ada@example.com';
}
User $user = new User();
property<User> $key = 'emial' as property<User>;
echo $user->$key, "\n";
Compiler error
error[E0405]: `User` has no public property `$emial`
--> property-key-typo.nvs:9:23
|
9 | property<User> $key = 'emial' as property<User>;
| ^^^^^^^^^^^^^^^^^^^^^^^^^ converted here
= help: a property name written in the code is checked when the program compiles. The public properties of `User` are: `$email`, `$name`
error: aborting due to 1 error
To read what a code means and how to fix it, run `nvs agent show <code>`.

Put the cursor on a name and press F2. Type the new name, and the editor changes the declaration and every place that uses it. Here the method add becomes addCents, and both calls change too.

How it looks in your editorA recording from the Novis editor extension. You cannot type here.
What this recording shows
  1. Press F2 and type addCents. The editor renames add in 3 places in this file.

Rename also changes the name in the other .nvs files of your folder.

When you rename a parameter, the editor also changes its @param line. It also changes each call that passes the parameter by name, such as count: 3.

You can also give a class a new namespace. Press F2 on the class name and type its full new name, such as Shop\Billing\Cart. The editor changes the namespace line of the class. It also changes each use line that names the class. The file moves to the folder where autoload looks for the new name.

You can also move the file. Drag a class file to another folder in the Explorer. The editor then renames the class to the name that its new path gives. For example, Shop/Cart.nvs moved to Shop/Billing/ becomes the class Shop\Billing\Cart.

Some methods get the name of a property as a string: initProperty, onPropertyGet, onPropertySet and beforePropertySet. When one of them compares that name with a string, such as 'total', the string is a use of the property. A rename of $total also changes the string.

<?nvs
final class Cart implements PropertyObserver
{
public int $total = 0;
public bool $changed = false;
public function onPropertyGet(string $name, mixed $value): void
{
}
public function onPropertySet(string $name, mixed $value): void
{
// A rename of `$total` also changes the string 'total' below.
if ($name == 'total') {
$this->changed = true;
}
}
}
var $cart = new Cart();
$cart->total = 25;
echo $cart->changed ? 'changed' : 'unchanged', "\n";
Output
changed

If the class has no property with the compared name, the string gets a warning. So a typo such as 'totl' has a yellow underline while you type.

The editor checks the new code before it changes a file. If the new code would not compile, the editor shows the error and changes nothing. The same check runs for every refactoring below.

A class, method, property or constant that nothing uses is grey. Put the cursor on its name and press Ctrl+. (Cmd+. on macOS). The action Delete unused … deletes it, with its doc comment and its attributes. A route handler, a test and a constructor are never grey, because Novis calls them for you.

nvs code unused lists the same declarations from a terminal. nvs code delete deletes one.

Inline replaces a variable or a method call with its value. Put the cursor on the name and press Ctrl+. to see these actions:

  • Inline variable replaces each use of a variable with its value, and deletes the variable.
  • Inline this call replaces one call with the body of the method. The method stays.
  • Inline method replaces every call with the body of the method, and deletes the method.

Here Inline variable on $total changes the first code to the second:

<?nvs
final class Order
{
public static function price(int $price, int $count): int
{
var $total = $price * $count;
return $total;
}
}
echo Order::price(4, 3), "\n";
Output
12
<?nvs
final class Order
{
public static function price(int $price, int $count): int
{
return $price * $count;
}
}
echo Order::price(4, 3), "\n";
Output
12

The action is not offered when the code would run in another order, or a different number of times. nvs code inline does the same from a terminal.

Put the cursor on a method name and choose Change parameters of … from the Ctrl+. list. An input box shows the current parameter list. Type the new list, such as int $cents, int $count = 1, and press Enter.

A parameter keeps its name, so you can change its type, its default or its place. A new parameter needs a default value, and the calls use that default. A removed parameter is also removed from every call. Each method that overrides the method, or that the method overrides, gets the same list. nvs code signature does the same from a terminal. It can also write a value for a new parameter at every call.

Put the cursor on a method, property or constant and choose Move … to another class…. An input box shows the name of the current class. Type the name of the other class, such as Shop\Order.

A static member or a constant can move to any class. Each use, such as Cart::MAX, then names the new class. A member that is not static can move only to a parent class or a child class. A private member that the old class still uses must be made public first. nvs code move does the same from a terminal.

Put the cursor on a class name and choose Extract an interface from …. An input box shows the class name followed by Contract, such as CartContract. Type the name you want and press Enter.

The editor writes a new file with the interface, in the folder where autoload looks for it. The interface has each public method of the class that is not static, except the constructor. The class then implements the interface. nvs code extract interface does the same from a terminal.

When the cursor is on an error, press Ctrl+. (Cmd+. on macOS) to see the fixes for it. Here the constructor does not give the property $name a value, so $name has an error. The fix adds $this->name = $name; to the constructor.

How it looks in your editorA recording from the Novis editor extension. You cannot type here.
What this recording shows
  1. Press Ctrl+. to show the code actions here. The menu has "assign $this->name from $name" and "Move name to another class…". Choose "assign $this->name from $name", and the editor changes the code.

The same list also has actions that write code. In a class, the editor offers to override each method of the parent class. The new method calls the parent method with parent::. You can then change its body.

How it looks in your editorA recording from the Novis editor extension. You cannot type here.
What this recording shows
  1. Press Ctrl+. to show the code actions here. The menu has "Override greet from Greeter". Choose "Override greet from Greeter", and the editor changes the code.

The completion list can also write an override. In a class, start to type the name of a parent method, such as bu for build. The list shows build with its parameters. When you choose it, the editor writes the whole method. The method has the same parameters as the parent method. Its body calls parent::build(...) with them, so the new method does what the parent method does until you change the body.

Other actions write the methods that an interface needs, and declare a method that you called but did not write yet. They also add a missing use line, sort the use lines, and move code into a new method or variable.

Order class members puts the properties, constants and methods of each class in the file in one fixed order. The editor does not run this action when you save a file. To run it, right-click in the file and choose Source Action. nvs code order writes the same order from a terminal.

The editor helps with an attribute declaration as it helps with a class. It colours the words after on, such as method. Each field name has the colour of a property name.

The outline lists each declaration and its fields. The body of a declaration folds. In the Explorer, a file that declares one attribute shows the letter A.

The editor completes the words attribute and repeatable, and the type of each field. If your editor supports snippets, attribute writes a whole declaration. You then type the name, choose the site and write the fields.

When you use the attribute, you write each field as a key, such as path:. Go to definition, find references and rename work on both. If you rename path below, the key path: in #[Route(path: '/cart')] changes too.

<?nvs
attribute Route on method { path: string, verb?: string }
class Shop
{
#[Route(path: '/cart')]
public function cart(): string
{
return 'cart';
}
}
echo (new Shop())->cart(), "\n";
Output
cart

Inside #[Route(, the editor shows the fields as signature help: Route(path: string, verb?: string). The field you are writing is highlighted. When the cursor is not on a key yet, the editor highlights the first required field that you have not written.

An attribute that nothing declares has an error. The quick fix Declare the attribute writes a declaration in the same file. If you used the attribute on a method, the declaration says on method. Each key you wrote becomes a field. The fix is not offered in a file that autoload loads, because that file may declare only one name.

Order class members and nvs code order move an attribute declaration in a class to the top of the class. It goes next to the enum and type declarations.

In a /// doc comment, the name after @see and the path after @example are links. Ctrl+click on a path to open the file. A @see path with a heading, such as notes/refunds.md#who-can-get-a-refund, opens the Markdown file at that heading. Ctrl+click on @see Invoice::total to go to the method total. The class after @throws is a link to that class.

When the mouse pointer is over a @see method, the editor shows the documentation of that method. Over a @see heading, it shows the text under that heading, up to 20 lines.

After @see, the editor completes the names of classes and methods. When you type / or ., it completes the files of your project. After #, type a letter or press Ctrl+Space to see the headings of the Markdown file.

Find references lists each @see and @throws that names a method or a class. The usage count above the method does not include these lines. When you rename a method or a class, its @see and @throws lines change too. When you move or rename a file or a folder in the Explorer, each @see and @example path to it changes. The heading after # does not change.

The compiler checks that the heading after # is in the file. If it is not, the line has the error E0323. The quick fix changes it to the most similar heading of the file.

Above each class and method, a grey line shows how often it is used. This line is a code lens. Above a method, a second lens counts the routes and the tests that use it.

How it looks in your editorA recording from the Novis editor extension. You cannot type here.
What this recording shows
  1. The editor shows 6 code lenses, short notes above the code: "2 references", "2 references", "used by 1 route, 2 tests (static)" and 3 more.

Here the route GET /cart calls base through the method cart. Both tests use base. The test cartLoads counts because it sends a request to /cart. A click on the lens runs the tests it counts.

(static) means that the editor counted the calls in your code. After you run the tests with coverage in VS Code, the count comes from that run, and (static) is not shown. The setting nvs.codeLens.enable turns the lenses off.

Right-click a method and choose Show Call Hierarchy. The editor lists the methods that call it, and the methods that it calls. Here total is called by receipt and isFree. It calls base and tax.

How it looks in your editorA recording from the Novis editor extension. You cannot type here.
What this recording shows
  1. Open the call hierarchy of Prices::total. It is called by Checkout::isFree and Checkout::receipt. It calls Prices::base and Prices::tax.

When the mouse pointer is over the method of a route, the editor shows the grants of the program. A grant says which files, hosts and processes the program may use. The grants come from the nvs.toml next to the file. Every route of a program has the same grants.

This nvs.toml allows connections to api.example.com:

[capabilities.net]
connect = ["api.example.com"]

The other grants have their default values:

How it looks in your editorA recording from the Novis editor extension. You cannot type here.
What this recording shows
  1. Point at the code. A card shows its documentation.

The extension is in the VS Code Marketplace. Its id is novis-lang.nvs. VSCodium, Cursor and some other editors install extensions from Open VSX. The extension is there too, with the same id.

  1. In VS Code, open the Extensions view and search for Novis. Install Novis-Lang. You can also install it from a terminal:

    Terminal window
    code --install-extension novis-lang.nvs
  2. Open a .nvs file. The status bar shows the version of nvs that the extension uses.

Each release also has the extension as a file. VS Code, VSCodium, Cursor and the other editors can all install that file.

  1. Download nvs-0.0.6.vsix from the current release.

  2. Install it. In the editor, open the command palette and run Extensions: Install from VSIX…. Then choose the file. You can also install it from a terminal:

    Terminal window
    code --install-extension nvs-0.0.6.vsix

You need Node.js and the Novis source code from Install Novis.

  1. Build the extension:

    Terminal window
    cd editors/vscode
    npm ci
    npm run package

    This writes nvs.vsix into editors/vscode.

  2. Install it:

    Terminal window
    code --install-extension nvs.vsix

    You can also run Extensions: Install from VSIX… in VS Code.

The extension does not include nvs. It looks in three places, in this order:

  1. the path in the setting nvs.path;
  2. nvs on your PATH;
  3. a copy that the command Novis: Download nvs installed.

The first two numbers of the extension’s version must be the same as those of nvs. For example, extension 0.4.2 works with nvs 0.4.0, and does not work with nvs 0.5.0.

Setting Default What it does
nvs.path "" The full path to the nvs program. Empty means: find nvs on the PATH.
nvs.lsp.enable true Starts the language server. With false, you get colours and nothing else.
nvs.check.scope "workspace" Which files are checked: workspace for every file in the folder, or open for the open files.
nvs.secrets.redact true Hides values of a secret type, such as a password.
nvs.taint.mark "off" Shows a sign next to tainted values, which come from outside the program. Use declaration or sink to turn it on.
nvs.codeLens.enable true Shows the code lenses: how often each declaration is used, and what the recorded requests did.
nvs.inlayHints.parameterNames true Shows the parameter name before a literal argument. With false, only the type hints stay.
nvs.debugViewer.openIn "editor" Where the Open Debug Viewer button opens the debug viewer: editor for a panel of the editor, or browser for your web browser.

A change to nvs.path or nvs.lsp.enable restarts the server. After a change to another setting, run Novis: Restart Language Server.

The editor reads every .nvs file in the folder you opened and in its subfolders. It skips these files and folders:

  • a file or folder that a .gitignore or .ignore file names. This is also true in a folder that is not a git repository.
  • a folder named target or vendor.
  • a folder whose name starts with a dot, such as .cache.

Novis does not read .git/info/exclude or your global git ignore file. It also does not read an ignore file above the folder you opened. These files are different on each computer. Because Novis does not read them, every computer finds the same files.

nvs check, nvs fmt and nvs code skip the same files. The editor and nvs code also share one index of the project. When the editor has indexed a project, nvs code is faster.

When you edit a file, the editor checks that file again and updates its errors and warnings. A change inside a method body or a comment checks only the file you edit. A change to a declaration also checks other files:

  • a public method, property or constant: the files that use it, and the subclasses.
  • a protected method, property or constant: the subclasses.
  • a private method or constant: the subclasses. A private property also checks the files that decode JSON or database rows into the class.
  • a new method or property: the files that tried to use that name and did not find it, and the subclasses.
  • the class line, such as extends or implements: every file that uses the class.

No other file is checked again.

The same is true when a file changes on disk, for example after git checkout. The server watches every .nvs file of the project and checks the changed files in the same way. When you start the editor again on a project that did not change, the server checks nothing again.

When you type while the server works, the server stops that work and checks your new text. Find references and rename check only the files that use the name under the cursor.

A class file usually has no autoload lines. The editor searches for the program that loads it, and uses the autoload lines of that program. When you open a file in a skipped folder, the editor also searches that folder. nvs check does the same for the file you check.

For example, .gitignore names the folder addons, and the program addons/Shop/public/index.nvs loads the classes in addons/Shop/src. When you open addons/Shop/src/Cart.nvs, the editor finds that program.

The other files in a skipped folder are still skipped. For example, rename does not change them. To read a folder like every other folder, create a file named .ignore next to .gitignore. Add the folder with a ! at the start of the line:

!/addons/

When .ignore and .gitignore disagree about a file, the editor uses the line in .ignore. Git does not read .ignore, so git still ignores the folder. After you create .ignore, run Novis: Restart Language Server.

The VS Code setting editor.tokenColorCustomizations changes the colour of a token. You can also change a colour for one theme only.

This setting changes the colour of /// doc comments in the theme Novis Dark:

"editor.tokenColorCustomizations": {
"[Novis Dark]": {
"textMateRules": [
{ "scope": "comment.line.documentation", "settings": { "foreground": "#7A9E86" } }
]
}
}

The settings editor.semanticTokenColorCustomizations and workbench.colorCustomizations work the same way.

The language server tells VS Code which variables are tainted and which are secret. A tainted value comes from outside the program, such as a request. This works at every place where you use the variable.

Your colour theme decides how these variables look. In the themes that come with VS Code, a tainted variable is underlined and a secret variable is in italic. Some other themes show no difference.

To choose the style yourself, add this to your settings.json:

"editor.semanticTokenColorCustomizations": {
"enabled": true,
"rules": {
"*.tainted": { "underline": true },
"*.secret": { "italic": true }
}
}

"enabled": true is needed for a theme that does not use the language server’s colours.

When the mouse pointer is over a tainted variable, the editor shows where its value came from. Each step has its line number. Here the value comes from the command-line arguments. Line 4 adds it to the text 'Hello, '.

How it looks in your editorA recording from the Novis editor extension. You cannot type here.
What this recording shows
  1. Point at the code. A card shows its documentation.

The editor shows the same list for a secret variable.

The extension adds a debugger of type nvs to VS Code. While a program is stopped, the Novis Tasks view in Run and Debug shows each task under the task that started it. Debugging in VS Code explains how to use it.

The debug viewer shows the requests that nvs debug recorded. The extension can open it in a panel of the editor.

Open a .nvs file, a .nvst file or nvs.toml. Then click the Open Debug Viewer button in the title bar of the editor. The command palette has the same command: Novis: Open Debug Viewer. The command Novis: Open Debug Viewer in Browser opens the viewer in your web browser.

The setting nvs.debugViewer.openIn chooses what the button does. With editor, the default, it opens the panel. With browser, it opens your web browser. With editor, a second click shows the panel that is already open. The editor does not open a second one.

When nvs debug is not running, the editor shows a message with the button Start nvs debug. This button runs nvs debug as a task. The panel opens when the viewer has started. If it does not start, the terminal of the task shows why.

When recording is off, the editor shows this message:

Novis: requests are not recorded. To record them, set store = true under [debug] in nvs.toml.

Click Open nvs.toml to open the file and add the line.

In a remote window, such as a WSL or SSH window, VS Code forwards the viewer’s port to your computer. The extension opens that forwarded address.

In the panel, click a file:line to open that file in the editor, at that line. The file opens only when it is inside one of your workspace folders. For any other file, the editor shows a warning.

Three more code lenses show what the recorded requests did in your code. These lenses read the requests that nvs debug recorded in the data folder. When no request is recorded, they are not shown. The setting nvs.codeLens.enable turns them off too.

A click on one of these lenses opens the debug viewer at the matching page.

Above a #[Core\Route] handler, the lens shows how many requests the route had and their median duration (p50): half of the requests were faster. Some requests may end with a status of 500 or more. Then the lens also shows the newest of these statuses and how long ago it was:

  • 3 requests, p50 2.0 ms, last 503 2 min ago
  • 1 request, p50 9.0 ms

A click on this lens opens the list of requests, filtered to that route.

Above a Core\Debug::dump call, the lens shows the newest value dumped on that line. The value is on one line, and a secret value is [redacted]:

  • Dumped: [1, 2, 3]
  • Dumped: Shop\Item {card: [redacted], name: "Lamp"}

A click on this lens opens the request that dumped the value, at that dump.

Above a throw, the lens shows the class of the exception, how many times it was thrown, and when it was thrown last:

  • Shop\OutOfStock thrown 3 times, last 3 h ago
  • Shop\Closed thrown once, last just now

A click on this lens opens the Errors page of the viewer at this exception class and this line.

A dump lens and a throw lens use the line number that was recorded. After you edit the file, that line may have other code. So these two lenses are shown only when both are true:

  • The file has no unsaved changes.
  • The request was recorded after you last saved the file.

A route lens finds its route by the method and the path, such as GET /notes/{id}. It does not use a line number, so it is also shown after an edit.

Open the command palette and type Novis. These are the commands you use most:

Command What it does
Novis: Run File Checks, compiles and runs the open file.
Novis: Run Tests Runs the #[Test] methods in the open file.
Novis: Restart Language Server Stops the server and starts it again.
Novis: Reveal Secret Shows the hidden value under the cursor.
Novis: Hide Secrets Hides every value you revealed again.
Novis: Download nvs Downloads the newest nvs that works with this extension.
Novis: Open Debug Viewer Opens the debug viewer where nvs.debugViewer.openIn says.
Novis: Open Debug Viewer in Browser Opens the debug viewer in your web browser.

Novis: Download nvs checks the download against the release’s checksum file before it uses it. Nothing is downloaded unless you run this command.

Next: Hello, World!, or A Tour of Novis.