Skip to content
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

Extract Method on multiple lines inside of a function does nothing #7875

Open
StellaHuang95 opened this issue Apr 17, 2024 · 1 comment
Open
Assignees
Labels

Comments

@StellaHuang95
Copy link
Contributor

Extract Method on the three lines inside func below does nothing:

def func():
    x = 1
    y = 2
    return x * y
@StellaHuang95
Copy link
Contributor Author

textDocument/codeAction:

rawjson	{
  "jsonrpc": "2.0",
  "id": 135,
  "result": [
    {
      "title": "Extract method",
      "command": {
        "title": "Extract method",
        "command": "pylance.extractMethod",
        "arguments": [
          "file:///c%3A/Users/stellahuang/source/repos/PythonApplication13/PythonApplication13/PythonApplication13.py",
          {
            "start": {
              "line": 1,
              "character": 4
            },
            "end": {
              "line": 3,
              "character": 16
            }
          }
        ]
      },
      "kind": "refactor.extract.method"
    }
  ]
}

workspace/applyEdit request:

rawjson	{
  "jsonrpc": "2.0",
  "id": 16,
  "method": "workspace/applyEdit",
  "params": {
    "label": "Command 'pylance.extractMethod'",
    "edit": {
      "changes": {
        "file:///c%3A/Users/stellahuang/source/repos/PythonApplication13/PythonApplication13/PythonApplication13.py": [
          {
            "range": {
              "start": {
                "line": 1,
                "character": 4
              },
              "end": {
                "line": 3,
                "character": 16
              }
            },
            "newText": "return new_func()"
          },
          {
            "range": {
              "start": {
                "line": 3,
                "character": 17
              },
              "end": {
                "line": 3,
                "character": 17
              }
            },
            "newText": "\n\ndef new_func():\n    x = 1\n    y = 2\n    return x * y"
          }
        ]
      }
    },
    "metadata": {
      "isRefactoring": true
    }
  }
}

workspace/applyEdit response

result.failurereason	Exception while applying edits: System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values.
Parameter name: position
   at Microsoft.VisualStudio.Text.SnapshotPoint..ctor(ITextSnapshot snapshot, Int32 position)
   at Microsoft.VisualStudio.Text.SnapshotPoint.Add(Int32 offset)
   at Microsoft.VisualStudio.LanguageServer.Client.Utilities.GetSnapshotPositionFromProtocolPosition(ITextSnapshot textSnapshot, Position position)
   at Microsoft.VisualStudio.LanguageServer.Client.WorkspaceEditBroker.ApplyTextEdit(TextEdit textEdit, ITextSnapshot snapshot, ITextEdit vsTextEdit)
   at Microsoft.VisualStudio.LanguageServer.Client.WorkspaceEditBroker.ApplyTextEditsToBuffer(IEnumerable`1 textEdits, ITextSnapshot snapshot, EditOptions editOptions, ITextBuffer textBuffer)
   at Microsoft.VisualStudio.LanguageServer.Client.WorkspaceEditBroker.ApplySingleEdit(Uri uri, Nullable`1 version, IEnumerable`1 textEdits, IDocumentLanguageServiceClient currentDocumentClient, EditOptions editOptions, CancellationToken cancellationToken)
   at Microsoft.VisualStudio.LanguageServer.Client.WorkspaceEditBroker.ApplyDocumentEdit(TextDocumentEdit textDocumentEdit, ILanguageServiceClient languageClient, ApplyWorkspaceEditResponse response, EditOptions editOptions, CancellationToken cancellationToken)
   at Microsoft.VisualStudio.LanguageServer.Client.WorkspaceEditBroker.ApplyWorkspaceEdit(WorkspaceEdit workspaceEdit, ILanguageServiceClient languageClient, CancellationToken cancellationToken)
   at Microsoft.VisualStudio.LanguageServer.Client.WorkspaceEditBroker.<ApplyWorkspaceEditAsync>d__6.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.VisualStudio.LanguageServer.Client.RemoteLanguageTarget.<OnWorkspaceApplyEditAsync>d__19.MoveNext()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant