Skip to content

Comments

Add global fallback for failed symbol lookups#141

Draft
Copilot wants to merge 5 commits intodevelopfrom
copilot/add-fallback-lookup-functionality
Draft

Add global fallback for failed symbol lookups#141
Copilot wants to merge 5 commits intodevelopfrom
copilot/add-fallback-lookup-functionality

Conversation

Copy link
Contributor

Copilot AI commented Feb 25, 2026

When go-to-definition fails to find a symbol in the current scope chain, it now falls back to a project-wide search. Previously returned empty results for symbols defined elsewhere.

Changes

  • lib/ruby_language_server/project_manager.rb: Added global search fallback in project_definitions_for after scope chain exhaustion

    • Searches all scopes (classes, modules, methods) by name
    • Only triggers when scope-based search returns empty
  • Tests: Added coverage for cross-file/cross-scope lookups of classes and methods

Example

# File: utils.rb
class StringUtils
  def self.format(text)
    text.upcase
  end
end

# File: service.rb
module Services
  class TextProcessor
    def process(input)
      StringUtils.format(input)  # Go-to-definition now works
    end
  end
end

Before: Failed to find StringUtils (not in Services scope chain)
After: Finds definition via global fallback

Note: The fallback searches for scopes (classes, modules, methods) only. Variables/constants are not included in the global fallback to avoid performance issues and maintain locality of variable references.

Original prompt

This section details on the original issue you should resolve

<issue_title>Fallback if nothing found</issue_title>
<issue_description>If a lookup fails to find any matching constant/variable/method then it should fallback and look for that constant/method anywhere.</issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 2 commits February 25, 2026 04:11
Co-authored-by: kwerle <23320+kwerle@users.noreply.github.com>
Co-authored-by: kwerle <23320+kwerle@users.noreply.github.com>
all_scopes = all_scopes.where(class_method: class_method_filter) unless class_method_filter.nil?
results.concat(all_scopes.to_a)

# Also search for constants/variables globally
Copy link
Owner

Choose a reason for hiding this comment

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

No - let's not look for variables.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed variable search from the fallback. The fallback now only searches for scopes (classes, modules, methods). Commit: 7bc7dac

Co-authored-by: kwerle <23320+kwerle@users.noreply.github.com>
Copilot AI changed the title [WIP] Add fallback functionality for lookup failures Add global fallback for failed symbol lookups Feb 25, 2026
Copilot AI requested a review from kwerle February 25, 2026 04:17
Copy link
Owner

@kwerle kwerle left a comment

Choose a reason for hiding this comment

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

In the fallback do not look for variables

Co-authored-by: kwerle <23320+kwerle@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Feb 25, 2026

In the fallback do not look for variables

Done. The fallback now only searches for scopes and not variables. Also removed the related test. Commit: 7bc7dac

Copilot AI requested a review from kwerle February 25, 2026 04:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fallback if nothing found

2 participants