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

Modules not resolved #7

Closed adsummertech closed 1 year ago

adsummertech commented 1 year ago

Hello.

I've installed the extension and disabled the Python Language Server as per the readme, however the editor is still not resolving any of the modules.

image

adsummertech commented 1 year ago

Copying the odoo folder from the source to my python Libs directory seemed to help, however Pyright was still struggling to find various definitions.

Switching back to Pylance with the odoo source in the Libs folder seems to offer the best support.

trinhanhngoc commented 1 year ago

Hi @adsummertech , the Odoo extension supports resolving imports like from odoo.addons.xxx where addon xxx can come from different addons paths attached to your VSCode workspace. Other imports like from odoo import are resolved in the same way as by the default Python Language Server. Please make sure that you are structuring your Odoo workspace correctly in VSCode. You can use the following sample structure:

image

We have a multi-root workspace with three folders (three projects):

We also need to setup project dependencies for this workspace by pyrightconfig.json (same for Pylance) (https://github.com/microsoft/pyright/blob/main/docs/configuration.md).

adsummertech commented 1 year ago

I'm not running odoo locally, just working on modules and deploying elsewhere, so that set up doesn't really work for me. I found that copying odoo to the python Libs dir worked best, but will look at a global extraPaths value.

However I'm still getting completion and reference errors when using Pyright. Can't find model.Model and fields.Many2many etc etc etc

image

image

This doesn't happen if I use Pylance as the language server

trinhanhngoc commented 1 year ago

As I know, there is no difference in import resolution mechanism between Pylance and Pyright. I see there is duplicated tooltip information in your screenshots. Did you also install the Pyright extension (https://marketplace.visualstudio.com/items?itemName=ms-pyright.pyright) beside Pylance?

adsummertech commented 1 year ago

I had Pylance disabled and Pyright enabled. Language server was set to none.

trinhanhngoc commented 1 year ago

Can you provide details on how you are structuring your project so I can reproduce the problem on my machine?

adsummertech commented 1 year ago

It's just a directory of modules, each with a__init__.py and __manifest__.py - not an entire project.

I really just wanted code completion and to be able to jump to the source, not sure I need the features of this extension so I think I will stick to pylance with odoo in my lib dir.