Skip to content

Conversation

@shugo
Copy link
Owner

@shugo shugo commented Nov 13, 2025

It should be the source location of the method of the appropriate subclass.

It should be the source location of the method of the appropriate subclass.
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes the source location reporting for generic commands to properly reflect the source location of the method implementation in the appropriate mode subclass, rather than the location where the generic command wrapper is defined.

Key changes:

  • Modified Command from a Struct to a Data class with an additional source_location_proc field that can dynamically compute the source location
  • Updated define_generic_command to provide a lambda that retrieves the actual method's source location from the current buffer's mode
  • Changed help display to use the new cmd.source_location method instead of directly accessing cmd.block.source_location

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
lib/textbringer/commands.rb Converts Command from Struct to Data.define, adds source_location method and source_location_proc parameter to support dynamic source location resolution
lib/textbringer/mode.rb Updates define_generic_command to pass a lambda that retrieves the source location from the actual mode method implementation
lib/textbringer/commands/help.rb Updates command_help to use the new cmd.source_location method instead of directly accessing the block's source location

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

command_name = (name.to_s + "_command").intern
define_command(command_name, **options) do |*args|
define_command(command_name,
source_location_proc: -> { Buffer.current.mode.method(name).source_location rescue nil },
Copy link

Copilot AI Nov 13, 2025

Choose a reason for hiding this comment

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

The bare rescue here catches all exceptions, including system-level exceptions like SystemExit and SignalException. Consider rescuing specific exceptions (e.g., rescue NoMethodError, NameError) to avoid suppressing unexpected errors that should propagate.

Suggested change
source_location_proc: -> { Buffer.current.mode.method(name).source_location rescue nil },
source_location_proc: -> { Buffer.current.mode.method(name).source_location rescue NameError, NoMethodError; nil },

Copilot uses AI. Check for mistakes.
Copy link
Owner Author

Choose a reason for hiding this comment

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

The rescue modifier doesn't catch SystemExit because such a system-level exception doesn't inherit StandardError.

@shugo shugo merged commit 8c9409c into main Nov 13, 2025
15 checks passed
@shugo shugo deleted the fix/generic_command-source_location branch November 13, 2025 07:07
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.

2 participants