anaconda icon indicating copy to clipboard operation
anaconda copied to clipboard

`Go To Definition` won't work after updating to the newest Anaconda release

Open jrzaurin opened this issue 2 years ago • 20 comments

Expected Behaviour

Go to the definition of the object in the source code. For example, when using python for Machine Learning, I cannot access any function in sklearn

Actual Behaviour

Prints unable to find 'object' (see picture attached)

Steps to Reproduce

set up an environment with pyenv

pyenv virtualenv 3.9.10 test39
pyenv activate test39

install any package (e.g. sklearn)

pip install -U scikit-learn

open sublime and type:

from sklearn.metrics import accuracy_score

in the editor. Then try: Anaconda -> go to definition

my anaconda user settings look like this:

{
	"anaconda_linting": false,
	"swallow_startup_errors": true,
	"python_interpreter": "/Users/javierrodriguezzaurin/.pyenv/versions/3.9.10/envs/test39/bin/python",
}

ST3, Anaconda and OS versions

ST4: 4126 Anaconda version: 2.3.0 MacOS: 12.2.1

ST3 Console Logs

Anaconda's JsonServer Logs

these are the relevant logs I think

2022-03-02 21:15:23,218: INFO    : client requests: goto
2022-03-02 21:15:23,230: ERROR   : Object of type PosixPath is not JSON serializable
2022-03-02 21:15:23,231: ERROR   : Traceback (most recent call last):
  File "/Users/javierrodriguezzaurin/Library/Application Support/Sublime Text/Packages/Anaconda/anaconda_server/jsonserver.py", line 112, in found_terminator
    self.handle_command(
  File "/Users/javierrodriguezzaurin/Library/Application Support/Sublime Text/Packages/Anaconda/anaconda_server/jsonserver.py", line 142, in handle_command
    handler(
  File "/Users/javierrodriguezzaurin/Library/Application Support/Sublime Text/Packages/Anaconda/anaconda_server/handlers/jedi_handler.py", line 28, in run
    super(JediHandler, self).run()
  File "/Users/javierrodriguezzaurin/Library/Application Support/Sublime Text/Packages/Anaconda/anaconda_server/lib/anaconda_handler.py", line 49, in run
    command(**kwargs)
  File "/Users/javierrodriguezzaurin/Library/Application Support/Sublime Text/Packages/Anaconda/anaconda_server/handlers/jedi_handler.py", line 101, in goto
    Goto(
  File "/Users/javierrodriguezzaurin/Library/Application Support/Sublime Text/Packages/Anaconda/anaconda_server/commands/goto.py", line 14, in __init__
    super(Goto, self).__init__(callback, uid)
  File "/Users/javierrodriguezzaurin/Library/Application Support/Sublime Text/Packages/Anaconda/anaconda_server/commands/base.py", line 14, in __init__
    self.run()
  File "/Users/javierrodriguezzaurin/Library/Application Support/Sublime Text/Packages/Anaconda/anaconda_server/commands/goto.py", line 44, in run
    self.callback(
  File "/Users/javierrodriguezzaurin/Library/Application Support/Sublime Text/Packages/Anaconda/anaconda_server/handlers/jedi_handler.py", line 37, in handle_result_and_purge_cache
    self.real_callback(result)
  File "/Users/javierrodriguezzaurin/Library/Application Support/Sublime Text/Packages/Anaconda/anaconda_server/jsonserver.py", line 63, in return_back
    data = '{0}\r\n'.format(json.dumps(data))
  File "/Users/javierrodriguezzaurin/.pyenv/versions/3.9.10/lib/python3.9/json/__init__.py", line 231, in dumps
    return _default_encoder.encode(obj)
  File "/Users/javierrodriguezzaurin/.pyenv/versions/3.9.10/lib/python3.9/json/encoder.py", line 199, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "/Users/javierrodriguezzaurin/.pyenv/versions/3.9.10/lib/python3.9/json/encoder.py", line 257, in iterencode
    return _iterencode(o, 0)
  File "/Users/javierrodriguezzaurin/.pyenv/versions/3.9.10/lib/python3.9/json/encoder.py", line 179, in default
    raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type PosixPath is not JSON serializable
Screenshot 2022-03-02 at 9 13 24 PM

jrzaurin avatar Mar 02 '22 20:03 jrzaurin

Just in case it helps, manually downgrading to Anaconda 2.2.3 fixed the issue

jrzaurin avatar Mar 02 '22 22:03 jrzaurin

Same problem for me

gimmi avatar Mar 06 '22 09:03 gimmi

Time to time control + option + g opens new empty tab instead of searching definition

Havdiak avatar Mar 09 '22 12:03 Havdiak

I'm experiencing the same thing too.

mikez avatar Mar 10 '22 11:03 mikez

I will not have time to look into this for a while, I am very busy with other projects right now, if someone steps up to look into this it would be great.

DamnWidget avatar Mar 10 '22 12:03 DamnWidget

@DamnWidget Thanks for the heads-up. :)

Note, I also experience this issue when jumping within the same file. It seems in that case, it's not thePosixPath is not JSON serializable error, but rather the position returns None instead of the filepath, thus leading to a blank tab when calling sublime.active_window().open_file(self.position, flags) in Jumper:

{"success": true, "result": [["__main__.hello", null, 7, 5]], "uid": "df29c0a94da3408e93b1204c9aa7ac74"}

mikez avatar Mar 10 '22 13:03 mikez

Something similar happens with "Find Usages", command palette drop down list with the results prefixed with "main"

Gregory-K avatar Apr 11 '22 14:04 Gregory-K

quickfix that fixed that for me - change this line: https://github.com/DamnWidget/anaconda/blob/master/anaconda_server/commands/goto.py#L36 from: (i.full_name, i.module_path, i.line, i.column + 1) to: (i.full_name, str(i.module_path), i.line, i.column + 1)

x0nix avatar Apr 13 '22 10:04 x0nix

@x0nix :) Thank you! This fixes "go to" involving import statements for me.

However, navigating within the same file, I still get a blank tab as described here: https://github.com/DamnWidget/anaconda/issues/924#issuecomment-1064063392 — maybe that's another issue.

mikez avatar Apr 13 '22 14:04 mikez

x0nix's 'quickfix' only hacks/paves the way to "Goto Definition" of an imported library (at the import statement location, like mikez mentioned above). Thanks to x0nix for their suggestion.

A quick diff between v2.3.0 and v2.2.3 shows that the problem couldn't reside in those two files alone, goto.py and find_usages.py (not sure, Anaconda's code base is too big for me to grasp it in a glimpse). The shift to ST4-only, and Python 3.8 for ST plugins, introduced many changes in multiple locations.

Then, there is

A. the release notes,

https://github.com/DamnWidget/anaconda/releases/tag/v2.3.0

Fixes

  • Goto Definition
  • Goto Assignment

B. the fix: fix anaconda to work with Python 3.10 commit

https://github.com/DamnWidget/anaconda/commit/ef6750f1dc66fa2da16245cfcaf2d54afb86d285

and

C. issue #921

So far I have the plugin working again with the latest version of Jedi and Python 3.10.1 in an Artix Linux box, that means, auto completion, docs, function signatures and goto, are working again.
...
I will make a new release as soon as I can, btw, I am not caring if older versions of Python gets broken by the update, ...

| |

Short pause to express my total respect to DamnWidget's decision and gratitude for all the past years of their hard work.

|>

So, do the v2.3.0 "Goto" commands work only with Python >= v3.10 ?
I don't know, I currently deal only with v3.7 =< Python =< v3.9 .

Summary of my quick and draft tests

Windows/Linux + ST4 + Anaconda-plugin v2.3.0 => 'linting' v3.7 =< Python =< v3.9 code-base

None of the v2.3.0 Goto Definition, Goto Assignment, and Find Usages commands work, at all, or as they should be.

I think a project-developer/project-previous-contributor should step in (code familiarity) or we'll have to wait for someone (including us subscribed to this issue) who has the time or the "talent" ("talent" as in less time/effort). Till then, v2.2.3 is the way backwards for anyone that wants the functionality above (described commands) or just a reassurance that all things work as before (including known quirks and bugs).

Gregory-K avatar May 07 '22 14:05 Gregory-K

@Gregory-K Thanks for the digging and write-up!

Does upgrading to Python 3.10 resolve this?

If so, as Sublime plugins as of now run at most on 3.8 (see documentation here), I wonder what workaround @DamnWidget had in mind.

mikez avatar May 07 '22 15:05 mikez

@mikez the situation is a little perplexed.

ST4 provides and 'runs' Python 3.8 for its plugins/plugin-system and will continue to do so till the next major version upgrade, ST5.

What DamnWidget is aiming for (at least what I understood by a quick glance at the relevant issues/announcements) is for Anaconda to support the "linting" of Python 3.10 code base.
e.g. Anaconda runs in ST4's provided Python 3.8 and provides "linting" for code written in/for Python 3.10

That said, I haven't tried to test it, as all my code for now targets =< Python 3.9.
It's not difficult though, but it requires time to create a virtual env Python 3.10 and test it. (pyenv could be of help)

Gregory-K avatar May 07 '22 16:05 Gregory-K

Just an update.
I tried today a Python 3.10 virtual env and ST4 + Anaconda v2.3.0.

Goto Definition, Goto Assignment, and Find Usages commands persist on not working.

I'm attaching some logs and notes.

Linux ST4 Console
Unable to open /home/USER/Desktop/Projects/PYTHON-PROJECT/None
Unable to open /home/USER/Desktop/Projects/PYTHON-PROJECT/None
Unable to open /home/USER/Desktop/Projects/PYTHON-PROJECT/None
ERROR:root:String required
ERROR:root:Traceback (most recent call last):
ERROR:root:  File "/home/USER/.config/sublime-text/Packages/Anaconda/anaconda_lib/jsonclient.py", line 104, in process_message
ERROR:root:    callback(data)
ERROR:root:  File "/home/USER/.config/sublime-text/Packages/Anaconda/anaconda_lib/callback.py", line 73, in __call__
ERROR:root:    return self._fire_callback(*args, **kwargs)
ERROR:root:  File "/home/USER/.config/sublime-text/Packages/Anaconda/anaconda_lib/callback.py", line 219, in _fire_callback
ERROR:root:    return callback and callback(*args, **kwargs)
ERROR:root:  File "/home/USER/.config/sublime-text/Packages/Anaconda/commands/find_usages.py", line 51, in on_success
ERROR:root:    ExplorerPanel(self.view, usages).show([], True)
ERROR:root:  File "/home/USER/.config/sublime-text/Packages/Anaconda/anaconda_lib/explore_panel.py", line 71, in show
ERROR:root:    self.view.window().show_quick_panel(
ERROR:root:  File "/opt/sublime_text/Lib/python38/sublime.py", line 776, in show_quick_panel
ERROR:root:    sublime_api.window_show_quick_panel(
ERROR:root:TypeError: String required
Unable to open /home/USER/Desktop/Projects/PYTHON-PROJECT/None
ERROR:root:String required
ERROR:root:Traceback (most recent call last):
ERROR:root:  File "/home/USER/.config/sublime-text/Packages/Anaconda/anaconda_lib/jsonclient.py", line 104, in process_message
ERROR:root:    callback(data)
ERROR:root:  File "/home/USER/.config/sublime-text/Packages/Anaconda/anaconda_lib/callback.py", line 73, in __call__
ERROR:root:    return self._fire_callback(*args, **kwargs)
ERROR:root:  File "/home/USER/.config/sublime-text/Packages/Anaconda/anaconda_lib/callback.py", line 219, in _fire_callback
ERROR:root:    return callback and callback(*args, **kwargs)
ERROR:root:  File "/home/USER/.config/sublime-text/Packages/Anaconda/commands/find_usages.py", line 51, in on_success
ERROR:root:    ExplorerPanel(self.view, usages).show([], True)
ERROR:root:  File "/home/USER/.config/sublime-text/Packages/Anaconda/anaconda_lib/explore_panel.py", line 71, in show
ERROR:root:    self.view.window().show_quick_panel(
ERROR:root:  File "/opt/sublime_text/Lib/python38/sublime.py", line 776, in show_quick_panel
ERROR:root:    sublime_api.window_show_quick_panel(
ERROR:root:TypeError: String required
Unable to open /home/USER/Desktop/Projects/PYTHON-PROJECT/None
Unable to open /home/USER/Desktop/Projects/PYTHON-PROJECT/None
Unable to open /home/USER/Desktop/Projects/PYTHON-PROJECT/None


Traceback (most recent call last):
  File "/opt/sublime_text/Lib/python38/sublime_plugin.py", line 571, in init
    on_activated(view_id)
  File "/opt/sublime_text/Lib/python38/sublime_plugin.py", line 960, in on_activated
    run_view_callbacks('on_activated', view_id)
  File "/opt/sublime_text/Lib/python38/sublime_plugin.py", line 728, in run_view_callbacks
    callback(v, *args)
  File "/opt/sublime_text/Lib/python38/sublime_plugin.py", line 152, in profiler
    return event_handler(*args)
  File "/home/USER/.config/sublime-text/Packages/Anaconda/listeners/linting.py", line 124, in on_activated
    self.run_linter(view)
  File "/home/USER/.config/sublime-text/Packages/Anaconda/anaconda_lib/linting/sublime.py", line 381, in run_linter
    Worker().execute(Callback(on_success=parse_results), **data)
  File "/home/USER/.config/sublime-text/Packages/Anaconda/anaconda_lib/workers/market.py", line 108, in execute
    _start_worker(worker, callback, **data)
  File "/home/USER/.config/sublime-text/Packages/Anaconda/anaconda_lib/workers/market.py", line 75, in _start_worker
    wk.start()
  File "/home/USER/.config/sublime-text/Packages/Anaconda/anaconda_lib/workers/local_worker.py", line 56, in start
    super(LocalWorker, self).start()
  File "/home/USER/.config/sublime-text/Packages/Anaconda/anaconda_lib/workers/worker.py", line 81, in start
    self.client = AsynClient(int(port), host=host)
  File "/home/USER/.config/sublime-text/Packages/Anaconda/anaconda_lib/jsonclient.py", line 42, in __init__
    EventHandler.__init__(
  File "/home/USER/.config/sublime-text/Packages/Anaconda/anaconda_lib/ioloop.py", line 110, in __init__
    self.sock.connect(address)
ConnectionRefusedError: [Errno 111] Connection refused
Windows ST4 JSON DEBUG server

When validate_imports is enabled

Received method: lint, handler: python_linter
<class 'handlers.python_lint_handler.PythonLintHandler'> handler retrieved from registry
ERROR:root:__init__() takes from 1 to 2 positional arguments but 5 positional arguments (and 1 keyword-only argument) were given
DEBUG:root:['Traceback (most recent call last):', '  File "Subl_4\\Data\\Packages\\Anaconda\\anaconda_server\\commands\\import_validator.py", line 30, in run', "

'errors': [] if v.is_valid() else self._convert(v),", '  File "Subl_4\\Data\\Packages\\Anaconda\\anaconda_lib\\import_validator.py", line 28, in is_valid', '
error, valid = self._validate_import(line, lineno)', '  File "Subl_4\\Data\\Packages\\Anaconda\\anaconda_lib\\import_validator.py", line 51, in _validate_import', '
s = Script(self.source, lineno, offset, self.filename, project=jedi_project)', 'TypeError: __init__() takes from 1 to 2 positional arguments but 5 positional arguments (and 1 keyword-only argument) were given']{'success': True, 'errors': [{'underline_range': True, 'level': 'W', 'lineno': 1324, 'offset': 0, 'message': '[w] pep 8 (%s): %s', 'raw_error': '[W] PEP 8 (E402): module level import not at top of file'}, {'underline_range': True, 'level': 'W', 'lineno': 1325, 'offset': 0, 'message': '[w] pep 8 (%s): %s', 'raw_error': '[W] PEP 8 (E402): module level import not at top of file'}], 'uid': 'ec391f30f65948e296d21c568bb00b65', 'vid': 12}
About push back to ST3: b'{"success": true, "errors": [{"underline_range": true, "level": "W", "lineno": 1324, "offset": 0, "message": "[w] pep 8 (%s): %s", "raw_error": "[W] PEP 8 (E402): module level import not at top of file"}, {"underline_range": true, "level": "W", "lineno": 1325, "offset": 0, "message": "[w] pep 8 (%s): %s", "raw_error": "[W] PEP 8 (E402): module level import not at top of file"}], "uid": "ec391f30f65948e296d21c568bb00b65", "vid": 12}\r\n'
INFO:root:About push back to ST3: b'{"success": true, "errors": [{"underline_range": true, "level": "W", "lineno": 1324, "offset": 0, "message": "[w] pep 8 (%s): %s", "raw_error": "[W] PEP 8 (E402): module level import not at top of file"}, {"underline_range": true, "level": "W", "lineno": 1325, "offset": 0, "message": "[w] pep 8 (%s): %s", "raw_error": "[W] PEP 8 (E402): module level import not at top of file"}], "uid": "ec391f30f65948e296d21c568bb00b65", "vid": 12}\r\n'

Further

Goto Definition, Goto Assignment, and Find Usages return a 'None' path on_sucess.

Just try a print(path) at Anaconda/commands/goto.py

    def on_success(self, data):
        """Called when a result comes from the query
        """

        if not data.get('result'):
            # fallback to ST3 builtin Goto Definition
            return self.view.window().run_command('goto_definition')

        symbols = []
        for result in data['result']:
            path = self._infere_context_data(result[1])
            print(path)  # DEBUG: why no path

Gregory-K avatar May 10 '22 22:05 Gregory-K

So, the problem described in https://github.com/DamnWidget/anaconda/issues/924#issuecomment-1064063392 keeps persisting.

Anyone has found a solution to this? Thanks!

jrzaurin avatar Jan 28 '23 18:01 jrzaurin

@jrzaurin I'm not aware of a fix yet. It seems @DamnWidget (the maintainer) is prioritizing other projects per https://github.com/DamnWidget/anaconda/issues/924#issuecomment-1063990902 and requested someone look into it.

mikez avatar Jan 28 '23 20:01 mikez

hey @mikez

Yean I read it. The truth is that this to me is a major drawback 😔.

Oh well, maybe I will give VScode a go and hope they fix this soon (I do love Sublime 🙂). Or if anyone knows an Alternative to Amaconda, please let me know.

jrzaurin avatar Jan 28 '23 20:01 jrzaurin

@jrzaurin I feel you. I think you may try posting here: https://forum.sublimetext.com/c/ideas-and-feature-requests ... and explain the importance of it. That is, to have Sublime natively support a more powerful "show definition", including imported libraries akin to VSCode.

Big thank you to @DamnWidget who has been running this project since 2013. I totally understand if he has less energy and resources for it today.

mikez avatar Jan 29 '23 20:01 mikez

Or if anyone knows an Alternative to Amaconda, please let me know.

@jrzaurin I don't know what your needs, constraints, and workflow are, but you can always downgrade to Anaconda v2.2.3 or try the other LSP alternatives mentioned here https://github.com/DamnWidget/anaconda#alternatives .

Gregory-K avatar Jan 30 '23 01:01 Gregory-K

Hi there,

I added some alternatives to this plugin a while ago, they can be found in this section of the README file.

I am not sure how well they really work, I don't really use ST since circa 2014 so I really couldn't say but they look good to me.

Being honest, I didn't archived this repository yet because I still have hopes that someone (or someones) would step up and take care of the project but the possibility seems less probable each day.

Good luck everyone!

DamnWidget avatar Jan 30 '23 01:01 DamnWidget

@Gregory-K I did try, since I actually wrote this comment https://github.com/DamnWidget/anaconda/issues/924#issuecomment-1057458022. However I found the behaviour rather random in the sense that, sometimes worked, sometimes did not🤷🏻‍♂️

jrzaurin avatar Jan 30 '23 08:01 jrzaurin