Sublime text 3 #18

Closed
wants to merge 7 commits into
from

6 participants

@Astrac

This PR contains updates to have SublimeJEDI working on Sublime 3. Don't merge with master please as it will break Sublime Text 2 at this moment, I'm working on making it backward compatible.

There are lots of changes in jedi since I updated the library, probably it could be better find a way to link to their code without keeping it under versioning (maybe as a submodule).

I also changed sublime_jedy.py to cope with the subtle v3 api changes and python 3.3 and I had to add some fix in imports.py in jedi which I'm going to discuss with jedi's maintainers; most notably I had to migrate it from the imp module to the importlib one since imp was showing different behaviors in python 2.6 and in python 3.3, giving different information for the "posix" module (and I suspect for similar cases in other OSs).

Can you please create a branch for this so that other people could contribute?

Thank you!

@nfaggian

Wow - fantastic effort! I will try this out now!

@davidhalter

There are lots of changes

Just wait until dev is being merged into master :-)

485 commits and 55 files changed, 5832 insertions(+), 3651 deletions(-)

I would really recommend you guys to use Jedi as a submodule :-)

@srusskih
Owner

I think this should be pushed to https://github.com/davidhalter/jedi

@srusskih
Owner

Looks like Sublime Package Control does not support git submodules, yet. wbond/package_control#126

@Astrac

@davidhalter I didn't change all that things in jedi, I just updated to the latest master. There has been only one thing I had to change in imports.py that wasn't handling correctly the posix module. I suspect is something about python 3.3 (the version used by Sublime); this is the difference between python 2.7 and python 3.3:

Python 2.7:
>>> imp.find_module("posix")
(None, 'posix', ('', '', 6))

Python 3.3:
>>> imp.find_module("posix")
(None, None, ('', '', 6))

I fixed it using importlib rather than imp, but this doesn't work on python 2.6; is this behavior being fixed in the dev branch?

Thanks! :)

EDIT:
I just noticed this PR in jedi about this issue: davidhalter/jedi#109
Is this solution going to be accepted? Maybe I can have a look into this problem ;)

@davidhalter

@Astrac There's no support for Python 3 yet.

Is this solution going to be accepted? Maybe I can have a look into this problem ;)

Just do that. It doesn't look like the author is very active there (the PR is not a working implementation, like the @1st1 says:

This commit is very WIP, and maybe considered as a proof of concept.

So I would be glad to accept PRs. But of course no "proof of concepts", but working implementations.

My idea would be to have imp do it for 2.5-3.2 and use importlib for >= 3.3. So basically we would just need a new implementation there of the method that handles this stuff.

@krya

we really should spawn a subprocess with defined in settings python binary and pass current buffer via pipe on each autocompete request. although I'm a bit horrified with a speed penalty it would bring :)

@Astrac Astrac referenced this pull request in davidhalter/jedi Mar 22, 2013
Closed

Trying to run Jedi on Python version 3.3 #123

@schlamar schlamar commented on the diff Mar 27, 2013
python_go_to.py
@@ -1,7 +1,7 @@
import sublime
import sublime_plugin
-from sublime_jedi import get_script, JediEnvMixin
+from SublimeJEDI.sublime_jedi import get_script, JediEnvMixin
@schlamar
schlamar added a line comment Mar 27, 2013

This should need a fix for ST2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@schlamar schlamar commented on the diff Mar 27, 2013
sublime_jedi.py
root = complete.name
display, insert = complete.word, complete.word
p = None
while isinstance(root, jedi.evaluate.ArrayElement):
root = root.parent()
- if isinstance(root, jedi.keywords.Keyword):
+ # Sublime 3 has a different import strategy that breaks any try to
+ # check for class equality using isinstance
@schlamar
schlamar added a line comment Mar 27, 2013

That doesn't make sense for me, could you elaborate on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@schlamar

Is the jedi upgrade really required for ST3 compability? If not, this shouldn't be in this PR.

@schlamar

Actually, this is everything to get Jedi (partially) running on ST3: schlamar@13dc24c

However, the complete design of SublimeJEDI is IMO broken as it does auto-completion with the ST plugin interpreter and not the configured interpreter.

we really should spawn a subprocess with defined in settings python binary and pass current buffer via pipe on each autocompete request. although I'm a bit horrified with a speed penalty it would bring :)

This goes in the right direction. Caching the auto-completion elements per view and regenerate the cache after a save should be a performant variation.

@srusskih
Owner

However, the complete design of SublimeJEDI is IMO broken as it does auto-completion with the ST plugin interpreter and not the configured interpreter.

Could you please, show an example, looks like I misunderstanding a bit

@schlamar

Could you please, show an example, looks like I misunderstanding a bit

My configured interpreter is python, which points to a Python 2 interpreter. But jedi is run with the Python 3.3 from ST which results in some SyntaxErrors on auto complete, e.g.

    except RuntimeError, e:
                       ^
SyntaxError: invalid syntax
@schlamar schlamar commented on the diff Mar 27, 2013
sublime_jedi.py
@@ -41,7 +46,8 @@ def get_user_env():
:return: list
"""
# load settings
- plugin_settings = sublime.load_settings(__name__ + '.sublime-settings')
+ settings_file = __name__.split('.')[-1] + '.sublime-settings'
@schlamar
schlamar added a line comment Mar 27, 2013

This is a hack. Why not using the literal name ('sublime_jedi.sublime-settings')?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@srusskih
Owner

@schlamar, Thx. Looks this can help http://www.python.org/dev/peps/pep-3110/#compatibility

UPD: oh, I just got.
Yours interpreter path to python is full-like path (/path/to/python) or default settings value (python) ?

@schlamar

Default settings.

However, upgrading jedi to davidhalter/jedi#187 solved this issue, see https://github.com/schlamar/SublimeJEDI/tree/jedi-3.3 for a fully working ST3 version.

@schlamar

As soon as davidhalter/jedi#187 gets merged, I'll make a clean PR for SublimeJEDI based on my jedi-3.3 branch.

@srusskih
Owner

Sounds promising :)

@schlamar

Sadly the patch doesn't seem to be stable: davidhalter/jedi#187 (comment)

@schlamar schlamar referenced this pull request in SublimeCodeIntel/SublimeCodeIntel Mar 27, 2013
Closed

Sublime Text 3 support? #234

@schlamar

Sounds promising :)

Here we go: #20

@srusskih srusskih closed this Mar 27, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment