Sublime Forum

Jedi fails on autocomplete in sublime text

#1

Jedi fails on autocomplete in sublime text for some cases. I know that this is not a support forum for “jedi”, but in independent python interpreter this code example works fine

Source example:

import os

def x(y):
    print(y)

print(x)
f = open('1.txt', mode='r', encoding='utf-8'). # fail on dot

from datetime import d # fail on module import

I’ve got this error in both cases:

...
  File "/Users/rmerkushin/Library/Application Support/Sublime Text 3/Packages/sublime-jedi/jedi/parser/__init__.py", line 267, in parse
    root_node = super(ParserWithRecovery, self).parse(self._tokenize(tokenizer))
  File "/Users/rmerkushin/Library/Application Support/Sublime Text 3/Packages/sublime-jedi/jedi/parser/__init__.py", line 146, in parse
    self.remove_last_newline()
  File "/Users/rmerkushin/Library/Application Support/Sublime Text 3/Packages/sublime-jedi/jedi/parser/__init__.py", line 227, in remove_last_newline
    assert newline.value.endswith('\n')
AssertionError

My plugin source:

import jedi

import sublime
import sublime_plugin


COMPLITION_FLAGS = sublime.INHIBIT_WORD_COMPLETIONS | sublime.INHIBIT_EXPLICIT_COMPLETIONS


class Autocomplete(sublime_plugin.EventListener):

    def on_query_completions(self, view, prefix, locations):
        line, column = view.rowcol(locations[0])
        source = view.substr(sublime.Region(0, view.size()))
        script = jedi.Script(source, line + 1, column, path=view.file_name() or '')
        completions = [(c.name + '\t' + c.type, c.name) for c in script.completions()]
        return (completions, COMPLITION_FLAGS)

Does anyone have idea how to fix this issue?

P.S.: jedi version - 0.10.0, Sublime Text - 3126
Sorry for my english :slightly_smiling:

0 Likes

#2

cross post from SO: http://stackoverflow.com/questions/42806829/jedi-fails-on-autocomplete-in-sublime-text

0 Likes

#3

Yes. I also wrote the question here: https://github.com/davidhalter/jedi/issues/896 but after discussion and debugging jedi lib, I think that the problem is in the code execution in sublime embedded python. Maybe I’m wrong, but i want to find true reason. Delete the topic if I violate forum rules.

0 Likes