#lsp #language-server #python #javascript #xml

bin+lib odoo-lsp

Language server for Odoo Python/JS/XML

7 releases

0.3.0 Dec 18, 2023
0.2.2 Dec 2, 2023
0.2.1 Nov 7, 2023
0.2.0 Oct 26, 2023
0.1.1 Aug 31, 2023

#571 in Development tools

Download history 2/week @ 2023-12-02 8/week @ 2023-12-16 2/week @ 2024-02-10 66/week @ 2024-02-17 52/week @ 2024-02-24

120 downloads per month

MIT license

215KB
6.5K SLoC

odoo-lsp

nightly

Features

Completion, definition and references for models, XML IDs and model fields

Works for records, templates, env.ref() and other structures.

model demo

Browse models and XML records as workspace symbols

symbols demo

For more features check out the wiki.

Install

The VSCode extension handles downloading the latest releases automatically; other editors need odoo-lsp on the path. Nightly binaries are also available for major platforms, please check Releases for the latest downloads.

# One-line
curl -L https://github.com/Desdaemon/odoo-lsp/releases/download/nightly/odoo-lsp-x86_64-unknown-linux-musl.tgz | tar -xzvf -

# Apple Silicon
curl -L https://github.com/Desdaemon/odoo-lsp/releases/download/nightly/odoo-lsp-aarch64-apple-darwin.tgz | tar -xzvf -

# With cargo-binstall
cargo binstall odoo-lsp

# Install from source
cargo install odoo-lsp

Setup

For usage instructions please check the wiki (work in progress).

VSCode

odoo-lsp is available from the Visual Studio Marketplace and the Open VSX Registry. Alternatively, you can grab the latest nightly builds from Releases.

Helix

See .helix/languages.toml

  1. Ensure that you have odoo-lsp on your path
  2. Determine your Helix runtime folder, e.g. ~/.config/helix/ on Linux
  3. Modify languages.toml in your Helix runtime folder (create one if none exists) to include these lines:
[language-server]
# Update the path to match your setup
odoo-lsp.command = "odoo-lsp"

[[language]]
name = "xml"
language-servers = ["odoo-lsp"]
roots = [".odoo_lsp", ".odoo_lsp.json"]

[[language]]
name = "python"
roots = [
   ".odoo_lsp", ".odoo_lsp.json",
   # add the default roots here
]
# Order is important here
language-servers = [
   "odoo-lsp",
   # add the default language servers here
   "pylsp",
   # and any you need
]
  1. Alternatively, modify $ROOT/.helix/languages.toml where $ROOT is your Odoo modules root to include the above lines.

Neovim via lsp-zero.nvim

  1. Ensure that you have odoo-lsp on your path
  2. Configure your Neovim (Lua) configuration file e.g. at ~/.config/nvim/init.lua to use lsp-zero.nvim, adding odoo-lsp as a new server using lsp.new_server before calling lsp.setup():
-- lsp-zero stanza
local lsp = require('lsp-zero').preset({})
lsp.on_attach(function(client, bufnr)
  lsp.default_keymaps({buffer = bufnr})
end)

-- define our custom language server here
lsp.new_server({
  name = 'odoo-lsp',
  cmd = {'odoo-lsp'},
  filetypes = {'javascript', 'xml', 'python'},
  root_dir = function()
    return lsp.dir.find_first({'.odoo_lsp', '.odoo_lsp.json', '.git'})
  end,
})

-- LSP setup done
lsp.setup()

A complete example can be found in examples/init.lua.

Troubleshooting

Run your editor with the RUST_LOG environment variable like below, e.g. for VSCode:

RUST_LOG=odoo_lsp=debug code ..

This will enable debug logs for the LSP server itself, which can be seen via your editor's logging mechanism. Please include these logs when opening an issue.

Development

  1. pnpm i
  2. cargo build
  3. In VSCode, press F5 or change to the Debug panel and click Launch Client

Note If encountered errors like Cannot find module '/xxx/xxx/dist/extension.js' please try run command tsc -b manually, you could refer https://github.com/IWANABETHATGUY/tower-lsp-boilerplate/issues/6 for more details

Dependencies

~26–37MB
~723K SLoC