microsoft / vscode

Visual Studio Code
https://code.visualstudio.com
MIT License
164.29k stars 29.31k forks source link

`inlineChat.viewInChat` command from notebook will cause pylance to crash #230172

Open StellaHuang95 opened 1 month ago

StellaHuang95 commented 1 month ago

Does this issue occur when all extensions are disabled?: Yes/No

Steps to Reproduce:

  1. Install Python and Pylance extensions
  2. Open a notebook or create a notebook file with the following content, and press ctrl + i to open the copilot inline chat
    # notebook1.ipynb
    def foo():
    print("foo")
  3. Ask for a code change, then run inlineChat.viewInChat on the response (ctrl+down)Image
  4. Pylance crashes with bad request
    2024-09-30 14:25:21.458 [info] [Error - 2:25:21 PM] Request textDocument/documentSymbol failed.
    2024-09-30 14:25:21.458 [info]   Message: Request textDocument/documentSymbol failed with message: Debug Failure. Notebook file should not be passed to getWorkspaceForFile: vscode-chat-code-block:/c%3A/Users/stellahuang/source/projects/issue6427/notebook1.ipynb?6ff16a3c-1351-4aff-837f-d29e7cb883a7
    Code: -32603

When inspecting the textDocument/documentSymbol request from the Pylance side, I noticed that the DocumentSymbolParams.textDocument.uri = 'vscode-chat-code-block:/c%3A/Users/stellahuang/source/projects/issue6427/notebook1.ipynb?3574a4e6-6692-4217-86b1-0ca8750d25f6'. It looks like the query is for the notebook file itself, not for a specific cell, which seems like a bug.

Related bug opened in Pylance: https://github.com/microsoft/pylance-release/issues/6454

aiday-mar commented 1 month ago

Hi @amunger not sure who to assign this to, please let me know if I should assign to someone else.

StellaHuang95 commented 6 days ago

Is there any update on this issue? Thanks.

amunger commented 5 days ago

That URI is actually for a text document that is independent of the notebook since the schema is vscode-chat-code-block. Is the language server able to use the contents of that document, rather than trying to look for the related notebook?

heejaechang commented 1 day ago

@amunger are you saying we should special casing vscode-chat-code-block? since we support virtual workspace we do not special case any specific schema. we consider it as notebook since it has file extension of ipynb. IMO, if you want people to treat it as text document, it shouldn't have ipynb as file extension.

heejaechang commented 1 day ago

for now, pylance special cased vscode copilot schemas, but it would be nice if uri doesn't has ipynb as file extension.