Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

textDocument/references Overreporting when class has multiple definitions in Neovim #3088

Closed
vicocamacho opened this issue Jan 23, 2025 · 4 comments · Fixed by #3098
Closed
Labels
bug Something isn't working help-wanted Extra attention is needed non-vscode

Comments

@vicocamacho
Copy link
Contributor

vicocamacho commented Jan 23, 2025

Description

Hi!

I noticed the following while I was working on a Ruby on Rails project that has classes that are re-opened on different parts of the codebase.

Something along the lines of:

# app/models/user.rb
class User < ApplicationRecord
  include Validations
end

# app/models/concerns/user/validations.rb
class User
  module Validations
    extend ActiveSupport::Concern

    def method
    end
  end
end

# app/controllers/users_controller.rb
class UsersController < ApplicationController
  def show
    @user = User.find(params[:id])
  end
end

if I trigger the textDocument/references action while hovering on User I see the results twice for the reference in users_controller.rb. I also confirmed that this doesn't happen in VSCode.

I would like to help solving the issue once it is confirmed I would just need some guidance.

Thanks!

@vicocamacho vicocamacho added bug Something isn't working help-wanted Extra attention is needed non-vscode labels Jan 23, 2025
@vinistock
Copy link
Member

Thanks for the report. If you turn on server tracing, you can verify what the LSP is returning back to the editor for the textDocument/references request.

{
  "ruby lsp.trace.server": "verbose"
}

If we're indeed returning more than one result for the same occurrence, then it's a bug in our implementation.

@vicocamacho
Copy link
Contributor Author

vicocamacho commented Jan 27, 2025

Hi @vinistock thanks for the guidance, this is what I'm seeing in the response from the LSP:

2025-01-27 11:13:41.119 [info] (test_app) [Trace - 11:13:41 AM] Received response 'textDocument/references - (37)' in 22ms.
2025-01-27 11:13:41.119 [info] (test_app) Result: [
    {
        "uri": "file:///Users/victor/src/test_app/app/models/concerns/user/validations.rb",
        "range": {
            "start": {
                "line": 0,
                "character": 6
            },
            "end": {
                "line": 0,
                "character": 10
            }
        }
    },
    {
        "uri": "file:///Users/victor/src/test_app/app/models/user.rb",
        "range": {
            "start": {
                "line": 0,
                "character": 6
            },
            "end": {
                "line": 0,
                "character": 10
            }
        }
    },
    {
        "uri": "file:///Users/victor/src/test_app/app/controllers/users_controller.rb",
        "range": {
            "start": {
                "line": 2,
                "character": 12
            },
            "end": {
                "line": 2,
                "character": 16
            }
        }
    },
    {
        "uri": "file:///Users/victor/src/test_app/app/controllers/users_controller.rb",
        "range": {
            "start": {
                "line": 2,
                "character": 12
            },
            "end": {
                "line": 2,
                "character": 16
            }
        }
    },
    {
        "uri": "file:///Users/victor/src/test_app/app/controllers/users_controller.rb",
        "range": {
            "start": {
                "line": 2,
                "character": 12
            },
            "end": {
                "line": 2,
                "character": 16
            }
        }
    }
]

I see the users_controller reference three times, is this what you were referring to?

@vinistock
Copy link
Member

Yes, indeed. It seems we're indeed returning duplicates if that's what you're seeing in the trace.

The relevant implementation is in our reference finder. I would start by writing a test that reproduces that example and then we can check what's going wrong in the implementation.

@vicocamacho
Copy link
Contributor Author

sounds good, I will get started on it. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help-wanted Extra attention is needed non-vscode
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants