volar

URL: https://github.com/vuejs/language-tools#readme

plugins.lsp.servers.volar.enable

Whether to enable https://github.com/johnsoncodehk/volar/tree/20d713b/packages/vue-language-server

Volar language server for Vue

Volar can be installed via npm:

npm install -g @vue/language-server

Volar by default supports Vue 3 projects. Vue 2 projects need additional configuration.

TypeScript support As of release 2.0.0, Volar no longer wraps around ts_ls. For typescript support, ts_ls needs to be configured with the @vue/typescript-plugin plugin.

Take Over Mode

Volar (prior to 2.0.0), can serve as a language server for both Vue and TypeScript via Take Over Mode.

To enable Take Over Mode, override the default filetypes in setup{} as follows:

require'lspconfig'.volar.setup{
  filetypes = {'typescript', 'javascript', 'javascriptreact', 'typescriptreact', 'vue', 'json'}
}

Overriding the default TypeScript Server used by Volar

The default config looks for TS in the local node_modules. This can lead to issues e.g. when working on a monorepo. The alternatives are:

  • use a global TypeScript Server installation
require'lspconfig'.volar.setup{
  init_options = {
    typescript = {
      tsdk = '/path/to/.npm/lib/node_modules/typescript/lib'
      -- Alternative location if installed as root:
      -- tsdk = '/usr/local/lib/node_modules/typescript/lib'
    }
  }
}
  • use a local server and fall back to a global TypeScript Server installation
local util = require 'lspconfig.util'
local function get_typescript_server_path(root_dir)

  local global_ts = '/home/[yourusernamehere]/.npm/lib/node_modules/typescript/lib'
  -- Alternative location if installed as root:
  -- local global_ts = '/usr/local/lib/node_modules/typescript/lib'
  local found_ts = ''
  local function check_dir(path)
    found_ts =  util.path.join(path, 'node_modules', 'typescript', 'lib')
    if util.path.exists(found_ts) then
      return path
    end
  end
  if util.search_ancestors(root_dir, check_dir) then
    return found_ts
  else
    return global_ts
  end
end

require'lspconfig'.volar.setup{
  on_new_config = function(new_config, new_root_dir)
    new_config.init_options.typescript.tsdk = get_typescript_server_path(new_root_dir)
  end,
}

.

Type: boolean

Default: false

Example: true

Declared by:

plugins.lsp.servers.volar.package

The volar package to use.

Type: null or package

Default: pkgs.vue-language-server

Declared by:

plugins.lsp.servers.volar.autostart

Controls if the FileType autocommand that launches a language server is created. If false, allows for deferring language servers until manually launched with :LspStart (|lspconfig-commands|).

Type: null or boolean or raw lua code

Default: null

Plugin default: true

Declared by:

plugins.lsp.servers.volar.cmd

A list where each entry corresponds to the blankspace delimited part of the command that launches the server.

The first entry is the binary used to run the language server. Additional entries are passed as arguments.

Type: null or (list of string)

Default: null

Declared by:

plugins.lsp.servers.volar.extraOptions

Extra options for the volar language server.

Type: attribute set of anything

Default: { }

Declared by:

plugins.lsp.servers.volar.filetypes

Set of filetypes for which to attempt to resolve {root_dir}. May be empty, or server may specify a default value.

Type: null or (list of string)

Default: null

Declared by:

plugins.lsp.servers.volar.rootDir

A function (or function handle) which returns the root of the project used to determine if lspconfig should launch a new language server, or attach a previously launched server when you open a new buffer matching the filetype of the server.

Type: null or lua function string

Default: null

Plugin default: "nil"

Declared by:

plugins.lsp.servers.volar.settings

The settings for this LSP.

Type: attribute set of anything

Default: { }

Example:

{
  callback = {
    __raw = ''
      function()
        print('nixvim')
      end
    '';
  };
  foo_bar = 42;
  hostname = "localhost:8080";
}

Declared by:

plugins.lsp.servers.volar.tslsIntegration

Enable integration with TypeScript language server.

Type: boolean

Default: true

Example: false

Declared by: