DamnWidget / anaconda

Anaconda turns your Sublime Text 3 in a full featured Python development IDE including autocompletion, code linting, IDE features, autopep8 formating, McCabe complexity checker Vagrant and Docker support for Sublime Text 3 using Jedi, PyFlakes, pep8, MyPy, PyLint, pep257 and McCabe that will never freeze your Sublime Text 3
http://damnwidget.github.io/anaconda/
GNU General Public License v3.0
2.21k stars 260 forks source link

Anaconda autocomplete #914

Open malonn23 opened 2 years ago

malonn23 commented 2 years ago

Anaconda autocomplete is not working. I am on Linux and my Sublime Text 3 recently updated. Prior to the update it worked fine. I update via the Package Manager. ST version 4121. Latest Anaconda version. I tried uninstalling and reinstalling but it didn't help.

I don't get any errors. Here is the most recent error in my jsonserver log: 021-11-30 15:23:57,206: ERROR : Traceback (most recent call last): File "/home/malonn/.config/sublime-text/Packages/Anaconda/anaconda_lib/jedi/cache.py", line 109, in wrapper return dct[key] KeyError: ((), frozenset())

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/home/malonn/.config/sublime-text/Packages/Anaconda/anaconda_server/jsonserver.py", line 112, in found_terminator self.handle_command(handler_type, method, uid, vid, settings, data) File "/home/malonn/.config/sublime-text/Packages/Anaconda/anaconda_server/jsonserver.py", line 140, in handle_command handler(method, data, uid, vid, settings, self.return_back, DEBUG_MODE).run() File "/home/malonn/.config/sublime-text/Packages/Anaconda/anaconda_server/handlers/jedi_handler.py", line 29, in run super(JediHandler, self).run() File "/home/malonn/.config/sublime-text/Packages/Anaconda/anaconda_server/lib/anaconda_handler.py", line 49, in run command(kwargs) File "/home/malonn/.config/sublime-text/Packages/Anaconda/anaconda_server/handlers/jedi_handler.py", line 99, in doc Doc(self.callback, self.uid, self.script, html) File "/home/malonn/.config/sublime-text/Packages/Anaconda/anaconda_server/handlers/jedi_handler.py", line 45, in script return self.jedi_script(self.data) File "/home/malonn/.config/sublime-text/Packages/Anaconda/anaconda_server/handlers/jedi_handler.py", line 53, in jedi_script return jedi.Script( File "/home/malonn/.config/sublime-text/Packages/Anaconda/anaconda_lib/jedi/api/init.py", line 184, in init self._inference_state = InferenceState( File "/home/malonn/.config/sublime-text/Packages/Anaconda/anaconda_lib/jedi/inference/init.py", line 91, in init self.grammar = environment.get_grammar() File "/home/malonn/.config/sublime-text/Packages/Anaconda/anaconda_lib/jedi/cache.py", line 111, in wrapper result = method(self, *args, kwargs) File "/home/malonn/.config/sublime-text/Packages/Anaconda/anaconda_lib/jedi/api/environment.py", line 37, in get_grammar return parso.load_grammar(version=version_string) File "/home/malonn/.config/sublime-text/Packages/Anaconda/anaconda_lib/parso/grammar.py", line 260, in load_grammar return load_grammar(kwargs) File "/home/malonn/.config/sublime-text/Packages/Anaconda/anaconda_lib/parso/grammar.py", line 236, in load_grammar version_info = parse_version_string(version) File "/home/malonn/.config/sublime-text/Packages/Anaconda/anaconda_lib/parso/utils.py", line 176, in parse_version_string return _parse_version(version) File "/home/malonn/.config/sublime-text/Packages/Anaconda/anaconda_lib/parso/utils.py", line 125, in _parse_version raise ValueError('The given version is not in the right format. ' ValueError: The given version is not in the right format. Use something like "3.8" or "3".

I'm running Python 3.10.

DamnWidget commented 2 years ago

I am a bit confused, you said that you are using ST3 but the version you are using is for ST4. There was a patch added to prevent the plugin from triggering auto-completion when typing : or ' in ST4, it should not affect ST3 and definitely it should not affect regular . (dot) completion, try to downgrade to the previous version of anaconda to see if the problem goes away, update this thread with the results please

malonn23 commented 2 years ago

My bad, DamnWidget. I'm using ST4 (The latest ST--I thought it was 3). Autocomplete does not work at all for me.

malonn23 commented 2 years ago

I think I may be partially mistaken. Autocomplete does work to a degree. Did you change code so that it does not fetch functions and methods after a . (dot)? I've noticed that it works for things like function/method references and definitions, but not for things like this:

DamnWidget commented 2 years ago

To my understanding nothing related with the auto-completion results have been changed since way back no

malonn23 commented 2 years ago

It must be a system thing then. I tried uninstalling and reinstalling, but that didn't help. I don't know what else to do. Here's a recent log:

2021-12-05 11:56:43,383: ERROR   : Traceback (most recent call last):
  File "/home/malonn/.config/sublime-text/Packages/Anaconda/anaconda_lib/jedi/cache.py", line 109, in wrapper
    return dct[key]
KeyError: ((), frozenset())

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/malonn/.config/sublime-text/Packages/Anaconda/anaconda_server/jsonserver.py", line 112, in found_terminator
    self.handle_command(handler_type, method, uid, vid, settings, data)
  File "/home/malonn/.config/sublime-text/Packages/Anaconda/anaconda_server/jsonserver.py", line 140, in handle_command
    handler(method, data, uid, vid, settings, self.return_back, DEBUG_MODE).run()
  File "/home/malonn/.config/sublime-text/Packages/Anaconda/anaconda_server/handlers/jedi_handler.py", line 29, in run
    super(JediHandler, self).run()
  File "/home/malonn/.config/sublime-text/Packages/Anaconda/anaconda_server/lib/anaconda_handler.py", line 49, in run
    command(**kwargs)
  File "/home/malonn/.config/sublime-text/Packages/Anaconda/anaconda_server/handlers/jedi_handler.py", line 99, in doc
    Doc(self.callback, self.uid, self.script, html)
  File "/home/malonn/.config/sublime-text/Packages/Anaconda/anaconda_server/handlers/jedi_handler.py", line 45, in script
    return self.jedi_script(**self.data)
  File "/home/malonn/.config/sublime-text/Packages/Anaconda/anaconda_server/handlers/jedi_handler.py", line 53, in jedi_script
    return jedi.Script(
  File "/home/malonn/.config/sublime-text/Packages/Anaconda/anaconda_lib/jedi/api/__init__.py", line 184, in __init__
    self._inference_state = InferenceState(
  File "/home/malonn/.config/sublime-text/Packages/Anaconda/anaconda_lib/jedi/inference/__init__.py", line 91, in __init__
    self.grammar = environment.get_grammar()
  File "/home/malonn/.config/sublime-text/Packages/Anaconda/anaconda_lib/jedi/cache.py", line 111, in wrapper
    result = method(self, *args, **kwargs)
  File "/home/malonn/.config/sublime-text/Packages/Anaconda/anaconda_lib/jedi/api/environment.py", line 37, in get_grammar
    return parso.load_grammar(version=version_string)
  File "/home/malonn/.config/sublime-text/Packages/Anaconda/anaconda_lib/parso/grammar.py", line 260, in load_grammar
    return load_grammar(**kwargs)
  File "/home/malonn/.config/sublime-text/Packages/Anaconda/anaconda_lib/parso/grammar.py", line 236, in load_grammar
    version_info = parse_version_string(version)
  File "/home/malonn/.config/sublime-text/Packages/Anaconda/anaconda_lib/parso/utils.py", line 176, in parse_version_string
    return _parse_version(version)
  File "/home/malonn/.config/sublime-text/Packages/Anaconda/anaconda_lib/parso/utils.py", line 125, in _parse_version
    raise ValueError('The given version is not in the right format. '
ValueError: The given version is not in the right format. Use something like "3.8" or "3".

What's that ValueError? Related to my Python version. It's 3.10 (the latest) and he file is named 'python3.10'. Should I rename and test? I guess I will try.

DIM-KO commented 2 years ago

Hi i have the same problem in SublimeText for python 3.10, but in Windows. As a temporary solution i changed function "_parse_version" in the file C:\Program Files\sublime_text_build_4121_x64\Data\Packages\Anaconda\anaconda_lib\parso\utils.py like this:

def _parse_version(version):

    major = 3
    minor = 8

    return PythonVersionInfo(major, minor)

autocomplete working again

malonn23 commented 2 years ago

Great tip. Thanks. I took a cursory look at the error and was planning on fixing it, but it looks like you beat me to it. I will do as you did and see what comes of it. Thanks. @DIM-KO .

DamnWidget commented 2 years ago

I just had surgery (writing from he hospital actually) will take a bit of time until I can look into this stuff, if you find workarounds for this , please share them with the community I will be out for like three weeks. Also provide the most data you can also PRs will be very welcome.

Regards

malonn23 commented 2 years ago

I'm looking at it now, @DamnWidget . I have never done any work with RegEx, so will have to brush up on syntax and such. @DIM-KO 's fix is not 1-for-1, so I have to dig a little. Also, I'm not familiar with the acronym "PR". The only thing that comes to mind is "Public Relations". I hope all goes well for you post surgery.

DamnWidget commented 2 years ago

Hi, PR stand for Pull Request, thanks, I also hope everything goes well :)

malonn23 commented 2 years ago

Alright. I was able to solve the RegEx matching problem, but it looks like you need to add support for Python 3.10, @DamnWidget I don't know what all goes into adding support for a new version. In the meantime, I think I'm going to trick Anaconda into thinking my Python version is 3.8. Is 3.9 supported?

malonn23 commented 2 years ago

Answered my own question. 3.9 is supported.

DIM-KO commented 2 years ago

Solution: Step 1: copy the file ...\ Sublime_text \ Data \ Packages \ Anaconda \ anaconda_lib \ parso \ python \ grammar39.txt and rename to grammar310.txt Step 2: change function "_parse_version" in the file .. \ sublime_text \ Data \ Packages \ Anaconda \ anaconda_lib \ parso \ utils.py like this:

def _parse_version(version):
    match = re.match(r'(\d+)(?:\.(\d+)(?:\.\d+)?)?$', version)

Regards

malonn23 commented 2 years ago

Thanks, @DIM-KO I figured out the RegEx issue and but not the renaming of "grammar39". Still, @DamnWidget needs to update the package when he is well because renaming the "grammarxx.txt" drops support for Python 3.9. I will try to add a new file named "grammar310.txt" and see if that fixes the issue.

EDIT: Oops, misread your comment. You did copy grammar39.txt and rename. My fault. Still, @DamnWidget needs to add support for anything new in Python 3.10.

sdrenn commented 2 years ago

@DamnWidget you, probably, should mention somewhere (RAEDME maybe?) that 3.10 is not supported. I spent too much time to find that out on my own.