Skip to content

Commit 5e9a698

Browse files
committed
Merge branch 'sn-console'
2 parents 96ca48f + 08ce6ed commit 5e9a698

12 files changed

+76
-77
lines changed

src/vs/workbench/contrib/languageRuntime/common/languageRuntimeActions.ts

+6
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import * as nls from 'vs/nls';
66
import { generateUuid } from 'vs/base/common/uuid';
77
import { ILocalizedString } from 'vs/platform/action/common/action';
8+
import { ICommandService } from 'vs/platform/commands/common/commands';
89
import { Action2, registerAction2 } from 'vs/platform/actions/common/actions';
910
import { ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
1011
import { IExtensionService } from 'vs/workbench/services/extensions/common/extensions';
@@ -117,6 +118,7 @@ export function registerLanguageRuntimeActions() {
117118
// Registers the start language runtime action.
118119
registerLanguageRuntimeAction('workbench.action.languageRuntime.start', 'Start Language Runtime', async accessor => {
119120
// Access services.
121+
const commandService = accessor.get(ICommandService);
120122
const extensionService = accessor.get(IExtensionService);
121123
const languageRuntimeService = accessor.get(ILanguageRuntimeService);
122124
const quickInputService = accessor.get(IQuickInputService);
@@ -134,7 +136,11 @@ export function registerLanguageRuntimeActions() {
134136
// Ask the user to select the language runtime to start. If they selected one, start it.
135137
const languageRuntime = await selectLanguageRuntime(quickInputService, registeredRuntimes, 'Select the language runtime to start');
136138
if (languageRuntime) {
139+
// Start the language runtime.
137140
languageRuntimeService.startRuntime(languageRuntime.metadata.runtimeId);
141+
142+
// Drive focus into the Positron console.
143+
commandService.executeCommand('workbench.panel.positronConsole.focus');
138144
}
139145
});
140146

src/vs/workbench/contrib/positronConsole/browser/components/consoleRepl.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { useEffect, useRef, useState } from 'react'; // eslint-disable-line no-d
88
import { generateUuid } from 'vs/base/common/uuid';
99
import { DisposableStore } from 'vs/base/common/lifecycle';
1010
import { useStateRef } from 'vs/base/browser/ui/react/useStateRef';
11-
import { IPositronConsoleInstance } from 'vs/workbench/services/positronConsole/common/positronConsole';
11+
import { IPositronConsoleInstance } from 'vs/workbench/services/positronConsole/common/positronConsoleInstance';
1212
import { ConsoleReplItem } from 'vs/workbench/contrib/positronConsole/browser/classes/consoleReplItem';
1313
import { usePositronConsoleContext } from 'vs/workbench/contrib/positronConsole/browser/positronConsoleContext';
1414
import { ConsoleReplItemInput } from 'vs/workbench/contrib/positronConsole/browser/classes/consoleReplItemInput';

src/vs/workbench/contrib/positronConsole/browser/components/consoleReplLiveInput.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ import { SuggestController } from 'vs/editor/contrib/suggest/browser/suggestCont
2222
import { SnippetController2 } from 'vs/editor/contrib/snippet/browser/snippetController2';
2323
import { ContextMenuController } from 'vs/editor/contrib/contextmenu/browser/contextmenu';
2424
import { TabCompletionController } from 'vs/workbench/contrib/snippets/browser/tabCompletion';
25-
import { IPositronConsoleInstance } from 'vs/workbench/services/positronConsole/common/positronConsole';
2625
import { IInputHistoryEntry } from 'vs/workbench/contrib/executionHistory/common/executionHistoryService';
2726
import { SelectionClipboardContributionID } from 'vs/workbench/contrib/codeEditor/browser/selectionClipboard';
2827
import { usePositronConsoleContext } from 'vs/workbench/contrib/positronConsole/browser/positronConsoleContext';
2928
import { RuntimeCodeFragmentStatus } from 'vs/workbench/services/languageRuntime/common/languageRuntimeService';
29+
import { IPositronConsoleInstance } from 'vs/workbench/services/positronConsole/common/positronConsoleInstance';
3030

3131
// ConsoleReplLiveInputProps interface.
3232
export interface ConsoleReplLiveInputProps {

src/vs/workbench/contrib/positronConsole/browser/positronConsole.contribution.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ import { registerIcon } from 'vs/platform/theme/common/iconRegistry';
99
import { SyncDescriptor } from 'vs/platform/instantiation/common/descriptors';
1010
import { ViewPaneContainer } from 'vs/workbench/browser/parts/views/viewPaneContainer';
1111
import { InstantiationType, registerSingleton } from 'vs/platform/instantiation/common/extensions';
12-
import { IPositronConsoleService } from 'vs/workbench/services/positronConsole/common/positronConsole';
1312
import { PositronConsoleViewPane } from 'vs/workbench/contrib/positronConsole/browser/positronConsoleView';
1413
import { PositronConsoleService } from 'vs/workbench/contrib/positronConsole/browser/positronConsoleService';
14+
import { IPositronConsoleService } from 'vs/workbench/services/positronConsole/common/positronConsoleService';
1515
import { registerPositronConsoleActions } from 'vs/workbench/contrib/positronConsole/browser/positronConsoleActions';
1616
import { PositronConsoleCommandId, POSITRON_CONSOLE_VIEW_ID } from 'vs/workbench/contrib/positronConsole/common/positronConsole';
1717
import { ViewContainer, IViewContainersRegistry, ViewContainerLocation, Extensions as ViewContainerExtensions, IViewsRegistry } from 'vs/workbench/common/views';

src/vs/workbench/contrib/positronConsole/browser/positronConsoleActions.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ import { IEditorService } from 'vs/workbench/services/editor/common/editorServic
1515
import { KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegistry';
1616
import { IWorkbenchLayoutService } from 'vs/workbench/services/layout/browser/layoutService';
1717
import { INotificationService, Severity } from 'vs/platform/notification/common/notification';
18-
import { IPositronConsoleService } from 'vs/workbench/services/positronConsole/common/positronConsole';
1918
import { confirmationModalDialog } from 'vs/workbench/browser/positronModalDialogs/confirmationModalDialog';
19+
import { IPositronConsoleService } from 'vs/workbench/services/positronConsole/common/positronConsoleService';
2020
import { IExecutionHistoryService } from 'vs/workbench/contrib/executionHistory/common/executionHistoryService';
2121
import { PositronConsoleCommandId, POSITRON_CONSOLE_ACTION_CATEGORY } from 'vs/workbench/contrib/positronConsole/common/positronConsole';
2222

src/vs/workbench/contrib/positronConsole/browser/positronConsoleInstance.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import { Disposable } from 'vs/base/common/lifecycle';
66
import { Emitter, Event } from 'vs/base/common/event';
77
import { ILanguageRuntime } from 'vs/workbench/services/languageRuntime/common/languageRuntimeService';
8-
import { IPositronConsoleInstance } from 'vs/workbench/services/positronConsole/common/positronConsole';
8+
import { IPositronConsoleInstance } from 'vs/workbench/services/positronConsole/common/positronConsoleInstance';
99

1010
/**
1111
* PositronConsoleInstance class.

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

+3-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ import { Emitter } from 'vs/base/common/event';
66
import { Disposable } from 'vs/base/common/lifecycle';
77
import { ILogService } from 'vs/platform/log/common/log';
88
import { ILanguageService } from 'vs/editor/common/languages/language';
9+
import { IPositronConsoleService } from 'vs/workbench/services/positronConsole/common/positronConsoleService';
910
import { PositronConsoleInstance } from 'vs/workbench/contrib/positronConsole/browser/positronConsoleInstance';
10-
import { IPositronConsoleInstance, IPositronConsoleService } from 'vs/workbench/services/positronConsole/common/positronConsole';
11+
import { IPositronConsoleInstance } from 'vs/workbench/services/positronConsole/common/positronConsoleInstance';
1112
import { formatLanguageRuntime, ILanguageRuntime, ILanguageRuntimeService } from 'vs/workbench/services/languageRuntime/common/languageRuntimeService';
1213

1314
/**
@@ -168,7 +169,7 @@ export class PositronConsoleService extends Disposable implements IPositronConso
168169
this._runningPositronConsoleInstancesByRuntimeId.set(runtime.metadata.runtimeId, positronConsoleInstance);
169170
this._runningPositronConsoleInstancesByLanguageId.set(runtime.metadata.languageId, positronConsoleInstance);
170171

171-
// Fire the onDidStartConsole event.
172+
// Fire the onDidStartPositronConsoleInstance event.
172173
this._onDidStartPositronConsoleInstanceEmitter.fire(positronConsoleInstance);
173174

174175
// When the runtime exits, see if the user wants to restart it.

src/vs/workbench/contrib/positronConsole/browser/positronConsoleState.ts

+8-10
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ import { useStateRef } from 'vs/base/browser/ui/react/useStateRef';
1010
import { ILanguageService } from 'vs/editor/common/languages/language';
1111
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
1212
import { ILanguageRuntimeService } from 'vs/workbench/services/languageRuntime/common/languageRuntimeService';
13+
import { IPositronConsoleService } from 'vs/workbench/services/positronConsole/common/positronConsoleService';
1314
import { IExecutionHistoryService } from 'vs/workbench/contrib/executionHistory/common/executionHistoryService';
14-
import { IPositronConsoleInstance, IPositronConsoleService } from 'vs/workbench/services/positronConsole/common/positronConsole';
15+
import { IPositronConsoleInstance } from 'vs/workbench/services/positronConsole/common/positronConsoleInstance';
1516

1617
/**
1718
* PositronConsoleServices interface. Defines the set of services that are required by the Positron console.
@@ -41,29 +42,26 @@ export interface PositronConsoleState extends PositronConsoleServices {
4142
*/
4243
export const usePositronConsoleState = (services: PositronConsoleServices): PositronConsoleState => {
4344
// Hooks.
44-
const [positronConsoleInstances, setPositronConsoleInstances, refPositronConsoleInstances] = useStateRef<IPositronConsoleInstance[]>([]);
45-
const [currentPositronConsoleInstance, setCurrentPositronConsoleInstance] = useState<IPositronConsoleInstance | undefined>(undefined);
45+
const [positronConsoleInstances, setPositronConsoleInstances, refPositronConsoleInstances] = useStateRef<IPositronConsoleInstance[]>(services.positronConsoleService.positronConsoleInstances);
46+
const [currentPositronConsoleInstance, setCurrentPositronConsoleInstance] = useState<IPositronConsoleInstance | undefined>(positronConsoleInstances.find(_ => _.runtime.metadata.runtimeId === services.positronConsoleService.activePositronConsoleInstance?.runtime.metadata.runtimeId));
4647

4748
// Add event handlers.
4849
useEffect(() => {
4950
// Create a disposable store for the event handlers we'll add.
5051
const disposableStore = new DisposableStore();
5152

52-
// If there are already Positron console instances in the repl service, create their repl instance entries.
53-
services.positronConsoleService.positronConsoleInstances.forEach((positronConsoleInstance, index, positronConsoleInstances) => {
54-
});
55-
56-
// Add the onDidStartConsole event handler.
53+
// Add the onDidStartPositronConsoleInstance event handler.
5754
disposableStore.add(services.positronConsoleService.onDidStartPositronConsoleInstance(positronConsoleInstance => {
5855
setPositronConsoleInstances(positronConsoleInstances => [...positronConsoleInstances, positronConsoleInstance]);
5956
}));
6057

61-
// Add the onDidChangeActiveConsole event handler.
58+
// Add the onDidChangeActivePositronConsoleInstance event handler.
6259
disposableStore.add(services.positronConsoleService.onDidChangeActivePositronConsoleInstance(positronConsoleInstance => {
6360
if (!positronConsoleInstance) {
6461
setCurrentPositronConsoleInstance(undefined);
6562
} else {
66-
setCurrentPositronConsoleInstance(refPositronConsoleInstances.current.find(x => x.runtime.metadata.languageId === positronConsoleInstance.runtime.metadata.languageId));
63+
const positronConsoleInstance = refPositronConsoleInstances.current.find(_ => _.runtime.metadata.languageId === _.runtime.metadata.languageId);
64+
setCurrentPositronConsoleInstance(positronConsoleInstance);
6765
}
6866
}));
6967

src/vs/workbench/contrib/positronConsole/browser/positronConsoleView.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import { IConfigurationService } from 'vs/platform/configuration/common/configur
2222
import { ViewPane, IViewPaneOptions } from 'vs/workbench/browser/parts/views/viewPane';
2323
import { IWorkbenchLayoutService } from 'vs/workbench/services/layout/browser/layoutService';
2424
import { PositronConsole } from 'vs/workbench/contrib/positronConsole/browser/positronConsole';
25-
import { IPositronConsoleService } from 'vs/workbench/services/positronConsole/common/positronConsole';
25+
import { IPositronConsoleService } from 'vs/workbench/services/positronConsole/common/positronConsoleService';
2626
import { ILanguageRuntimeService } from 'vs/workbench/services/languageRuntime/common/languageRuntimeService';
2727
import { IReactComponentContainer, ISize, PositronReactRenderer } from 'vs/base/browser/positronReactRenderer';
2828
import { IExecutionHistoryService } from 'vs/workbench/contrib/executionHistory/common/executionHistoryService';

src/vs/workbench/services/languageRuntime/common/languageRuntime.ts

+4-12
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
import { Emitter } from 'vs/base/common/event';
66
import { ILogService } from 'vs/platform/log/common/log';
7-
import { ICommandService } from 'vs/platform/commands/common/commands';
87
import { ILanguageService } from 'vs/editor/common/languages/language';
98
import { Disposable, IDisposable, toDisposable } from 'vs/base/common/lifecycle';
109
import { InstantiationType, registerSingleton } from 'vs/platform/instantiation/common/extensions';
@@ -69,7 +68,6 @@ export class LanguageRuntimeService extends Disposable implements ILanguageRunti
6968
* @param _logService The log service.
7069
*/
7170
constructor(
72-
@ICommandService private readonly _commandService: ICommandService,
7371
@ILanguageService private readonly _languageService: ILanguageService,
7472
@ILogService private readonly _logService: ILogService
7573
) {
@@ -207,7 +205,6 @@ export class LanguageRuntimeService extends Disposable implements ILanguageRunti
207205
this._runningLanguageRuntimesByLanguageId.delete(runtime.metadata.languageId);
208206
}
209207

210-
211208
// Let listeners know that the runtime state has changed.
212209
const languageRuntimeInfo = this._registeredLanguageRuntimesByRuntimeId.get(runtime.metadata.runtimeId);
213210
if (!languageRuntimeInfo) {
@@ -292,14 +289,6 @@ export class LanguageRuntimeService extends Disposable implements ILanguageRunti
292289

293290
// Start the runtime.
294291
runtime.start().then(languageRuntimeInfo => {
295-
console.log(`Back from start language runtime ${runtime.metadata.languageName}`);
296-
297-
298-
// TODO@softwarenerd - I think this should be moved out of this layer.
299-
// Execute the Focus into Console command using the command service
300-
// to expose the REPL for the new runtime.
301-
this._commandService.executeCommand('workbench.panel.positronConsole.focus');
302-
303292
// Change the active runtime.
304293
this._activeRuntime = runtime;
305294
this._onDidChangeActiveRuntimeEmitter.fire(runtime);
@@ -313,4 +302,7 @@ export class LanguageRuntimeService extends Disposable implements ILanguageRunti
313302
//#region Private Methods
314303
}
315304

316-
registerSingleton(ILanguageRuntimeService, LanguageRuntimeService, InstantiationType.Delayed);
305+
// Instantiate the language runtime service "eagerly", meaning as soon as a consumer depdends on it.
306+
// This fixes an issue where languages are encountered BEFORE the language runtime service has been
307+
// instantiated.
308+
registerSingleton(ILanguageRuntimeService, LanguageRuntimeService, InstantiationType.Eager);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Posit Software, PBC.
3+
*--------------------------------------------------------------------------------------------*/
4+
5+
import { Event } from 'vs/base/common/event';
6+
import { ILanguageRuntime } from 'vs/workbench/services/languageRuntime/common/languageRuntimeService';
7+
8+
/**
9+
* IPositronConsoleInstance interface.
10+
*/
11+
export interface IPositronConsoleInstance {
12+
/**
13+
* Gets the runtime for the Positron console instance.
14+
*/
15+
readonly runtime: ILanguageRuntime;
16+
17+
/**
18+
* The onDidClearConsole event.
19+
*/
20+
readonly onDidClearConsole: Event<void>;
21+
22+
/**
23+
* The onDidClearInputHistory event.
24+
*/
25+
readonly onDidClearInputHistory: Event<void>;
26+
27+
/**
28+
* The onDidExecuteCode event.
29+
*/
30+
readonly onDidExecuteCode: Event<string>;
31+
32+
/**
33+
* Clears the console.
34+
*/
35+
clearConsole(): void;
36+
37+
/**
38+
* Clears the input hstory.
39+
*/
40+
clearInputHistory(): void;
41+
42+
/**
43+
* Executes code in the Positron console instance.
44+
* @param code The code to execute.
45+
*/
46+
executeCode(code: string): void;
47+
}

src/vs/workbench/services/positronConsole/common/positronConsole.ts renamed to src/vs/workbench/services/positronConsole/common/positronConsoleService.ts

+2-47
Original file line numberDiff line numberDiff line change
@@ -4,52 +4,11 @@
44

55
import { Event } from 'vs/base/common/event';
66
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
7-
import { ILanguageRuntime } from 'vs/workbench/services/languageRuntime/common/languageRuntimeService';
7+
import { IPositronConsoleInstance } from 'vs/workbench/services/positronConsole/common/positronConsoleInstance';
88

99
// Create the decorator for the Positron console service (used in dependency injection).
1010
export const IPositronConsoleService = createDecorator<IPositronConsoleService>('positronConsoleService');
1111

12-
/**
13-
* IPositronConsoleInstance interface.
14-
*/
15-
export interface IPositronConsoleInstance {
16-
/**
17-
* Gets the runtime for the Positron console instance.
18-
*/
19-
readonly runtime: ILanguageRuntime;
20-
21-
/**
22-
* The onDidClearConsole event.
23-
*/
24-
readonly onDidClearConsole: Event<void>;
25-
26-
/**
27-
* The onDidClearInputHistory event.
28-
*/
29-
readonly onDidClearInputHistory: Event<void>;
30-
31-
/**
32-
* The onDidExecuteCode event.
33-
*/
34-
readonly onDidExecuteCode: Event<string>;
35-
36-
/**
37-
* Clears the console.
38-
*/
39-
clearConsole(): void;
40-
41-
/**
42-
* Clears the input hstory.
43-
*/
44-
clearInputHistory(): void;
45-
46-
/**
47-
* Executes code in the Positron console instance.
48-
* @param code The code to execute.
49-
*/
50-
executeCode(code: string): void;
51-
}
52-
5312
/**
5413
* IPositronConsoleService interface.
5514
*/
@@ -60,7 +19,7 @@ export interface IPositronConsoleService {
6019
/**
6120
* Gets the Positron console instances.
6221
*/
63-
readonly positronConsoleInstances: readonly IPositronConsoleInstance[];
22+
readonly positronConsoleInstances: IPositronConsoleInstance[];
6423

6524
/**
6625
* Gets the active Positron console instance.
@@ -77,10 +36,6 @@ export interface IPositronConsoleService {
7736
*/
7837
readonly onDidChangeActivePositronConsoleInstance: Event<IPositronConsoleInstance | undefined>;
7938

80-
/**
81-
* Executes code in a PositronConsoleInstance.
82-
*/
83-
8439
/**
8540
* Executes code in a PositronConsoleInstance.
8641
* @param languageId The language ID.

0 commit comments

Comments
 (0)