odoo-ide / vscode-odoo

Visual Studio Code extension for Odoo
https://marketplace.visualstudio.com/items?itemName=trinhanhngoc.vscode-odoo
46 stars 3 forks source link

Issue detecting odoo libraries #26

Closed ymolinar closed 1 year ago

ymolinar commented 1 year ago

I have installed the module following the steps in the documentation and I can't get it to detect the Odoo libraries. The odoo.addons... if they work correctly, the problem is only with the Odoo base libraries This is my project folder organization: project-folder-organization

This are the issues without-odoo odoo

But if i use odoo.odoo works great. with-odoo odoo

trinhanhngoc commented 1 year ago

Hi @ymolinar. Your Odoo workspace needs to be configured a bit for it to work. Because the odoo source code folder is not the root folder of your workspace (it is currently a sub-folder of the root folder, besides other folders such as addons, bin, build,...), the Python language server cannot resolve imports from odoo without additional configuration. To make it work, you can create a pyrightconfig.json in the root folder of your workspace with something like the following sample:

{
    "extraPaths": ["odoo"]
}

Note: odoo is the relative path to the odoo source code in your workspace.

Also, you should not put the odoo-stubs folder inside the odoo source code folder. You can put odoo-stubs outside your workspace and set the relative path to it in pyrightconfig.json like:

{
    "extraPaths": ["odoo"],
    "stubPath": "../relative/path/to/odoo-stubs"
}

I simulated your workspace structure and here are my results:

image image

You can learn more about import resolution here: https://microsoft.github.io/pyright/#/import-resolution

ymolinar commented 1 year ago

Work's like a charm.