Closed gregvanl closed 2 years ago
@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"
}
]
}
@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"
}
]
}
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?
Testing microsoft/vscode-python#18997
"No code actions available" shown in hover
Again "No code actions available" hover