Skip to content

Smart send is sending too much code, and executing incorrect lines #23696

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

Closed
Yoyokrazy opened this issue Jun 25, 2024 · 6 comments
Closed

Smart send is sending too much code, and executing incorrect lines #23696

Yoyokrazy opened this issue Jun 25, 2024 · 6 comments
Assignees
Labels
area-repl bug Issue identified by VS Code Team member as probable bug

Comments

@Yoyokrazy
Copy link

Testing #23676

my_dict = {
    'key1': 'value1',
    'key2': 'value2',
    'key3': 'value3',
    'key4': 'value4'
}

class MyClass:
    def my_function(self):
        print("Hello, world!")
        print("bye, world!")

    print("asdf, world!")
    print("fghj, world!")

# Create an instance of MyClass
my_instance = MyClass()

# Call the my_function method
my_instance.my_function()
  • shift enter on line 11 (print bye world within my_fn)
  • 🐛 entire class is sent
    • expected: only the print sends

image
image

@github-actions github-actions bot added the triage-needed Needs assignment to the proper sub-team label Jun 25, 2024
@eleanorjboyd
Copy link
Member

dup: #23697

@eleanorjboyd
Copy link
Member

this is kinda the opposite problem but I also found strange, I was on the "return false" line but this line on its own doesn't make much sense? But I am not sure the distinction of when to send whole function vs just the line

Screenshot 2024-06-25 at 10 20 59 AM

@github-actions github-actions bot added the info-needed Issue requires more information from poster label Jun 25, 2024
@eleanorjboyd
Copy link
Member

for this one too it send the whole function when my hover was on line w/ rpc = {

def send_post_request(
    payload: Union[ExecutionPayloadDict, DiscoveryPayloadDict, EOTPayloadDict],
    cls_encoder=None,
):
    """
    Sends a post request to the server.
    Keyword arguments:
    payload -- the payload data to be sent.
    cls_encoder -- a custom encoder if needed.
    """
    if not TEST_RUN_PIPE:
        error_msg = (
            "PYTEST ERROR: TEST_RUN_PIPE is not set at the time of pytest starting. "
            "Please confirm this environment variable is not being changed or removed "
            "as it is required for successful test discovery and execution."
            f"TEST_RUN_PIPE = {TEST_RUN_PIPE}\n"
        )
        print(error_msg, file=sys.stderr)
        raise VSCodePytestError(error_msg)
    global __writer
    if __writer is None:
        try:
            __writer = socket_manager.PipeManager(TEST_RUN_PIPE)
            __writer.connect()
        except Exception as error:
            error_msg = f"Error attempting to connect to extension named pipe {TEST_RUN_PIPE}[vscode-pytest]: {error}"
            print(error_msg, file=sys.stderr)
            print(
                "If you are on a Windows machine, this error may be occurring if any of your tests clear environment variables"
                " as they are required to communicate with the extension. Please reference https://docs.pytest.org/en/stable/how-to/monkeypatch.html#monkeypatching-environment-variables"
                "for the correct way to clear environment variables during testing.\n",
                file=sys.stderr,
            )
            __writer = None
            raise VSCodePytestError(error_msg)
    rpc = {
        "jsonrpc": "2.0",
        "params": payload,
    }
    data = json.dumps(rpc, cls=cls_encoder)
    try:
        if __writer:
            __writer.write(data)
        else:
            print(
                f"Plugin error connection error[vscode-pytest], writer is None \n[vscode-pytest] data: \n{data} \n",
                file=sys.stderr,
            )
    except Exception as error:
        print(
            f"Plugin error, exception thrown while attempting to send data[vscode-pytest]: {error} \n[vscode-pytest] data: \n{data}\n",
            file=sys.stderr,
        )

@anthonykim1 anthonykim1 added area-repl bug Issue identified by VS Code Team member as probable bug and removed triage-needed Needs assignment to the proper sub-team info-needed Issue requires more information from poster labels Jun 25, 2024
@anthonykim1
Copy link

anthonykim1 commented Jun 27, 2024

I think description I provided for smart send can be misleading in this type of "nested" or simple as inside the function or class scenario.

For smart send, we send minimum executable code (as provided by Python Abstract Syntax Tree after parsing your Python file) in a non-nested scenario (expression/statement outside of any higher level code block).

In "nested" scenario, we would send the highest top-level block of code. This allows users to quickly shift+enter throughout their file to run the maximum amount of executable code with the least amount of effort, which is the biggest reasoning behind this smart send and cursor move feature.

So it would be actually as expected to send the entire function,class or other higher level of code block as its a "nested" scenario where block of print statement is effectively living under the higher block of function, and we send the highest level of code block we can find in this nested scenario case as provided by AST. If users decide to run a very specific part/line of code, they can just highlight/explicitly select part of the Python file they want to execute and smart send will not interfere at all.
I will go ahead and make sure to update descriptions on smart send and hopefully make it clear for others.

In the future with: #22558 should make it much more clear what we are sending to smart send via notification/warning of some sort.

this is kinda the opposite problem but I also found strange, I was on the "return false" line but this line on its own doesn't make much sense? But I am not sure the distinction of when to send whole function vs just the line

I will have to investigate on this @eleanorjboyd

@anthonykim1 anthonykim1 closed this as not planned Won't fix, can't repro, duplicate, stale Jun 27, 2024
@anthonykim1
Copy link

Screen.Recording.2024-06-27.at.12.59.21.PM.mov

For me I'm able to get complete function sent when I shift+enter on the return statement. @eleanorjboyd

@eleanorjboyd
Copy link
Member

Great that makes sense thank you! Good explanation and that made it very clear

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 28, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-repl bug Issue identified by VS Code Team member as probable bug
Projects
None yet
Development

No branches or pull requests

3 participants