GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Add basic Goto Implementation Request support by smheidrich · Pull Request #644 · python-lsp/python-lsp-server

Conversation

@smheidrich

@smheidrich smheidrich commented May 11, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Description

As pointed out in #97, support for the LSP Goto Implementation Request (textDocument/implementation) aka implementationProvider capability is still missing.

This PR adds basic support for this feature using Rope's rope.findit.find_implementations function (so it only works if the rope extra is installed).

Rope's find_implementations function seems a bit brittle, e.g. it doesn't appear to work for some slightly more complicated inheritance hierarchies (multiple levels & multiple inheritance & generics, but not sure which of these is the issue), but these things should be fixed upstream & in any case it's better than nothing.

Status

  • Blocked by:
    • findit.find_implementations on method call finds implementation for different subclass python-rope/rope#812
  • Also at least 1 bug remaining on this side of the implementation:
    • Add basic Goto Implementation Request support #644 (comment)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

jakubbortlik reacted with rocket emoji
All reactions
  • 🚀 1 reaction
@smheidrich
smheidrich force-pushed the implement-basic-goto-implementation branch 3 times, most recently from 282f64b to 8604c25 Compare May 11, 2025 16:10
smheidrich added 2 commits May 11, 2025 22:13
@smheidrich
Add basic Goto Implementation Request support
84cb3a5
@smheidrich
Add test_implementation based on test_definition
b7fb666
These don't work because Rope's find_implementations doesn't take a
`source` argument (unlike e.g. `code_assist`) and hence *always*
loads the file from disk, which means we can't use a "fake" module
unless we want to use `unittest.mock.patch` to override some of this
behavior, which is hacky & bad.
@smheidrich
smheidrich force-pushed the implement-basic-goto-implementation branch from 8604c25 to 6dd3500 Compare May 11, 2025 20:32
@smheidrich
Fix test_implementations by using real on-FS file
41a8852
@smheidrich
smheidrich force-pushed the implement-basic-goto-implementation branch from 6dd3500 to 41a8852 Compare May 11, 2025 20:35
@smheidrich
smheidrich marked this pull request as ready for review May 11, 2025 20:38
@smheidrich
Determine columns for found implementations
9c715d1
krassowski
krassowski reviewed May 12, 2025
View reviewed changes
Comment thread pylsp/plugins/rope_implementation.py Outdated
rope_project = workspace._rope_project_builder(rope_config)
rope_resource = document._rope_resource(rope_config)

impls = find_implementations(rope_project, rope_resource, offset)

@krassowski krassowski May 12, 2025

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should it be wrapped in try-except to handle exceptions, as in:

python-lsp-server/pylsp/plugins/rope_completion.py

Lines 59 to 65 in 04fa3e5

try:
definitions = code_assist(
rope_project, document.source, offset, document_rope, maxfixes=3
)
except Exception as e:
log.debug("Failed to run Rope code assist: %s", e)
return []

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

smheidrich reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

@smheidrich smheidrich May 12, 2025

Copy link
Copy Markdown
Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread pylsp/plugins/rope_implementation.py

from rope.base.project import Project
from rope.base.resources import Resource
from rope.contrib.findit import Location, find_implementations

@krassowski krassowski May 12, 2025

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess it would also make sense to add find_definition?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@smheidrich smheidrich May 12, 2025

Copy link
Copy Markdown
Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you mean using rope.contrib.findit.find_definition to implement the LSP textDocument/definition request, that one is already implemented in python-lsp-server using Jedi, so I don't think adding an additional Rope-powered implementation makes sense. But maybe I misunderstand it?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@krassowski krassowski May 12, 2025

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that's what I meant. My reasoning is twofold:

  • I think that jedi's implementation will return both implementation and definitions
  • I believe that users who would want to use rope for this would likely want to disable the jedi implementation if they could have a matching rope implementation for consistency

Of note, rope is disabled by default in general because it is hard to guarantee it works well and does not conflict with jedi (e.g. by de-duplciating responses).

For the best UX for an average user I think it would be best to add textDocument/implementation using jedi, but I would not object to adding one with rope as in this PR.

I was just curious as to your reasoning for adding only textDocument/implementation and not also textDocument/definition which would be my choice if I was adding a rope version for it.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@smheidrich smheidrich May 12, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Comment deleted because it doesn't make sense, give me a minute while I write a new one)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@smheidrich smheidrich May 12, 2025

Copy link
Copy Markdown
Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I originally wrote a response disagreeing but there was a glaring mistake in it because I overlooked that the current Rope find_implementations implementation is much buggier than I thought: E.g. for a file like

class A:
  def f(self): ...

class B(A):
  def f(self): ...

a: A = A()
a.f()

using Rope's find_implementations on the a.f() call will go to B.f for some reason 😕

It works well for moving between overridden methods within a class hierarchy, where it nicely complements the Jedi textDocument/definition, which always moves "up", by moving "down" instead.

But my guess is that it would take quite a lot of effort to fix Rope's find_implementations so it works correctly when used on method calls as well 😔

I'll open an issue but this PR should be on hold until it's fixed, no point merging something that's fundamentally buggy from day 1.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@smheidrich smheidrich May 12, 2025

Copy link
Copy Markdown
Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rope issue created:

  • findit.find_implementations on method call finds implementation for different subclass python-rope/rope#812

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@krassowski

krassowski commented May 12, 2025

Copy link
Copy Markdown
Member

It looks like a few of the tests are failing:

ERROR test/plugins/test_implementations.py::test_implementations - TypeError: expected str, bytes or os.PathLike object, not NoneType
ERROR test/plugins/test_implementations.py::test_implementations_skipping_one_class - TypeError: expected str, bytes or os.PathLike object, not NoneType
ERROR test/plugins/test_implementations.py::test_property_implementations - TypeError: expected str, bytes or os.PathLike object, not NoneType
ERROR test/plugins/test_implementations.py::test_implementations_not_a_method - TypeError: expected str, bytes or os.PathLike object, not NoneType
smheidrich reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

smheidrich
smheidrich commented May 12, 2025
View reviewed changes
Comment thread test/plugins/test_implementations.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

smheidrich added 3 commits May 12, 2025 12:42
@smheidrich
Add Python 3.8 support for rope_implementations
c1437e8
@smheidrich
Handle Rope find_implementations errors explicitly
f38d3ef
@smheidrich
Fix linting issues in rope_implementation & tests
b460f31
smheidrich
smheidrich commented May 12, 2025
View reviewed changes
Comment thread pylsp/plugins/rope_implementation.py
{
"uri": uris.uri_with(
document.uri,
path=os.path.join(workspace.root_path, impl.resource.path),

@smheidrich smheidrich May 12, 2025

Copy link
Copy Markdown
Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Under certain circumstances I seem to get URIs like ///example.py here for a file that is actually in another directory - will have to investigate & fix.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@smheidrich
smheidrich marked this pull request as draft May 12, 2025 21:03
@smheidrich smheidrich mentioned this pull request May 12, 2025
findit.find_implementations on method call finds implementation for different subclass python-rope/rope#812
Open
@Hoblovski Hoblovski mentioned this pull request May 13, 2025
Add support for type definition #645
Merged
Hoblovski added a commit to cloudwego/abcoder that referenced this pull request May 15, 2025
@Hoblovski
feat: python parser skeleton with custom pylsp
8d868e8
Custom pylsp is based on [python-lsp-server](https://github.com/python-lsp/python-lsp-server), and plus the following pull requests:
1. semanticTokens/full: python-lsp/python-lsp-server#645
2. typeDefinition: python-lsp/python-lsp-server#533
Maybe also
3. implementation: python-lsp/python-lsp-server#644
Hoblovski added a commit to cloudwego/abcoder that referenced this pull request Jul 25, 2025
@Hoblovski
Custom pylsp is based on [python-lsp-server](https://github.com/pytho…
2fe1f71
…n-lsp/python-lsp-server), and plus the following pull requests:

1. semanticTokens/full: python-lsp/python-lsp-server#645
2. typeDefinition: python-lsp/python-lsp-server#533
Maybe also
3. implementation: python-lsp/python-lsp-server#644
Hoblovski added a commit to cloudwego/abcoder that referenced this pull request Jul 30, 2025
@Hoblovski
Custom pylsp is based on [python-lsp-server](https://github.com/pytho…
3f6c3ed
…n-lsp/python-lsp-server), and plus the following pull requests:

1. semanticTokens/full: python-lsp/python-lsp-server#645
2. typeDefinition: python-lsp/python-lsp-server#533
Maybe also
3. implementation: python-lsp/python-lsp-server#644
simuleite pushed a commit to simuleite/abcoder that referenced this pull request Feb 28, 2026
@Hoblovski
Custom pylsp is based on [python-lsp-server](https://github.com/pytho…
bce5505
…n-lsp/python-lsp-server), and plus the following pull requests:

1. semanticTokens/full: python-lsp/python-lsp-server#645
2. typeDefinition: python-lsp/python-lsp-server#533
Maybe also
3. implementation: python-lsp/python-lsp-server#644
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@krassowski krassowski krassowski left review comments

At least 1 approving review is required to merge this pull request.

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@smheidrich @krassowski
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.