Skip to content

Complete notebook cells with the cells round them - #580

Merged
m1ab0t merged 1 commit into
twinnydotdev:devfrom
officialasishkumar:fix/notebook-completion-context
Nov 21, 2026
Merged

m1ab0t merged 1 commit into
twinnydotdev:devfrom
officialasishkumar:fix/notebook-completion-context

Conversation

@officialasishkumar

Copy link
Copy Markdown
Contributor

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.

  • When the document is a notebook cell, the open notebook's code cells in that cell's language are joined in order, with a blank line between each. The prefix and suffix window is cut from that joined text, with the cursor moved to its place in it.
  • Markdown cells and code cells in another language (for example a SQL cell in a Python notebook) are left out, because they wouldn't read as part of the same code.
  • The usual limits still apply: twinny.contextLength lines, the prefix and suffix character caps, and the step-aligned window start that keeps the server's prompt cache warm.
  • getPrefixSuffix now takes only the lineCount and getText it actually reads. The joined text reaches it through a small view (textDocumentOf) that clamps positions the same way a document does.
  • The prefetch check uses the same window, so in a notebook a prefetched completion is still recognised as on the way.
  • Tests (notebook.test.ts):
    • The view gives the same window as a real document at every position tried, and the same text for clamped ranges.
    • Cells are joined and the cell's first line is found, with markdown and other-language cells skipped.
    • A completion in the middle cell of a real jupyter-notebook document 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 and vscode:package are clean. In the full npm test run, 876 tests passed, and 5 Chat edit_file / Agent reply tests failed in my headless Linux container. Those 5 fail the same way on main. npm run test:sqlite passes.

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.
@chatgpt-codex-connector

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-11-19T22:12:33.602367Z
We couldn’t complete this review. Comment @codex review to try again.
8d0ce69 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@m1ab0t
m1ab0t changed the base branch from main to dev November 21, 2026 21:17
@m1ab0t
m1ab0t merged commit 59a3ce6 into twinnydotdev:dev Nov 21, 2026
1 check passed
@m1ab0t m1ab0t mentioned this pull request Nov 21, 2026
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.

Completions in Jupyter include only the current cell

2 participants