Repository navigation
Complete notebook cells with the cells round them - #580
Merged
m1ab0t merged 1 commit intoNov 21, 2026
Merged
Conversation
VS Code hands the completion provider each notebook cell as a document of its own, so the window of code round the cursor stopped at the cell's edges. In a Jupyter notebook that is usually most of what matters: the imports, the data frame and the helpers a cell uses were defined in the cells above, and the model, shown only the cell, guessed at them or wrote code in another language altogether (twinnydotdev#430). When the document is a notebook cell, the code cells of the open notebook in that cell's language are now joined in order, a blank line between each, and the prefix and suffix window is cut from that text with the cursor moved to its place in it. Markdown cells and code cells in another language (a SQL cell in a Python notebook) are left out, as they would not read as part of the same code. The usual limits still apply: twinny.contextLength lines, the character caps, and the step-aligned start that lets the server reuse its prompt cache. getPrefixSuffix now takes only the lineCount and getText it reads, so the joined text is passed to it through a small view with the same clamping as a document. The prefetch check uses the same window, so a prefetched completion in a notebook is recognised as on the way. Tests: the view matches a real document for every window and clamped range tried; cells are joined and the cell's first line found, with markdown and other-language cells skipped; and a completion asked in the middle cell of a real jupyter-notebook document is made with the cell above as prefix and the one below as suffix.
Codex Review Summary: ❌ FailedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #430
VS Code passes each notebook cell to the inline completion provider as a separate document, so the code window around the cursor stopped at the cell's edges. In a Jupyter notebook, the imports, data frames and helpers a cell uses usually come from the cells above. With only the cell to go on, the model guessed at them, or wrote code in another language, as in the issue's screenshot.
twinny.contextLengthlines, the prefix and suffix character caps, and the step-aligned window start that keeps the server's prompt cache warm.getPrefixSuffixnow takes only thelineCountandgetTextit actually reads. The joined text reaches it through a small view (textDocumentOf) that clamps positions the same way a document does.notebook.test.ts):jupyter-notebookdocument uses the cell above as its prefix and the cell below as its suffix. This test fails without the change.Checked:
tsc,eslint src, the build andvscode:packageare clean. In the fullnpm testrun, 876 tests passed, and 5Chat edit_file/Agent replytests failed in my headless Linux container. Those 5 fail the same way onmain.npm run test:sqlitepasses.