Include code locations in execute requests #10815
Open
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.
This PR introduces new optional Positron-specific fields in Jupyter execute requests that contain source editor information (URI and range). This will be used by Ark to map source references to their original locations in editors. The information will also be used to figure out whether the executed code has a breakpoint in range, and inject it in that case.
Approach:
The
workbench.action.positronConsole.executeCodeaction now addscodeLocationas metadata forCodeAttributionof kindScript, in case of a statement range request or of a selection request.On the main thread side,
executemethods take aCodeAttribution. This code attribution is converted to avscode.Location(wrapper aroundUriandRange) before being passed to runtime'sexecute()methods on the extension host side.For consistency, the cursor location included as metadata for Script attributions was refactored to a
vscode.Locationwith an empty range. I was really looking for a version ofLocationthat wraps aPositioninstead of aRangeso that the type itself encodes the invariant of a position, but this doesn't exist and using aLocationto send positions seems to be the established way in the VSC codebase.JupyterExecuteRequestgains apositronfield. The name of that field is consistent with our existing extensions, e.g. for a language_info response.The message extension introduces LSP/VSCode-like
PositionandRangedata structures, which means they are based on a pair ofline/characteroffsets. Compared to simple offsets in a document, which are simpler in some aspects, this approach has the advantages of side stepping any line endings issues, and of being more immediately ingestible by backends that implement an LSP.The main difference with the LSP data structures is that the
characteroffset is in terms of encoding-agnostic Unicode points rather than UTF-16 offsets as in the LSP spec. This is to be consistent with how offsets are documented in the Jupyter protocol: https://jupyter-client.readthedocs.io/en/stable/messaging.html#cursor-pos-unicode-note.Release Notes
New Features
Bug Fixes
QA Notes
Should incur no visible changes to tests and UX.