@@ -10,8 +10,9 @@ import { useStateRef } from 'vs/base/browser/ui/react/useStateRef';
10
10
import { ILanguageService } from 'vs/editor/common/languages/language' ;
11
11
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation' ;
12
12
import { ILanguageRuntimeService } from 'vs/workbench/services/languageRuntime/common/languageRuntimeService' ;
13
+ import { IPositronConsoleService } from 'vs/workbench/services/positronConsole/common/positronConsoleService' ;
13
14
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 ' ;
15
16
16
17
/**
17
18
* PositronConsoleServices interface. Defines the set of services that are required by the Positron console.
@@ -41,29 +42,26 @@ export interface PositronConsoleState extends PositronConsoleServices {
41
42
*/
42
43
export const usePositronConsoleState = ( services : PositronConsoleServices ) : PositronConsoleState => {
43
44
// 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 ) ) ;
46
47
47
48
// Add event handlers.
48
49
useEffect ( ( ) => {
49
50
// Create a disposable store for the event handlers we'll add.
50
51
const disposableStore = new DisposableStore ( ) ;
51
52
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.
57
54
disposableStore . add ( services . positronConsoleService . onDidStartPositronConsoleInstance ( positronConsoleInstance => {
58
55
setPositronConsoleInstances ( positronConsoleInstances => [ ...positronConsoleInstances , positronConsoleInstance ] ) ;
59
56
} ) ) ;
60
57
61
- // Add the onDidChangeActiveConsole event handler.
58
+ // Add the onDidChangeActivePositronConsoleInstance event handler.
62
59
disposableStore . add ( services . positronConsoleService . onDidChangeActivePositronConsoleInstance ( positronConsoleInstance => {
63
60
if ( ! positronConsoleInstance ) {
64
61
setCurrentPositronConsoleInstance ( undefined ) ;
65
62
} 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 ) ;
67
65
}
68
66
} ) ) ;
69
67
0 commit comments