@@ -3,7 +3,9 @@ import { Cause, Chunk, Effect, Either, Layer, Option } from "effect";
33import { decodeCellMetadata , isStaleCellMetadata } from "../schemas.ts" ;
44import { ConfigContextManager } from "../services/config/ConfigContextManager.ts" ;
55import { MarimoConfigurationService } from "../services/config/MarimoConfigurationService.ts" ;
6+ import { ExecutionRegistry } from "../services/ExecutionRegistry.ts" ;
67import { GitHubClient } from "../services/GitHubClient.ts" ;
8+ import { LanguageClient } from "../services/LanguageClient.ts" ;
79import { NotebookSerializer } from "../services/NotebookSerializer.ts" ;
810import { OutputChannel } from "../services/OutputChannel.ts" ;
911import { VsCode } from "../services/VsCode.ts" ;
@@ -17,10 +19,12 @@ export const RegisterCommandsLive = Layer.scopedDiscard(
1719 Effect . gen ( function * ( ) {
1820 const gh = yield * GitHubClient ;
1921 const code = yield * VsCode ;
22+ const client = yield * LanguageClient ;
2023 const channel = yield * OutputChannel ;
2124 const serializer = yield * NotebookSerializer ;
2225 const configService = yield * MarimoConfigurationService ;
2326 const configContextManager = yield * ConfigContextManager ;
27+ const executions = yield * ExecutionRegistry ;
2428
2529 yield * code . commands . registerCommand (
2630 "marimo.newMarimoNotebook" ,
@@ -78,6 +82,61 @@ export const RegisterCommandsLive = Layer.scopedDiscard(
7882 configContextManager,
7983 } ) ,
8084 ) ;
85+
86+ yield * code . commands . registerCommand (
87+ "marimo.restartKernel" ,
88+ Effect . gen ( function * ( ) {
89+ const editor = yield * code . window . getActiveNotebookEditor ( ) ;
90+ if ( Option . isNone ( editor ) ) {
91+ yield * code . window . showInformationMessage (
92+ "No marimo notebook is currently open" ,
93+ ) ;
94+ return ;
95+ }
96+
97+ yield * code . window . withProgress (
98+ {
99+ location : code . ProgressLocation . Window ,
100+ title : "Restarting kernel" ,
101+ cancellable : true ,
102+ } ,
103+ Effect . fnUntraced ( function * ( progress ) {
104+ progress . report ( { message : "Closing session..." } ) ;
105+
106+ const result = yield * client
107+ . executeCommand ( {
108+ command : "marimo.api" ,
109+ params : {
110+ method : "close_session" ,
111+ params : {
112+ notebookUri : getNotebookUri ( editor . value . notebook ) ,
113+ inner : { } ,
114+ } ,
115+ } ,
116+ } )
117+ . pipe ( Effect . either ) ;
118+
119+ if ( Either . isLeft ( result ) ) {
120+ yield * Effect . logFatal ( "Failed to restart kernel" , result . left ) ;
121+ yield * showErrorAndPromptLogs ( "Failed to restart kernel." , {
122+ channel,
123+ code,
124+ } ) ;
125+ return ;
126+ }
127+
128+ yield * executions . handleInterrupted ( editor . value ) ;
129+
130+ progress . report ( { message : "Kernel restarted." } ) ;
131+ yield * Effect . sleep ( "500 millis" ) ;
132+ } ) ,
133+ ) ;
134+
135+ yield * code . window . showInformationMessage (
136+ "Kernel restarted successfully" ,
137+ ) ;
138+ } ) ,
139+ ) ;
81140 } ) ,
82141) ;
83142
0 commit comments