Skip to main content

Language server for Vyper, a pythonic smart contract language

Project description

Vyper LSP Server

Requirements

Vyper LSP requires a minimum vyper version of 0.4.1. For full support, it is also required that the Vyper version installed in your virtual environment is capable of compiling your contract.

Development

Setting up Development Environment

  1. Install uv (Fast Python package installer and resolver)

    # Install with pip
    pip install uv
    
    # Or on macOS with Homebrew
    brew install uv
    
  2. Clone the repository

    git clone https://github.com/vyperlang/vyper-lsp.git
    cd vyper-lsp
    
  3. Install dependencies

    uv pip install -e .
    
  4. Run tests

    uv run pytest
    

Code Quality and Testing

  • Run linting: ruff check .
  • Format code: ruff format .
  • Generate test coverage: coverage run -m pytest && coverage report

Install Vyper-LSP

via pipx

I like pipx because it handles creating an isolated env for executables and putting them on your path.

pipx install git+https://github.com/vyperlang/vyper-lsp.git

via pip

You can install using pip if you manage your environments through some other means:

pip install git+https://github.com/vyperlang/vyper-lsp.git

Verify installation

Check that vyper-lsp is on your path:

In your terminal, run which vyper-lsp. If installation was succesful, you should see the path to your installed executable.

Editor Setup

Emacs

The following emacs lisp snippet will create a Vyper mode derived from Python Mode, and sets up vyper-lsp.

(define-derived-mode vyper-mode python-mode "Vyper" "Major mode for editing Vyper.")

(add-to-list 'auto-mode-alist '("\\.vy\\'" . vyper-mode))

(with-eval-after-load 'lsp-mode
  (add-to-list 'lsp-language-id-configuration
               '(vyper-mode . "vyper"))
  (lsp-register-client
   (make-lsp-client :new-connection
                    (lsp-stdio-connection `(,(executable-find "vyper-lsp")))
                    :activation-fn (lsp-activate-on "vyper")
                    :server-id 'vyper-lsp)))

Neovim

Add the following to your neovim lua config.

It should be at ~/.config/nvim/init.lua

vim.api.nvim_create_autocmd({ "BufEnter" }, {
  pattern = { "*.vy" },
  callback = function()
    vim.lsp.start({
      name = "vyper-lsp",
      cmd = { "vyper-lsp" },
      root_dir = vim.fs.dirname(vim.fs.find({ ".git" }, { upward = true })[1])
    })
  end,
})

vim.api.nvim_create_autocmd({ "BufEnter" }, {
  pattern = { "*.vy" },
  callback = function()
    vim.lsp.start({
      name = "vyper-lsp",
      cmd = { "vyper-lsp" },
      root_dir = vim.fs.dirname(vim.fs.find({ ".git" }, { upward = true })[1])
    })
  end,
})

vim.api.nvim_set_keymap('n', 'gd', '<Cmd>lua vim.lsp.buf.definition()<CR>', { noremap = true, silent = true })
vim.api.nvim_set_keymap('n', 'gD', '<Cmd>lua vim.lsp.buf.declaration()<CR>', { noremap = true, silent = true })
vim.api.nvim_set_keymap('n', 'gr', '<Cmd>lua vim.lsp.buf.references()<CR>', { noremap = true, silent = true })
vim.api.nvim_set_keymap('n', 'gi', '<Cmd>lua vim.lsp.buf.implementation()<CR>', { noremap = true, silent = true })
vim.api.nvim_set_keymap('n', 'K', '<Cmd>lua vim.lsp.buf.hover()<CR>', { noremap = true, silent = true })
vim.api.nvim_set_keymap('n', '<C-k>', '<Cmd>lua vim.lsp.buf.signature_help()<CR>', { noremap = true, silent = true })
vim.api.nvim_set_keymap('n', '[d', '<Cmd>lua vim.lsp.diagnostic.goto_prev()<CR>', { noremap = true, silent = true })
vim.api.nvim_set_keymap('n', ']d', '<Cmd>lua vim.lsp.diagnostic.goto_next()<CR>', { noremap = true, silent = true })

VS Code

See vyper-lsp VS Code extension

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

vyper_lsp-0.1.1.tar.gz (58.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

vyper_lsp-0.1.1-py3-none-any.whl (22.4 kB view details)

Uploaded Python 3

File details

Details for the file vyper_lsp-0.1.1.tar.gz.

File metadata

  • Download URL: vyper_lsp-0.1.1.tar.gz
  • Upload date:
  • Size: 58.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.8

File hashes

Hashes for vyper_lsp-0.1.1.tar.gz
Algorithm Hash digest
SHA256 ddaab8ca66bb5b8e3fb6b1b042964dbcae3c502c3080ef01e26197f054fea867
MD5 c4c4108f95c34f13a4deead5353b352d
BLAKE2b-256 c8a7de07c7fa8aa4da1c5a828e2187fdc34d7fc93f1e7d6592bb74b2de4574e1

See more details on using hashes here.

File details

Details for the file vyper_lsp-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: vyper_lsp-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 22.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.8

File hashes

Hashes for vyper_lsp-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 238110a3b5499992872294bb723d85d63e3f0ed276636d7ab9ccc20f92d7c692
MD5 1cf4db28a9b3335c9c47032b165b75b3
BLAKE2b-256 755481fb4defa496f3aecc7c49eaa8ff149d70149fa3014d98913e0cc06a23d7

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page