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.
Completion and errors
Section titled “Completion and errors”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.
What this recording shows
- Type
em. A list of suggestions opens. It showsemail. - 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.
What this recording shows
- Type
emial. A list of suggestions opens. It shows no suggestions. - Point at the red underline. The error says:
Userhas no public property$emialThe error code isE0405.
nvs check reports the same error:
<?nvsclass 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";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 errorTo read what a code means and how to fix it, run `nvs agent show <code>`.Rename
Section titled “Rename”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.
What this recording shows
- Press F2 and type
addCents. The editor renamesaddin 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.
Move a class to another namespace
Section titled “Move a class to another namespace”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.
Property names in strings
Section titled “Property names in strings”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.
<?nvsfinal 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";changedIf 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.
A rename is checked first
Section titled “A rename is checked first”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.
Delete unused code
Section titled “Delete unused code”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
Section titled “Inline”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:
<?nvsfinal class Order{ public static function price(int $price, int $count): int { var $total = $price * $count; return $total; }}
echo Order::price(4, 3), "\n";12<?nvsfinal class Order{ public static function price(int $price, int $count): int { return $price * $count; }}
echo Order::price(4, 3), "\n";12The 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.
Change the parameters of a method
Section titled “Change the parameters of a method”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.
Move a member to another class
Section titled “Move a member to another class”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.
Extract an interface
Section titled “Extract an interface”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.
Quick fixes and generated code
Section titled “Quick fixes and generated code”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.
What this recording shows
- Press Ctrl+. to show the code actions here. The menu has "assign
$this->namefrom$name" and "Movenameto another class…". Choose "assign$this->namefrom$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.
What this recording shows
- Press Ctrl+. to show the code actions here. The menu has "Override
greetfromGreeter". Choose "OverridegreetfromGreeter", 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.
Attribute declarations
Section titled “Attribute declarations”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.
<?nvsattribute Route on method { path: string, verb?: string }
class Shop{ #[Route(path: '/cart')] public function cart(): string { return 'cart'; }}
echo (new Shop())->cart(), "\n";cartInside #[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.
Links in doc comments
Section titled “Links in doc comments”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.
How often a method is used
Section titled “How often a method is used”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.
What this recording shows
- 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.
Calls to and from a method
Section titled “Calls to and from a method”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.
What this recording shows
- Open the call hierarchy of
Prices::total. It is called byCheckout::isFreeandCheckout::receipt. It callsPrices::baseandPrices::tax.
Grants of a route
Section titled “Grants of a route”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:
What this recording shows
- Point at the code. A card shows its documentation.
Install the extension
Section titled “Install the extension”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.
-
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 -
Open a
.nvsfile. The status bar shows the version ofnvsthat the extension uses.
Install the extension from a file
Section titled “Install the extension from a file”Each release also has the extension as a file. VS Code, VSCodium, Cursor and the other editors can all install that file.
-
Download
nvs-0.0.6.vsixfrom the current release. -
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
Build the extension from source
Section titled “Build the extension from source”You need Node.js and the Novis source code from Install Novis.
-
Build the extension:
Terminal window cd editors/vscodenpm cinpm run packageThis writes
nvs.vsixintoeditors/vscode. -
Install it:
Terminal window code --install-extension nvs.vsixYou can also run Extensions: Install from VSIX… in VS Code.
How the extension finds nvs
Section titled “How the extension finds nvs”The extension does not include nvs. It looks in three places, in this order:
- the path in the setting
nvs.path; nvson yourPATH;- 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.
Settings you may change
Section titled “Settings you may change”| 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.
Which files the editor reads
Section titled “Which files the editor reads”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
.gitignoreor.ignorefile names. This is also true in a folder that is not a git repository. - a folder named
targetorvendor. - 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
publicmethod, property or constant: the files that use it, and the subclasses. - a
protectedmethod, property or constant: the subclasses. - a
privatemethod or constant: the subclasses. Aprivateproperty 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
extendsorimplements: 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 file in a skipped folder
Section titled “A file in a skipped folder”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.
Change a Novis colour
Section titled “Change a Novis colour”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.
Tainted and secret variables
Section titled “Tainted and secret variables”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.
Where a tainted value came from
Section titled “Where a tainted value came from”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, '.
What this recording shows
- Point at the code. A card shows its documentation.
The editor shows the same list for a secret variable.
Debugging
Section titled “Debugging”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 in the editor
Section titled “The debug viewer in the editor”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 = trueunder[debug]innvs.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.
What the recorded requests did
Section titled “What the recorded requests did”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 ago1 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 agoShop\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.
Commands
Section titled “Commands”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.
