-
Notifications
You must be signed in to change notification settings - Fork 294
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
Jupyter notebook kernel changes not detected to Pylance #6333
Comments
I've noticed this only started happening after I updated vscode when the kernel selector moved from the bottom left to the top right. |
This is because Pylance resolves imports against the active Python interpreter and not whichever kernel the notebook is running against. Pylance doesn't know about the Jupyter kernel AFAIK. Not sure if we've already discussed this, but perhaps when the user changes Python kernels, the Jupyter extension can find the interpreter most closely associated with the new environment if any and set that as the active Python interpreter? |
I didn't realize that there was a big difference between jupyter kernels and python interpreters. My kernel list and interpreter list is identical. |
We should discuss this with the pylance team to see how we resolve this. |
Based on previous meetings, my impression was that you were going to spawn kernel-specific language servers and route jupyter requests though them, rather than the normal LS, avoiding this issue. Has something changed, or have you just had other things on your plate in the meantime? |
We haven't gotten to this and I'm not sure it was entirely clear this was the plan all along. I think if we all met in person we could discuss the downsides/upsides to that approach. There were some worries pylance wouldn't be happy with us spinning up multiple copies of it. |
Crux of problem:
Document selector decides language client to use. Document selector isn't specific enough to pick a different language client based on interpreter. Implementation thoughts: Thought 1:
Thought 2:
Thought 3:
Thought 4:
|
We can't make the document selector specific to only Python files, at least not by extension; the selector needs to be "any and all files marked as python" in order to handle untitled files, scripts wihtout |
After some more discussion, the tentative plan is:
|
Additionally the location for this will likely be in the Jupyter extension (or this npm module: https://github.com/microsoft/vscode-jupyter-lsp-middleware) |
One deal breaker here may be commands; more than one LS shouldn't be registering as the handler for the same commands, but Pylance uses all sorts of commands for various purposes. Starting them up separately may cause VS Code to complain, or certain actions (some completions, quick fixes, our fancier extraction code action) to break. |
Implementation ideas:
|
Another option that we could consider is just making the "real fix" and making the LS notebook aware, at least for LSs that are known to support them. We'd need to spec out the details of how to ask for the kernel's interpreter, figure out how to move the contact doc, and then modify Pylance internally to reconstruct and maybe spawn multiple faked internal workspaces, but that may be the "correct" long term solution. Depends on how hard the above turns out to be in the end, I guess. |
After implementing a language server per notebook, I'm ending up with about 100MBs allocated per notebook running (what pylance on my machine seems to keep in memory). So 10 notebooks open is 1GB of memory reserved. Seems like a lot. It would be a lot less if DocumentSelector could use a function instead of a pattern for matching (then I could have one server per interpreter in use) |
Alternative ideas
|
Expanding on option 5:
Responses come back on wrong client? Wouldn't work if there's some state in the client before calling the middleware. |
Another idea: Create a language server for every interpreter that starts (default to active). public provideCompletionItem(
document: TextDocument,
position: Position,
context: CompletionContext,
token: CancellationToken,
next: ProvideCompletionItemsSignature
) {
if (isMyNotebookCell(document.uri)) {
const newDoc = this.converter.toOutgoingDocument(document);
const newPos = this.converter.toOutgoingPosition(document, position);
const result = next(newDoc, newPos, context, token);
if (isThenable(result)) {
return result.then(this.converter.toIncomingCompletions.bind(this.converter, document));
}
return this.converter.toIncomingCompletions(document, result);
}
} Where Maybe pass isMyNotebookCell into the middleware as a function (so can be applied by jupyter extension which knows the mapping) |
This requires updates to both the jupyter extension and the python extension (python extension was providing notebook intellisense before this change). PR for python is still in progress: microsoft/vscode-python#17734 |
Woo hoo.. |
Hello, folks. I've found a workaround for this issue. I've to configure python.analysis.extraPaths in settings.json of the current project in VSCode: I'm working in a local project with a conda venv enviroment, so the config looks like: *Note.: I'm using VSCode 1.64.2 version. |
In a remote situation, pylance isn't on the remote machine so it doesn't know anything about the remote environment. In that situation pylance only knows about system modules. |
Is this #13907 a worsen regression? Now manual change the interpreter fails to fix it in vscode 1.80 |
Environment data
Expected behaviour
Upon changing the kernel in the top right Pylance should detect module changes and resolve imports
Actual behaviour
Pylance will only detect kernel changes if you change the interpreter via the command palette
Before changing via command palette
After changing
Imports resolve
Steps to reproduce:
Python: Select Interpreter
in the command palette will update PylanceNote: code execution will work as if the venv is selected, but highlighting doesn't.
Another note: I'm sure a lot of my lingo I'm using is incorrect, I'm just starting out :)
The text was updated successfully, but these errors were encountered: