-
Notifications
You must be signed in to change notification settings - Fork 625
fix(amazonq): Previous and subsequent cells are used as context for completion in a Jupyter notebook #7086
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
Conversation
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is helpful, thanks! Tests for this function are here:
aws-toolkit-vscode/packages/amazonq/test/unit/codewhisperer/util/editorContext.test.ts
Line 32 in d457022
describe('extractContextForCodeWhisperer', function () { |
You can run that test file by opening it in vscode then choose Extension tests (current file) (amazon)
in the run/debug menu:

8ca009c
to
5f29d4a
Compare
Will consolidate the function doing the suffix and prefix context fetching. |
5b7ca22
to
76e096a
Compare
packages/amazonq/test/unit/codewhisperer/util/editorContext.test.ts
Outdated
Show resolved
Hide resolved
packages/amazonq/test/unit/codewhisperer/util/editorContext.test.ts
Outdated
Show resolved
Hide resolved
6fc5a9f
to
db49f5d
Compare
lint failure
|
130c19d
to
2650145
Compare
@@ -24,19 +24,130 @@ import { predictionTracker } from '../nextEditPrediction/activation' | |||
|
|||
let tabSize: number = getTabSizeSetting() | |||
|
|||
const languageCommentChars: Record<string, string> = { | |||
python: '# ', | |||
java: '// ', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just noticed this. It's not sustainable for us to introduce yet another language-specific handling just for notebooks. Why isn't the notebook logic using the existing logic used by other Q functionality ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good question! I'm new to this codebase, so I'll have to research what existing logic you are referring to -- any quick pointers of where to start looking are appreciated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Never mind, Q to the rescue -- figured out the changes I needed to make to runtimeLanguageContext
.
2650145
to
a6625ea
Compare
…mpletion in a Jupyter notebook
…mpletion in a Jupyter notebook
Renaming `extractCellsSliceContext` to `getNotebookCellsSliceContext` Co-authored-by: Justin M. Keyes <[email protected]>
a6625ea
to
dbfe86b
Compare
Problem
VS Code treats each cell in a notebook as a separate editor. As a result, when building the left- and right-contexts for the completion from the current editor, we were limited to just the current cell, which might be very small and/or reference variables and functions defined in other cells. That meant that completions never used the context of other cells when making suggestions, and were often very generic. #7031
Solution
The
extractContextForCodeWhisperer
function now checks if it is being called in a cell in a Jupyter notebook. If so, it collects the surrounding cells to use as context, respecting the maximum context length. During this process, Markdown cells have each line prefixed with a language-specific comment character.feature/x
branches will not be squash-merged at release time.