Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
michaelkarrer81 opened this issue Mar 16, 2021 · 8 comments
Labels
enhancement New feature or request

Comments

@michaelkarrer81
Copy link

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:

  • create two new folders for an external addon repo e.g: odoo/custom/src/web/odoo
  • clone the addon repo to a folder called addons inside this new folderstructure: odoo/custom/src/web/odoo/addons
  • Also in the private addons section we should add the two folders ...custom/src/private/odoo/addons/[private addons here]

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
Copy link
Contributor

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
Copy link
Author

michaelkarrer81 commented Mar 16, 2021

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
Copy link
Contributor

yajo commented Mar 17, 2021

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
Copy link
Contributor

yajo commented Mar 17, 2021

imagen

@yajo yajo added the enhancement New feature or request label Mar 17, 2021
@yajo yajo added this to the v2.8.0 milestone Mar 17, 2021
@pedrobaeza
Copy link
Member

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
Copy link
Contributor

yajo commented Mar 17, 2021

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.

@yajo yajo removed this from the v2.8.0 milestone Mar 17, 2021
@pleirb
Copy link

pleirb commented Aug 30, 2024

ow are you all?
Does anyone think that now that more time has passed, this code autocompletion issue is resolved?
For people who are new to Odoo programming and long to one day make a meaningful contribution, we are very grateful for this development environment that is carefully designed for comfortable working. And we were wondering if it would also be possible to include an autocomplete extension. A while ago I published in #460 about some warnings that appear when opening a vscode project that I would like to know if it is something related to what is being raised here. Thank you !

@pleirb
Copy link

pleirb commented Aug 30, 2024

It also happens that the project suggests the installation of this extension that is obsolete:
imagen

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

5 participants