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

basedpyright cannot execute code action #1117

Open
Ziqi-Yang opened this issue Nov 28, 2024 · 5 comments
Open

basedpyright cannot execute code action #1117

Ziqi-Yang opened this issue Nov 28, 2024 · 5 comments
Labels
help wanted Extra attention is needed

Comments

@Ziqi-Yang
Copy link

For better debugging this issue, I only enabled basedpyright single language server.

Example python code:
image

When I run lsp-bridge-code-action command on reverse, it prompts me with this warning:

Please move cursor to error or warning, then execute 'lsp-bridge-code-action' again.

lsp bridge log:

--- [10:31:49.325362] Send textDocument/codeAction request (15740) to 'basedpyright' for project by6pms
{
   "id": 15740,
   "method": "textDocument/codeAction",
   "params": {
      "range": {
         "start": {
            "line": 40,
            "character": 15
         },
         "end": {
            "line": 40,
            "character": 22
         }
      },
      "context": {
         "diagnostics": [
            {
               "range": {
                  "start": {
                     "line": 40,
                     "character": 15
                  },
                  "end": {
                     "line": 40,
                     "character": 22
                  }
               },
               "message": "\"reverse\" is not defined",
               "severity": 1,
               "code": "reportUndefinedVariable",
               "source": "basedpyright",
               "codeDescription": {
                  "href": "https://docs.basedpyright.com/v1.21.1/configuration/config-files/#reportUndefinedVariable"
               },
               "server-name": "basedpyright"
            }
         ]
      },
      "textDocument": {
         "uri": "file:///home/meowking/proj/web/by6pms/apps/project/api/lib.py"
      }
   },
   "jsonrpc": "2.0"
}

--- [10:31:50.390402] Recv textDocument/codeAction response (15740) from 'basedpyright' for project by6pms

--- [10:31:50.390500] Record actions from 'basedpyright' for file lib.py
Eval in Emacs: (message '"[LSP-Bridge] Please move cursor to error or warning, then execute 'lsp-bridge-code-action' again.")
{
   "jsonrpc": "2.0",
   "id": 15740,
   "result": []
}

However, when I use eglot, I can see the code action list and execute them successfully. Here is the eglot log (beautified json):

[jsonrpc] e[10:29:00.845] --> textDocument/codeAction[17] 
{
  "jsonrpc": "2.0",
  "id": 17,
  "method": "textDocument/codeAction",
  "params": {
    "textDocument": {
      "uri": "file:///home/meowking/proj/web/by6pms/apps/project/api/lib.py"
    },
    "range": {
      "start": {
        "line": 40,
        "character": 15
      },
      "end": {
        "line": 40,
        "character": 22
      }
    },
    "context": {
      "diagnostics": [
        {
          "range": {
            "start": {
              "line": 40,
              "character": 15
            },
            "end": {
              "line": 40,
              "character": 22
            }
          },
          "message": "\"reverse\" is not defined",
          "severity": 1,
          "code": "reportUndefinedVariable",
          "source": "basedpyright",
          "codeDescription": {
            "href": "https://docs.basedpyright.com/v1.21.1/configuration/config-files/#reportUndefinedVariable"
          }
        }
      ]
    }
  }
}

[jsonrpc] e[10:29:00.856]   <-- textDocument/codeAction[17] 
{
  "jsonrpc": "2.0",
  "id": 17,
  "result": [
    {
      "title": "from django.urls import reverse",
      "edit": {
        "changes": {
          "file:///home/meowking/proj/web/by6pms/apps/project/api/lib.py": [
            {
              "range": {
                "start": {
                  "line": 40,
                  "character": 15
                },
                "end": {
                  "line": 40,
                  "character": 22
                }
              },
              "newText": "reverse"
            },
            {
              "range": {
                "start": {
                  "line": 0,
                  "character": 0
                },
                "end": {
                  "line": 0,
                  "character": 0
                }
              },
              "newText": "from django.urls import reverse\n"
            }
          ]
        }
      },
      "kind": "quickfix"
    },
    {
      "title": "from django.urls.base import reverse",
      "edit": {
        "changes": {
          "file:///home/meowking/proj/web/by6pms/apps/project/api/lib.py": [
            {
              "range": {
                "start": {
                  "line": 40,
                  "character": 15
                },
                "end": {
                  "line": 40,
                  "character": 22
                }
              },
              "newText": "reverse"
            },
            {
              "range": {
                "start": {
                  "line": 0,
                  "character": 0
                },
                "end": {
                  "line": 0,
                  "character": 0
                }
              },
              "newText": "from django.urls.base import reverse\n"
            }
          ]
        }
      },
      "kind": "quickfix"
    },
    {
      "title": "from django.views.generic.base import reverse",
      "edit": {
        "changes": {
          "file:///home/meowking/proj/web/by6pms/apps/project/api/lib.py": [
            {
              "range": {
                "start": {
                  "line": 40,
                  "character": 15
                },
                "end": {
                  "line": 40,
                  "character": 22
                }
              },
              "newText": "reverse"
            },
            {
              "range": {
                "start": {
                  "line": 0,
                  "character": 0
                },
                "end": {
                  "line": 0,
                  "character": 0
                }
              },
              "newText": "from django.views.generic.base import reverse\n"
            }
          ]
        }
      },
      "kind": "quickfix"
    }
  ]
}
@manateelazycat
Copy link
Owner

Can you give me code for test ?

@Ziqi-Yang
Copy link
Author

OK. Here is the example test code (whole file):

if __name__ == '__main__':
    print(os.listdir("."))

os should be marked as error.
Instruction: run lsp-bridge-code-action on os symbol.

Thank you!

@manateelazycat
Copy link
Owner

image

I have test it, works fine.

@Ziqi-Yang
Copy link
Author

I have test it, works fine.

From your image, it seems like you are using ruff as the action backend (as defined in basedpyright_ruff multiserver configuration), not the basedpyright as the action backend.

@manateelazycat
Copy link
Owner

Yes, I just use ruff as code_action backend, haven't test basedpyright's code_action, sorry, too busy recently.

@manateelazycat manateelazycat added the help wanted Extra attention is needed label Dec 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants