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

error squiggle when using %pip in interactive window #2894

Closed
amunger opened this issue Jun 6, 2022 · 19 comments
Closed

error squiggle when using %pip in interactive window #2894

amunger opened this issue Jun 6, 2022 · 19 comments
Assignees
Labels
bug Something isn't working fixed in next version (main) A fix has been implemented and will appear in an upcoming version P1

Comments

@amunger
Copy link

amunger commented Jun 6, 2022

enter %pip install torch into the IW input box

image

@amunger amunger added the bug Something isn't working label Jun 6, 2022
@greazer greazer removed triage-needed bug Something isn't working labels Jun 6, 2022
@greazer greazer transferred this issue from microsoft/vscode-jupyter Jun 6, 2022
@github-actions github-actions bot added the triage label Jun 6, 2022
@greazer
Copy link
Member

greazer commented Jun 6, 2022

We think this may be due to pylance not realizing that the IW input box is part of a "notebook". The "pylance lsp notebooks" setting was on.

@debonte debonte self-assigned this Jun 6, 2022
@judej judej added the needs investigation Could be an issue - needs investigation label Jun 7, 2022
@github-actions github-actions bot removed the triage label Jun 7, 2022
@debonte
Copy link
Contributor

debonte commented Jun 9, 2022

When LSP notebooks are enabled, the _isNotebookCell check in NotebookHandler.handleOpen returns false and therefore we set ipythonMode to false for the interactive window document.

Should we be getting a notebookDocument/didOpen instead of a textDocument/didOpen?

@debonte debonte added bug Something isn't working P1 lsp notebooks and removed needs investigation Could be an issue - needs investigation labels Jun 9, 2022
@rchiodo
Copy link
Contributor

rchiodo commented Jun 9, 2022

No _isNotebookCell is actually wrong or should be updated to also include the interactive cell scheme.

@rchiodo rchiodo closed this as completed Jun 9, 2022
@rchiodo rchiodo reopened this Jun 9, 2022
@debonte
Copy link
Contributor

debonte commented Jun 9, 2022

lsp-notebook-concat's isNotebookCell implementation already returns true for the interactive window, which is why this works correctly when the LSP notebooks experiment is disabled. However, when the experiment is enabled we don't call that function. Instead, we assume that only notebook documents (i.e. notebookDocument/didOpen) are notebooks.

Maybe for textDocument/didOpen we should call lsp-notebook-concat's isNotebookCell to determine the right value for the parser's ipythonMode boolean.

@debonte
Copy link
Contributor

debonte commented Jun 10, 2022

@rchiodo, are you planning to have the interactive window be treated as a notebook document from LSP's perspective at some point in the future?

I could fix the %magic issue, but that's not the only problem when the LSP notebooks experiment is enabled. Since the interactive window cells are passed as individual text documents, Pylance doesn't chain them together as we do for notebook cells. And therefore IntelliSense, hover, semantic coloring, go to def, etc don't work when working with symbols defined in earlier cells.

image

@rchiodo
Copy link
Contributor

rchiodo commented Jun 10, 2022

Sounds like a bug in the LSP client if it isn't already behaving this way.

With the old middleware solution, the interactive window was treated just like a notebook. I concatenated all of the cells (including the special one at the bottom) into the concatenated document.

This would need to happen in the new way too.

@debonte
Copy link
Contributor

debonte commented Jun 10, 2022

Ok, I'll take a look at the LSP code.

Earlier I asked:

Should we be getting a notebookDocument/didOpen instead of a textDocument/didOpen?

And your reply was "No..." so I thought you were saying this was expected at the moment.

@rchiodo
Copy link
Contributor

rchiodo commented Jun 10, 2022

I would expect that the interactive window will have to be treated special in the language client. It's internally a notebook and separate text document, so unless Dirk pieced them together, the language client probably doesn't know about it.

@debonte
Copy link
Contributor

debonte commented Jun 10, 2022

so unless Dirk pieced them together, the language client probably doesn't know about it

Is the interactive window a Python-specific feature? I'm wondering if it is generic enough that Dirk would be willing to handle this in vscode-languageclient or if Pylance should special-case it.

For IW cells (not the input box), part of the problem in my screenshot above was that Pylance's notebookSelector only requested notifications about Jupyter notebooks. Fixing that got hover and semantic highlighting working, but go to definition is still broken (opens the target cell in a new tab).

@dbaeumer
Copy link
Member

The notebook support in LSP syncs notebooks and not individual cells. Piecing this together might be complicated for me since currently a cell text document is referenced by notebook cell. when syncing things.

It sounds like that the interactive windows is visually part of a notebook. Why can't it be a notebook cell as well with a special language id. The you could simply use a special notebook selector (https://github.com/microsoft/vscode-languageserver-node/blob/12900cfb006ce56360e3f64feaeff9c0224854a1/protocol/src/common/protocol.notebook.ts#L312) and everything should work.

@rchiodo
Copy link
Contributor

rchiodo commented Jun 10, 2022

Why can't it be a notebook cell as well with a special language id.

It has a specific scheme associated with it. So I believe if the selector was updated to include the interactive input scheme it might include that document as part of a notebook.

Here's the two schemes in use for 'cells' in an interactive window:

export const InteractiveInputScheme = 'vscode-interactive-input';
export const InteractiveScheme = 'vscode-interactive';

The interactive window isn't tied to a specific language (we've just only used it for python so for).

@debonte
Copy link
Contributor

debonte commented Jun 10, 2022

It's not currently included because cells are expected to have the vscode-notebook-cell scheme. The LSP notebooks feature supports notebook documents with custom schemes, but not cells with custom schemes.

Here's the two schemes in use for 'cells' in an interactive window:

export const InteractiveInputScheme = 'vscode-interactive-input';
export const InteractiveScheme = 'vscode-interactive';

To clarify, vscode-interactive is the scheme of the notebook document. The non-input cells use vscode-notebook-cell.

@debonte
Copy link
Contributor

debonte commented Jun 10, 2022

@dbaeumer, here's a picture of the Interactive Window in case you're not familiar with it. When the user clicks the triangular "Execute Code" button to the left of the input box, the text in the input box is removed and placed in a new cell at the bottom of the notebook.

image

@dbaeumer
Copy link
Member

LSP has no knowledge about the scheme that the editor uses to sync notebooks. Even the VS Code implementations has only little knowledge and mostly only for performance reasons (to not generate unnecessary events). This was done that way since IMO a client shouldn't make any assumption about the cell schema. VS Code should have the freedom to change it. And a server should never ever know which schema an editor uses to identify a notebook cell.

The way how LSP communicates with VS Code is basically by using the extended document selector syntax specified via the VS Code API (https://github.com/microsoft/vscode/blob/5bb16df4b0dea028da65676ef28045e70d151157/src/vscode-dts/vscode.d.ts#L2166). To make the interactive Window work I recommend that you use a standard cell and use a special language mode for the interactive cell. Then every code path in VS Code and LSP client / server will work as expected.

May I ask how you get that cell with a different schema into the editor in the first place. I was always under the assumption that VS Code manages all these cells?

@rchiodo
Copy link
Contributor

rchiodo commented Jun 13, 2022

May I ask how you get that cell with a different schema into the editor in the first place. I was always under the assumption that VS Code manages all these cells?

VS code does manage the entire interactive window. None of this is created in the extension. It's the one that knows about the schema. We can't change the language as we don't create it.

@dbaeumer
Copy link
Member

OK. Now I see. Then I think either VS Code should use a consistent schema or the schema needs to be handles correctly in the document filter code.

@debonte
Copy link
Contributor

debonte commented Jun 16, 2022

We're still discussing how to properly fix this, but a temporary workaround will be available in our next release.

@debonte
Copy link
Contributor

debonte commented Jul 23, 2022

A more correct fix has been checked in and in coming days can be tested with:

  • Jupyter 2022.7.1002051049 or later
  • Python <tonight's build> or later
  • Pylance 2022.7.51 or later (should be available Wednesday 7/27)

@debonte debonte added the fixed in next version (main) A fix has been implemented and will appear in an upcoming version label Jul 23, 2022
@heejaechang
Copy link
Contributor

This issue has been fixed in version 2022.7.42, which we've just released. You can find the changelog here: CHANGELOG.md

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fixed in next version (main) A fix has been implemented and will appear in an upcoming version P1
Projects
None yet
Development

No branches or pull requests

7 participants