Closed StellaHuang95 closed 2 months ago
Extract Method on the three lines inside func below does nothing:
def func():
x = 1
y = 2
return x * y
workspace/applyEdit message is:
"jsonrpc": "2.0",
"id": 8,
"method": "workspace/applyEdit",
"params": {
"label": "Command 'pylance.extractMethod'",
"edit": {
"changes": {
"file:///c%3A/Users/stellahuang/source/repos/PythonApplication10/PythonApplication10/PythonApplication10.py": [
{
"range": {
"start": {
"line": 1,
"character": 0
},
"end": {
"line": 1,
"character": 0
}
},
"newText": "def new_func():\n x = 1\n\n"
},
{
"range": {
"start": {
"line": 1,
"character": 0
},
"end": {
"line": 1,
"character": 5
}
},
"newText": "new_func()"
}
]
}
},
"metadata": {
"isRefactoring": true
}
}
so looks like pylance isn't returning the correct edits at the first place.
but the textDocument/codeAction request is sending the wrong range
to pylance, the _vs_selectionRange
has the correct range.
"traceparent": "00-319dc53d5a70fd459c7fa23603b3a7c5-46f9f679959dbc4d-01",
"jsonrpc": "2.0",
"id": 16,
"method": "textDocument/codeAction",
"params": {
"textDocument": {
"uri": "file:///C:/Users/stellahuang/source/repos/PythonApplication10/PythonApplication10/PythonApplication10.py"
},
"range": {
"start": {
"line": 1,
"character": 0
},
"end": {
"line": 1,
"character": 5
}
},
"context": {
"_vs_selectionRange": {
"start": {
"line": 1,
"character": 0
},
"end": {
"line": 2,
"character": 5
}
},
"diagnostics": [],
"triggerKind": 1
}
}
https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1378352
See above for the response from LSP team. It's by design that the range
is always current line in VS. If pylance depends on the range
, we will need to use _vs_selectionRange
instead.
def func(): x = 1 y = 2 return x * y
This is a separate issue, let me file another ticket to track it.
Steps to Reproduce
Expected behavior
Actual behavior