Skip to content
This repository was archived by the owner on Apr 14, 2022. It is now read-only.

No completions for python-docx #178

Open
huguesv opened this issue Oct 2, 2018 · 9 comments
Open

No completions for python-docx #178

huguesv opened this issue Oct 2, 2018 · 9 comments

Comments

@huguesv
Copy link
Contributor

huguesv commented Oct 2, 2018

pip install python-docx
import docx

doc = docx.Document()
doc.

From microsoft/PTVS#4752

@supriyanta
Copy link

I want to work on this, please help, beginner here

@AlexanderSher
Copy link
Contributor

Test to repro the issue:

        [TestMethod, Priority(0)]
        public async Task PythonDocxCompletion() {
            var text = @"import docx

doc = docx.Document()
doc.";
            using (var server = await new Server().InitializeAsync(PythonVersions.LatestAvailable)) {
                var uri = await server.OpenDefaultDocumentAndGetUriAsync(text);
                var completion = await server.SendCompletion(uri, 3, 4);
                completion.Should().HaveItem("settings");
            }
        }

@MikhailArkhipov
Copy link

@supriyanta - this may not be an easy thing :-). basically you want to

  • check what is docx library - is it in python or C++?
  • if it is in C++, then what is generated in cache (those oddly named folders next to LS binary) by the scraping script in Python
  • if it is in Python, how code is processed in Ast-based analysis (i.e. lightweight pass).

You can start with completion repro and see what types are attached to docx (i.e. what GetMembers see). Then perhaps set breakpoint where variable type is assigned or at the AssignmentStatement in AST walk.

@supriyanta
Copy link

Seems hard for me :(

@MikhailArkhipov
Copy link

MikhailArkhipov commented Oct 5, 2018

The library is in Python. Go to definition works correctly. When file is opened, full analysis knows that open returns OpcPackage

image

Hover, in the Document class OpcPackage.open(). fails, although open and its signature are known

image

Most probably AST analysis fails somewhere along the path

@supriyanta
Copy link

Okay, thanks for your help!

@supriyanta
Copy link

Where is this file located?

@MikhailArkhipov
Copy link

MikhailArkhipov commented Oct 19, 2018

Although while debugging I found few issues related to property resolution, this is, unfortunately, by design. Jedi does not show anything either. The reason is that there is no type.

Document:

def Document(docx=None):
    document_part = Package.open('s').main_document_part
    return document_part.document

OpcPackage:

    @property
    def main_document_part(self):
        return self.part_related_by(RT.OFFICE_DOCUMENT)

    @classmethod
    def open(cls, pkg_file):
        package = cls()
        return package

    def part_related_by(self, reltype):
        return self.rels.part_with_reltype(reltype)

    @lazyproperty
    def rels(self):
        return Relationships(PACKAGE_URI.baseURI)

Relationships:

class Relationships(dict):
    def _get_rel_of_type(self, reltype):
        matching = [rel for rel in self.values() if rel.reltype == reltype]
         ...
        return matching[0]

but since it is based on plain dict analyzer can't determine type of self.values.

@MikhailArkhipov
Copy link

Actually, we may try and add type based on __init__ and super.
Related #207

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants