Skip to content
vlangPublic

About

V language server

Topics

Resources

Stars

374 stars

Watchers

26 watching

Forks

Latest commit

 

History

199 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

VLS - V Language Server

Build with: v .

Or let the compiler install it for you: v ls --install (see v help ls for update and source-build options).

Check the installed version with vls --version or vls version. Both print VLS 0.0.3 and exit without starting the server. LSP initialize reports the same version in serverInfo.

Place the vls binary in your PATH. For example, on Linux you can place it in /usr/local/bin. On Windows, you can place it in a directory that is included in your PATH environment variable.

Otherwise, you can set the path to the vls binary in your editor's settings.

Installing VLS for your editor

Other editor?

Sublime Text

  1. Build VLS with v . and place the resulting vls binary in your PATH.
  2. In Sublime Text, open Package Control: Install Package from the Command Palette and install both V (for the source.v syntax) and LSP.
  3. Open Preferences > Package Settings > LSP > Server Configurations and add this to Packages/User/LanguageServers.sublime-settings:
{
  "vls": {
    "enabled": true,
    "command": ["vls"],
    "selector": "source.v"
  }
}

If vls is not in Sublime Text's PATH, replace it with the absolute path to the binary. If the V compiler is not in that PATH either, use absolute paths and add VLS_V_COMMAND:

{
  "vls": {
    "enabled": true,
    "command": ["/absolute/path/to/vls"],
    "selector": "source.v",
    "env": {
      "VLS_V_COMMAND": "/absolute/path/to/v"
    }
  }
}

Open a folder containing a V project, then open a .v file. The Sublime status bar should show that VLS has started. Use Tools > Developer > Show Scope Name to confirm that the file's base scope is source.v if the server does not start.

VS Code

Install the V extension from the Visual Studio Marketplace. Its source and build instructions are in vlang/vscode-vlang.

Build VLS with v . and make the vls binary available in VS Code's PATH, or set v.vls.command to its path. Set v.executablePath if the V compiler is not on that PATH.

The extension includes V: Build, V: Run, and V: Test in the Command Palette and in Tasks: Run Task. Runnable CodeLens actions show their output in a task terminal. Test tasks also visualize line coverage; set v.vls.coverage.enabled to false to turn that off.

Code behind a compile-time flag

V compiles the code inside $if flag ? { ... } only when the program is built with -d flag. VLS runs the compiler without defines, so that code used to get no errors, and hover and go-to-definition found little or nothing in it. It now checks that code when the flag is given.

Set vls.defines in the editor's settings for VLS, naming the flag the code uses:

"vls.defines": ["-d", "flag"]

The joined spelling, ["-dflag"], is accepted too. To keep the flag with the project rather than in the editor, put a vls.json in the folder that holds the nearest v.mod:

{ "defines": ["-d", "flag"] }

A vls.json may also set inlayHints, diagnostics and coverageDirectory. The settings the editor sends win over the project's file, and the file over VLS_DEFINES in the environment, which also works for an editor with no settings of its own. The nearest vls.json is read when a file of its project is opened, so its switches apply before the first check rather than after it. The keys the file accepts are listed in vls.schema.json. The defines reach the checks only: v fmt, hover, go-to-definition and completion run without them. The code inside $if !flag ? { ... } is then the one left unchecked.

Generating tests for untested functions

A coverage recording is what tells VLS which functions a test run never entered. Record one, then point the project at it:

v -no-skip-unused -coverage vcov/ test ./
{ "coverageDirectory": "vcov" }

coverageDirectory may also be sent by the editor as vls.coverageDirectory, which wins over the file. With it set, a .v file whose functions were never entered offers a code action per function: Generate test for 'foo'. The action runs v cover --write-tests, which appends one test_foo() beside the source with a zero-value call and a // TODO: line. It is a starting point, not a test: the generator cannot know what the function should return.

-no-skip-unused belongs with the recording. Without it a function nothing calls is dropped from the build, so its coverage cannot be reported at all.

Features

Instant errors

image

Go to definition

gddemo.mov

Autocomplete for module functions

image

Information about function parameters

image

Autocomplete for struct fields and methods

image

Zed

NOTE: the Zed editor lacks first-party support for the V programming language.

  1. Build VLS with v . and place the resulting vls binary in your PATH.
  2. Open Zed > Open Settings File and add this to your settings file:
{
  "languages": {
    "V": {
      "formatter": {
        "external": {
          "command": "vls",
          "arguments": ["-"]
        }
      }
    }
  }
}

or alternatively if the vls binary is NOT in your PATH:

{
  "languages": {
    "V": {
      "formatter": {
        "external": {
          "command": "/absolute/path/to/vls",
          "arguments": ["-"]
        }
      }
    }
  }
}

About

V language server

Topics

Resources

Stars

374 stars

Watchers

26 watching

Forks

Releases

Packages

Contributors

Languages