davidhalter / jedi-vim

Using the jedi autocompletion library for VIM.
MIT License
5.29k stars 372 forks source link

Name of project's root file. #593

Closed ANtlord closed 8 years ago

ANtlord commented 8 years ago

Hello! I've reinstalled my OS (Arch Linux) and I see, that I can't autocompletion for my local modules from not root file. I've created clear project without any framework or something else. And I can't get completions. I've found on stackoverflow same issue, but it is without response. http://stackoverflow.com/questions/31094490/cant-use-jedi-vim-on-imported-modules

I've upload project here https://github.com/ANtlord/test-jedi. I get completions in this file https://github.com/ANtlord/test-jedi/blob/master/main.py But I can't get copmpletions here https://github.com/ANtlord/test-jedi/blob/master/mymod/submod.py

This is my sys.path. https://gist.github.com/ANtlord/66d3e783911d6b194a60b68846fdcd31 This my vim modules. I have python/dyn and python3/dyn. https://gist.github.com/ANtlord/1c64b3e05414f6a9688b66e78b2f6b0c

I've tried add manually root directory of project. It doesn't affect something.

One more thing. I've tried work on my old Django based project even without running vim under virtualenv and withoud using vim-virtualenv. Only directory .venv is in project. I've tried to remove .venv directoty and autocomplete still works in any file of project. I've almost all... settings.py, static files, templates, all 'applications' except two. So... autocomplete still works until I rename manage.py to main.py (manage.py -> main.py)!

I've rename main.py to manage.py (main.py -> manage.py) and autocomplete works again. I go to project, that I share for this issue. I've renamed main.py to manage.py (main.py -> manage.py) and autocomplete works here too!

Is this bug? How can I help to fix it?

Commit of jedi-vim: 6b7dfe1c1afa9f40df283b2223676ba32f9aa791 Commit ofsubmoduled jedi: 995a6531225ba0b65e1ff863d97e5404d989047b. On master I have a same issue.

davidhalter commented 8 years ago

On master I have a same issue.

So what's your last commit?


If you want to help me debug it, please play around with Jedi and try to check if the django detection is the problem (you could just delete it)?

ANtlord commented 8 years ago

So what's your last commit?

I've tried for both commits of Jedi. But let's choose master. It supports pep484 :)

Ok. I've tried remove checking django detection. Autocomplete doesn't work in both cases. I mean case, when file is main.py and when file is manage.py. I mean this line https://github.com/davidhalter/jedi/blob/master/jedi/evaluate/sys_path.py#L195 It seems, that _check_module doesn't any effect.

I can show what it returns. https://gist.github.com/ANtlord/84610e266ec5d8f9a0f6d280d66aeebb

After django detection and when file is manage.py it also adds path to my project.

Why Jedi doesn't get path of first opened file. Is it possible?

ANtlord commented 8 years ago

Same situation on commit 995a6531225ba0b65e1ff863d97e5404d989047b and on tag v0.9.0

davidhalter commented 8 years ago

I'm still not sure what you actually try to complete. In https://github.com/ANtlord/test-jedi/blob/master/mymod/submod.py you don't get completions, but for what? And where do you complete?

ANtlord commented 8 years ago

My bad.

I mean that I can't get completion of project's modules. In file submod.py I try to get name of project's module mymod2. Take a look. I've typed comment of first line. It is here https://github.com/ANtlord/test-jedi/blob/master/mymod2/

davidhalter commented 8 years ago

Ok. And what is now still an issue?

ANtlord commented 8 years ago

Surely! It seems I need to clarify clearer.

When I try use autocomplete inside file, that is not in root of project, in this case it is file submode.py for complete name of modules of the project, I can't get them. And it happens, as we figure out, because Jedi doesn't add path of project to sys.path inside function sys_path_with_modifications. And can't fix it, because I don't know hot to get path where vim is started (current working directory of vim).

Can you fix addition or can you prompt me how to get cwd of vim in python code?

davidhalter commented 8 years ago

Please give me the code you try to complete on, like import x# <----Completion here. I still don't know where it's actually going wrong.

ANtlord commented 8 years ago

Hello! I've given the link to project above, where I get the issue. In first message. Take a look. https://github.com/ANtlord/test-jedi And the link where I can't get completion https://github.com/ANtlord/test-jedi/blob/master/mymod/submod.py. It should suggest to me word "mymod2", but it doesn't. This is name of another module in my project.

davidhalter commented 8 years ago

Now I see! The library you're working on has to be on sys.path to be completable. This is something that you have to configure yourself. You could use pip install -e . for example (which is what I often do).

ANtlord commented 8 years ago

Now I can't understand. What are the cases I have to configure? pip install -e depends on setup.py, but I don't need it often. Manually edition sys.path by command py import sys; sys.path.append(path_to_my_project) doesn't help me.

Is a wrong way to add CWD of vim to sys.path? I'm sure it worked early. Take a look here https://github.com/davidhalter/jedi/pull/746. You've got CWD already. I don't how I mess it. I've just added the variable curdir and this issue will be solved.

I'm not sure that it's correct because it is library and CWD must be got of editor. I think, that CWD should be passed by editor's plugin.

What do you think about this?

davidhalter commented 8 years ago

I think you should write a setup.py.

ANtlord commented 8 years ago

Ok, as you say, thank you!