@@ -1273,8 +1273,11 @@ async function dumpServerState(
12731273 const packageJsonContent = await fsAsync . readFile ( packageJsonPath , {
12741274 encoding : "utf-8" ,
12751275 } ) ;
1276- const packageJson = JSON . parse ( packageJsonContent ) ;
1277- serverVersion = packageJson . version ;
1276+ const packageJson : { version ?: unknown } = JSON . parse ( packageJsonContent ) ;
1277+ serverVersion =
1278+ typeof packageJson . version === "string"
1279+ ? packageJson . version
1280+ : undefined ;
12781281 } catch ( e ) {
12791282 // If we can't read the version, that's okay - we'll just omit it
12801283 serverVersion = undefined ;
@@ -1311,28 +1314,12 @@ async function dumpServerState(
13111314 // have been converted to plain objects/arrays above
13121315 const formattedJson = JSON . stringify ( state , null , 2 ) ;
13131316
1314- // Write the file to disk on the server side
1315- const outputFile = utils . createFileInTempDir ( "_server_state.json" ) ;
1316- fs . writeFileSync ( outputFile , formattedJson , { encoding : "utf-8" } ) ;
1317-
1318- // Request the client to open the document
1319- const fileUri = utils . pathToURI ( outputFile ) ;
1320- const showDocumentRequest : p . RequestMessage = {
1321- jsonrpc : c . jsonrpcVersion ,
1322- id : serverSentRequestIdCounter ++ ,
1323- method : "window/showDocument" ,
1324- params : {
1325- uri : fileUri ,
1326- external : false ,
1327- takeFocus : true ,
1328- } ,
1329- } ;
1330- send ( showDocumentRequest ) ;
1331-
1317+ // Return the content so the client can create an unsaved document
1318+ // This avoids creating temporary files that would never be cleaned up
13321319 let response : p . ResponseMessage = {
13331320 jsonrpc : c . jsonrpcVersion ,
13341321 id : msg . id ,
1335- result : { uri : fileUri } ,
1322+ result : { content : formattedJson } ,
13361323 } ;
13371324 return response ;
13381325 } catch ( e ) {
0 commit comments