Tecnativa / doodba-copier-template

A Copier template for Doodba projects
Boost Software License 1.0
84 stars 114 forks source link

Visual Studio Code Autocompletion for Addon Repositories other than odoo source #233

Open michaelkarrer81 opened 3 years ago

michaelkarrer81 commented 3 years ago

Lately autocompletion was added for visual studio code by switching the language server to jedi and adding python.autoComplete.extraPaths.

This will enable autocompletion for all addons in the odoo source because they are under odoo/addons and odoo/odoo/addons. So import from odoo.addons.website_sale ... will work because the path matches .../odoo/addons.

But this will not work for addons of other e.g. OCA addon repositories because the addons will be e.g. in odoo/custom/src/web/[addon_name] so the import path no longer matches odoo/addons.

Solutions:

One easy solution might be to clone all the external addon repos like this:

Another solution would be to create the final odoo structure by symlinking like in the auto folder. But i am not sure how well vs-code works with symlinks - pycharm has it's problems with it... Therefore i would prefer the first solution.

joao-p-marques commented 3 years ago

IMHO changing the way we clone repos isn't a very good option because we might be introducing some conflicts with the way we handle repos, addons, and the integration with git-aggregator. It could become a very complex change.

Another solution, however, could be adding those paths dynamically to the settings with the invoke task as we do with the debugger path mappings.

WDYT @Yajo?

michaelkarrer81 commented 3 years ago

Another solution, however, could be adding those paths dynamically to the settings with the invoke task as we do with the debugger path mappings.

Could you give an example?

The only settings i found that would influence code completion was in tasks.py > write_code_workspace_file()

cw_config["settings"].update(
        {
            "python.autoComplete.extraPaths": [f"{str(SRC_PATH)}/odoo"],
            "python.languageServer": "Jedi",

I guess adding e.g. odoo/custom/src/web to extraPaths would not help because still the structure is not odoo/addons/[addon] but web/[addon].

But i may just don't know the vs-code python settings well enough to get your point?

yajo commented 3 years ago

I agree with you @joao-p-marques.

I guess adding e.g. odoo/custom/src/web to extraPaths would not help because still the structure is not odoo/addons/[addon] but web/[addon].

I don't think that's enough.

For python (and I guess vscode) to interpret a folder as a module, usually the folder needs to have a __init__.py file inside (even if empty).

If it were so simple, one solution (at least for OCA addons) would be to include the setup folder inside OCA repos. This random example shows it has the same structure you're asking for, @michaelkarrer81.

If this worked, that'd mean the only ones left out of luck would be private and non-OCA repos. But both cases would probably be easy to fix by leveraging the toolset OCA uses for generating those setup folders.

yajo commented 3 years ago

imagen

pedrobaeza commented 3 years ago

For me this auto-completion doesn't bring too much value compared with the setup process, as the real killer feature will be to interpret the ORM essence (type env["res.partner"]. and bring you the list of fields for example). Odoo mentioned in last OXP AMA that they want to put a VSCode plugin for getting this.

yajo commented 3 years ago

this auto-completion doesn't bring too much value [...] the real killer feature will be to interpret the ORM essence (type env["res.partner"]. and bring you the list of fields for example).

Yes, it'd help mostly when doing controllers, but models would remain mostly the same.

compared with the setup process

We don't really need to add the setup folder, but for cases when it already exists, we can benefit from it.

Odoo mentioned in last OXP AMA that they want to put a VSCode plugin for getting this.

I don't trust Odoo's promises anymore. Anyways, let's leave this issue open in case somebody from the community wants to add support. It wouldn't be so hard nor harm anybody.