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

Ctrl+. doesn't work for isort Quick Fix #22

Closed
gregvanl opened this issue Apr 26, 2022 · 3 comments · Fixed by #23
Closed

Ctrl+. doesn't work for isort Quick Fix #22

gregvanl opened this issue Apr 26, 2022 · 3 comments · Fixed by #23
Assignees
Labels
triage-needed Issue is not triaged.

Comments

@gregvanl
Copy link

Testing microsoft/vscode-python#18997

  1. Follow the test plan instructions until you get the red squiggly under the first import.
  2. Put the cursor on the first import.
  3. Press Ctrl+. to show Quick Fixes.

"No code actions available" shown in hover

image

  1. Hover over first import so that you see the Problem text along with link to Quick Fix (Ctrl+.)

image

  1. Try Ctrl+.

Again "No code actions available" hover

@github-actions github-actions bot added the triage-needed Issue is not triaged. label Apr 26, 2022
@karthiknadig karthiknadig transferred this issue from microsoft/vscode-python Apr 27, 2022
@karthiknadig
Copy link
Member

karthiknadig commented Apr 27, 2022

@dbaeumer I need some input here. For this scenario, I think I am sending the correct data for code actions (over LSP) but, VS Code seems to think not. Somehow, the same info is shown on hover.

Request (for ctrl+.):

  {
    "jsonrpc": "2.0",
    "id": 21,
    "method": "textDocument/codeAction",
    "params": {
      "textDocument": {
        "uri": "file:///c%3A/GIT/repros/formatTest/something.py"
      },
      "range": {
        "start": { "line": 0, "character": 3 },
        "end": { "line": 0, "character": 3 }
      },
      "context": { "diagnostics": [] }
    }
  },

Response:

  {
    "jsonrpc": "2.0",
    "id": 21,
    "result": [
      {
        "title": "isort: Organize Imports",
        "kind": "source.organizeImports",
        "edit": null,
        "data": "file:///c%3A/GIT/repros/formatTest/something.py"
      },
      {
        "title": "isort: Fix import sorting and/or formatting",
        "kind": "quickfix",
        "diagnostics": null,
        "edit": null,
        "data": "file:///c%3A/GIT/repros/formatTest/something.py"
      }
    ]
  }

@karthiknadig
Copy link
Member

@dbaeumer For hover it looks like we do get the diagnostics in context, but there is no diagnostic in context for ctrl+..

Request (for hover):

  {
    "jsonrpc": "2.0",
    "id": 31,
    "method": "textDocument/codeAction",
    "params": {
      "textDocument": {
        "uri": "file:///c%3A/GIT/repros/formatTest/something.py"
      },
      "range": {
        "start": { "line": 0, "character": 0 },
        "end": { "line": 0, "character": 0 }
      },
      "context": {
        "diagnostics": [
          {
            "range": {
              "start": { "line": 0, "character": 0 },
              "end": { "line": 0, "character": 0 }
            },
            "message": "Imports are incorrectly sorted and/or formatted.",
            "code": "E",
            "severity": 1,
            "source": "isort"
          }
        ],
        "only": ["quickfix"]
      }
    }
  }

Response:

  {
    "jsonrpc": "2.0",
    "id": 31,
    "result": [
      {
        "title": "isort: Organize Imports",
        "kind": "source.organizeImports",
        "edit": null,
        "data": "file:///c%3A/GIT/repros/formatTest/something.py"
      },
      {
        "title": "isort: Fix import sorting and/or formatting",
        "kind": "quickfix",
        "diagnostics": [
          {
            "range": {
              "start": { "line": 0, "character": 0 },
              "end": { "line": 0, "character": 0 }
            },
            "message": "Imports are incorrectly sorted and/or formatted.",
            "severity": 1,
            "code": "E",
            "source": "isort"
          }
        ],
        "edit": null,
        "data": "file:///c%3A/GIT/repros/formatTest/something.py"
      }
    ]
  }

@karthiknadig
Copy link
Member

Figured out the issue. Range was the problem here. Somehow hover, is able to identify the range. But when using ctrl+. it does not accept the range. Updating the original diagnostic range from "start": { "line": 0, "character": 0 }, "end": { "line": 0, "character": 0 } to "start": { "line": 0, "character": 0 }, "end": { "line": 1, "character": 0 } seems to have fixed the issue.

Should VS Code be handing the range for ctrl+. the same way it does for hover?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
triage-needed Issue is not triaged.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants