Skip to content

assistant: fix copilot inline completions for ipynb #8498

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

sharon-wang
Copy link
Member

@sharon-wang sharon-wang commented Jul 12, 2025

Summary

Release Notes

Note

TBD if this is a feature or a bugfix 😆

New Features

Bug Fixes

QA Notes

@:assistant

  • inline completions should be available for ipynb files when authenticated with GitHub Copilot
  • the positron.assistant.inlineCompletionExcludes setting should continue to work

@sharon-wang sharon-wang requested a review from timtmok July 12, 2025 02:27
Copy link

github-actions bot commented Jul 12, 2025

E2E Tests 🚀
This PR will run tests tagged with: @:critical @:assistant

readme  valid tags

Comment on lines +220 to +230
return true; // No glob patterns configured, so completions are enabled
}

// Check all of the glob patterns and return true if any match
// Check all of the glob patterns and return false if any match
for (const pattern of globPattern) {
if (glob.match(pattern, uri.path)) {
return true; // File matches an exclusion pattern
return false; // File matches an exclusion pattern, so it is excluded from completions
}
}

return false; // No patterns matched, so the file is not excluded
return true; // No patterns matched, so completions are enabled
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I saw the name of the function areCompletionsEnabled, I expected the function to return true when no globs are provided or matched, but this was returning the opposite.

I inverted the logic here so that the returned value aligns with the function name. Somehow, this seems to resolve the issue with ipynb?? 🧐

Copy link
Contributor

@timtmok timtmok left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still don't get completions in notebooks. It logs an error in the console about the file URI.

ERR Document for URI could not be found: vscode-notebook-cell:/Users/tmok/source/test/Python/notebook.ipynb#W0sZmlsZQ%3D%3D: Error: Document for URI could not be found: vscode-notebook-cell:/Users/tmok/source/test/Python/notebook.ipynb#W0sZmlsZQ%3D%3D

@sharon-wang
Copy link
Member Author

I still don't get completions in notebooks. It logs an error in the console about the file URI.

ERR Document for URI could not be found: vscode-notebook-cell:/Users/tmok/source/test/Python/notebook.ipynb#W0sZmlsZQ%3D%3D: Error: Document for URI could not be found: vscode-notebook-cell:/Users/tmok/source/test/Python/notebook.ipynb#W0sZmlsZQ%3D%3D

Ah I see this error too, but I was signed into both Copilot and Gemini for completions. The completions appeared to work for me, but actually Copilot completions are not working, while Gemini completions seem to be all good.

Investigating the Copilot completions issue... 🔎

@sharon-wang
Copy link
Member Author

This requires more involved investigation than initially thought. I'm going to pause on this while I take a look at some higher priority items. Kicking to Draft -- I'll let you know when this is ready again.


Some notes in the meantime:

  • I don't think Copilot inline completions ever worked for ipynb? Does anyone recall this previously working?
  • The error seems to occur on line 237:
    • async inlineCompletion(
      textDocument: vscode.TextDocument,
      position: vscode.Position,
      context: vscode.InlineCompletionContext,
      token: vscode.CancellationToken
      ): Promise<vscode.InlineCompletionItem[] | vscode.InlineCompletionList | undefined> {
      const client = this.client();
      const params = client.code2ProtocolConverter.asInlineCompletionParams(textDocument, position, context);
      const result = await client.sendRequest(InlineCompletionRequest.type, params, token);
      return client.protocol2CodeConverter.asInlineCompletionResult(result);
      }
  • inline completions work when signed in with Gemini, but not Copilot. The problem seems specific to Copilot completions.

Console logs with some notes from myself and Wasim (ty!)

// debug print right after line 236
*** debug log *** inlineCompletion params: {"context":{"triggerKind":1},"textDocument":{"uri":"vscode-notebook-cell:/Users/sashimi/qa-example-content/workspaces/large_py_notebook/spotify.ipynb#W0sZmlsZQ%3D%3D"},"position":{"line":12,"character":4}} (at console.<anonymous> (file:///Users/sashimi/dev/positron-dev/out/vs/workbench/api/common/extHostConsoleForwarder.js:45:22))
log.ts:464
  • note the URI scheme vscode-notebook-cell and the fragment #W0sZmlsZQ%3D%3D, which differ from "regular" text files which have URI scheme file and no fragment
// error message at line 237, we don't get to a debug print right after line 237
ERR Document for URI could not be found: vscode-notebook-cell:/Users/sashimi/qa-example-content/workspaces/large_py_notebook/spotify.ipynb#W0sZmlsZQ%3D%3D: Error: Document for URI could not be found: vscode-notebook-cell:/Users/sashimi/qa-example-content/workspaces/large_py_notebook/spotify.ipynb#W0sZmlsZQ%3D%3D
	at handleResponse (/Users/sashimi/dev/positron-dev/extensions/positron-assistant/node_modules/vscode-jsonrpc/lib/common/connection.js:565:48)
	at handleMessage (/Users/sashimi/dev/positron-dev/extensions/positron-assistant/node_modules/vscode-jsonrpc/lib/common/connection.js:345:13)
	at processMessageQueue (/Users/sashimi/dev/positron-dev/extensions/positron-assistant/node_modules/vscode-jsonrpc/lib/common/connection.js:362:17)
	at Immediate.<anonymous> (/Users/sashimi/dev/positron-dev/extensions/positron-assistant/node_modules/vscode-jsonrpc/lib/common/connection.js:334:13)
	at process.processImmediate (node:internal/timers:483:21)
	at process.callbackTrampoline (node:internal/async_hooks:130:17)
  • does the language server we're using support URIs with scheme vscode-notebook-cell as vscode.TextDocuments? I noticed there are also vscode.NotebookDocuments and wonder if the distinction is important in this scenario. It seems like completions run through TextDocuments either way though, whether a code file or a notebook.
  • Notebook documents essentially contain metadata for the entire notebook and each cell, and map those cells back to their text document. Each cell is treated as a separate text document.
  • the server does have to inspect notebook documents if it wants to consider prior/other cells when providing completions. The client still shouldn't need any special handling or configuration
  • this error looks like the language server isn't receiving messages from Positron when the text document corresponding to the notebook cell is first opened
    • We could be incorrectly specifying LanguageClientOptions -- so far, nothing in particular sticks out though
// sometimes this error occurs instead of `ERR Document for URI could not be found`
ERR Schema validation failed with the following errors:
- /context/selectedCompletionInfo/range: Expected object
- : Expected all values to match: Error: Schema validation failed with the following errors:
- /context/selectedCompletionInfo/range: Expected object
- : Expected all values to match
  • could we be misspecifying vscode.InlineCompletionContext.selectedCompletionInfo?
  • it's possible client.code2ProtocolConverter.asInlineCompletionParams doesn't work as expected for these more custom/novel LSP parts
  • Maybe the Copilot LS expects us to skip the request if selectedCompletionInfo is undefined?

@sharon-wang sharon-wang marked this pull request as draft July 15, 2025 20:41
@sharon-wang sharon-wang changed the title assistant: invert logic for completions checks to enable completions for ipynb assistant: fix copilot inline completions for ipynb Jul 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants