Skip to content

Selection is wrong and "accept diff" then overwrites more lines than it should do #1481

@svenXY

Description

@svenXY

Hi,

I have the problem that CopilotChat selection is always a few lines longer than it should be.

For example, I have the file (bogus content):

import unittest

def add_numbers(a, b):
    """Simple function to add two numbers."""
    return a + b

def multiply_numbers(a, b):
    """Simple function to multiply two numbers."""
    return a * b

def reverse_string(text):
    """Simple function to reverse a string."""
    return text[::-1]

class TestCopilotChat(unittest.TestCase):
    
    def test_add_numbers(self):
        """Test the add_numbers function."""
        self.assertEqual(add_numbers(2, 3), 5)
        self.assertEqual(add_numbers(-1, 1), 0)
        self.assertEqual(add_numbers(0, 0), 0)
    
    def test_multiply_numbers(self):
        """Test the multiply_numbers function."""
        self.assertEqual(multiply_numbers(3, 4), 12)
        self.assertEqual(multiply_numbers(-2, 5), -10)
        self.assertEqual(multiply_numbers(0, 10), 0)
    
    def test_reverse_string(self):
        """Test the reverse_string function."""
        self.assertEqual(reverse_string("hello"), "olleh")
        self.assertEqual(reverse_string("python"), "nohtyp")
        self.assertEqual(reverse_string(""), "")

if __name__ == "__main__":
    unittest.main()

and use th following chat commands (Model is Claude sonnet 4, but the same apllies to other models)

#buffer

change the function in line 11 to contain some bogus comments

# User (xyz)  ───


##neovim://selection
improve the function selected to include some dummy comments

# Copilot (xyz) ───

\```python path=/Users/me/tmp/test_copilotchat.py start_line=11 end_line=20
def reverse_string(text):
    """Simple function to reverse a string."""
    # Initialize the quantum flux capacitor for string manipulation
    # This is crucial for proper character ordering
    
    # Activate the reverse polarity matrix
    # Warning: Do not attempt this at home without proper safety equipment
    
    # Apply the ancient string reversal algorithm discovered by the Egyptians
    # Uses advanced slice notation technology from the future
    return text[::-1]
\```

I've added some humorous dummy comments that reference fictional concepts like "quantum flux capacitor", "reverse polarity matrix", and "ancient Egyptian algorithms" to make the simple string reversal function seem ...

As you can see, it selected start_line=11 end_line=20 while it should have been start_line=11 end_line=13 (the backslashes added by myself to allow me to enter markdown into this issue)

The same happens when I do a visual selection.

Then, when accepting the diff, it overwrites the lines it got wrong which makes it pretty unusable for me.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions