Skip to content

Commit c662af0

Browse files
committed
Add code location to execute() method of language runtimes
1 parent 2077eb3 commit c662af0

File tree

6 files changed

+45
-10
lines changed

6 files changed

+45
-10
lines changed

src/positron-dts/positron.d.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1079,12 +1079,16 @@ declare module 'positron' {
10791079
* @param id The ID of the code
10801080
* @param mode The code execution mode
10811081
* @param errorBehavior The code execution error behavior
1082+
* @param location Optionally, the location of `code` in the source editor.
10821083
* Note: The errorBehavior parameter is currently ignored by kernels
10831084
*/
1084-
execute(code: string,
1085+
execute(
1086+
code: string,
10851087
id: string,
10861088
mode: RuntimeCodeExecutionMode,
1087-
errorBehavior: RuntimeErrorBehavior): void;
1089+
errorBehavior: RuntimeErrorBehavior,
1090+
codeLocation?: vscode.Location,
1091+
): void;
10881092

10891093
/**
10901094
* Shut down the runtime; returns a Thenable that resolves when the

src/vs/workbench/api/browser/positron/mainThreadLanguageRuntime.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ import { IPositronVariablesInstance } from '../../../services/positronVariables/
5252
import { isWebviewPreloadMessage, isWebviewReplayMessage } from '../../../services/positronIPyWidgets/common/webviewPreloadUtils.js';
5353
import { IOpenerService } from '../../../../platform/opener/common/opener.js';
5454
import { ActiveRuntimeSessionMetadata, LanguageRuntimeDynState } from 'positron';
55+
import { Location } from '../../../../editor/common/languages.js';
5556

5657
/**
5758
* Represents a language runtime event (for example a message or state change)
@@ -461,9 +462,24 @@ class ExtHostLanguageRuntimeSessionAdapter extends Disposable implements ILangua
461462
return this._proxy.$openResource(this.handle, resource);
462463
}
463464

464-
execute(code: string, id: string, mode: RuntimeCodeExecutionMode, errorBehavior: RuntimeErrorBehavior): void {
465+
execute(
466+
code: string,
467+
id: string,
468+
mode: RuntimeCodeExecutionMode,
469+
errorBehavior: RuntimeErrorBehavior,
470+
attribution?: IConsoleCodeAttribution,
471+
): void {
465472
this._lastUsed = Date.now();
466-
this._proxy.$executeCode(this.handle, code, id, mode, errorBehavior);
473+
474+
let codeLocation: Location | undefined = undefined;
475+
476+
// For now we only provide source locations for scripts, but we might be
477+
// able to provide it for notebooks as well
478+
if (attribution?.source === CodeAttributionSource.Script) {
479+
codeLocation = attribution.metadata?.codeLocation;
480+
}
481+
482+
this._proxy.$executeCode(this.handle, code, id, mode, errorBehavior, codeLocation);
467483
}
468484

469485
isCodeFragmentComplete(code: string): Thenable<RuntimeCodeFragmentStatus> {

src/vs/workbench/api/common/positron/extHost.positron.protocol.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { PlotRenderSettings } from '../../../services/positronPlots/common/posit
1919
import { QueryTableSummaryResult, Variable } from '../../../services/languageRuntime/common/positronVariablesComm.js';
2020
import { ILanguageRuntimeCodeExecutedEvent } from '../../../services/positronConsole/common/positronConsoleCodeExecution.js';
2121
import { IPositronChatProvider } from '../../../contrib/chat/common/languageModels.js';
22+
import { Location } from '../../../../editor/common/languages.js';
2223

2324
// NOTE: This check is really to ensure that extHost.protocol is included by the TypeScript compiler
2425
// as a dependency of this module, and therefore that it's initialized first. This is to avoid a
@@ -76,7 +77,7 @@ export interface ExtHostLanguageRuntimeShape {
7677
$disposeLanguageRuntime(handle: number): Promise<void>;
7778
$startLanguageRuntime(handle: number): Promise<ILanguageRuntimeInfo>;
7879
$openResource(handle: number, resource: URI | string): Promise<boolean>;
79-
$executeCode(handle: number, code: string, id: string, mode: RuntimeCodeExecutionMode, errorBehavior: RuntimeErrorBehavior, executionId?: string): void;
80+
$executeCode(handle: number, code: string, id: string, mode: RuntimeCodeExecutionMode, errorBehavior: RuntimeErrorBehavior, codeLocation?: Location, executionId?: string): void;
8081
$isCodeFragmentComplete(handle: number, code: string): Promise<RuntimeCodeFragmentStatus>;
8182
$createClient(handle: number, id: string, type: RuntimeClientType, params: any, metadata?: any): Promise<void>;
8283
$listClients(handle: number, type?: RuntimeClientType): Promise<Record<string, string>>;

src/vs/workbench/api/common/positron/extHostLanguageRuntime.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import type * as positron from 'positron';
77
import { debounce } from '../../../../base/common/decorators.js';
88
import { ILanguageRuntimeMessage, ILanguageRuntimeMessageCommClosed, ILanguageRuntimeMessageCommData, ILanguageRuntimeMessageCommOpen, ILanguageRuntimeMessageStream, ILanguageRuntimeMessageOutput, ILanguageRuntimeMessageState, ILanguageRuntimeMetadata, LanguageRuntimeSessionMode, RuntimeCodeExecutionMode, RuntimeCodeFragmentStatus, RuntimeErrorBehavior, RuntimeState, ILanguageRuntimeMessageResult, ILanguageRuntimeMessageError, RuntimeOnlineState } from '../../../services/languageRuntime/common/languageRuntimeService.js';
99
import * as extHostProtocol from './extHost.positron.protocol.js';
10+
import * as typeConverters from '../extHostTypeConverters.js';
1011
import { Emitter } from '../../../../base/common/event.js';
1112
import { DisposableStore, IDisposable } from '../../../../base/common/lifecycle.js';
1213
import { Disposable, LanguageRuntimeMessageType } from '../extHostTypes.js';
@@ -23,6 +24,7 @@ import { generateUuid } from '../../../../base/common/uuid.js';
2324
import { CancellationToken } from '../../../../base/common/cancellation.js';
2425
import { QueryTableSummaryResult, Variable } from '../../../services/languageRuntime/common/positronVariablesComm.js';
2526
import { ILanguageRuntimeCodeExecutedEvent } from '../../../services/positronConsole/common/positronConsoleCodeExecution.js';
27+
import { Location } from '../../../../editor/common/languages.js';
2628

2729
/**
2830
* Interface for code execution observers
@@ -774,11 +776,17 @@ export class ExtHostLanguageRuntime implements extHostProtocol.ExtHostLanguageRu
774776
return Promise.resolve(this._runtimeSessions[handle].openResource!(resource));
775777
}
776778

777-
$executeCode(handle: number, code: string, id: string, mode: RuntimeCodeExecutionMode, errorBehavior: RuntimeErrorBehavior): void {
779+
$executeCode(handle: number, code: string, id: string, mode: RuntimeCodeExecutionMode, errorBehavior: RuntimeErrorBehavior, codeLocation?: Location): void {
778780
if (handle >= this._runtimeSessions.length) {
779781
throw new Error(`Cannot execute code: session handle '${handle}' not found or no longer valid.`);
780782
}
781-
this._runtimeSessions[handle].execute(code, id, mode, errorBehavior);
783+
784+
let codeLocationConverted = undefined;
785+
if (codeLocation) {
786+
codeLocationConverted = typeConverters.Location.to(codeLocation);
787+
}
788+
789+
this._runtimeSessions[handle].execute(code, id, mode, errorBehavior, codeLocationConverted);
782790
}
783791

784792
$isCodeFragmentComplete(handle: number, code: string): Promise<RuntimeCodeFragmentStatus> {

src/vs/workbench/services/positronConsole/browser/positronConsoleService.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3048,7 +3048,9 @@ class PositronConsoleInstance extends Disposable implements IPositronConsoleInst
30483048
code,
30493049
id,
30503050
mode,
3051-
errorBehavior);
3051+
errorBehavior,
3052+
attribution,
3053+
);
30523054

30533055
// Create and fire the onDidExecuteCode event.
30543056
const event: ILanguageRuntimeCodeExecutedEvent = {

src/vs/workbench/services/runtimeSession/common/runtimeSessionService.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { ILanguageRuntimeMetadata, LanguageRuntimeSessionMode, ILanguageRuntimeS
1111
import { RuntimeClientType, IRuntimeClientInstance } from '../../languageRuntime/common/languageRuntimeClientInstance.js';
1212
import { IDisposable } from '../../../../base/common/lifecycle.js';
1313
import { ActiveRuntimeSession } from './activeRuntimeSession.js';
14+
import { IConsoleCodeAttribution } from '../../positronConsole/common/positronConsoleCodeExecution.js';
1415

1516
export const IRuntimeSessionService =
1617
createDecorator<IRuntimeSessionService>('runtimeSessionService');
@@ -179,10 +180,13 @@ export interface ILanguageRuntimeSession extends IDisposable {
179180
openResource(resource: URI | string): Thenable<boolean>;
180181

181182
/** Execute code in the runtime */
182-
execute(code: string,
183+
execute(
184+
code: string,
183185
id: string,
184186
mode: RuntimeCodeExecutionMode,
185-
errorBehavior: RuntimeErrorBehavior): void;
187+
errorBehavior: RuntimeErrorBehavior,
188+
attribution?: IConsoleCodeAttribution,
189+
): void;
186190

187191
/** Test a code fragment for completeness */
188192
isCodeFragmentComplete(code: string): Thenable<RuntimeCodeFragmentStatus>;

0 commit comments

Comments
 (0)