@@ -2,7 +2,7 @@ import { IWebSocket, WebSocketMessageReader, WebSocketMessageWriter, toSocket }
2
2
import { MessageTransports } from 'monaco-languageclient'
3
3
import * as monaco from 'monaco-editor'
4
4
import type * as vscode from 'vscode'
5
- import { TextDocumentSaveReason } from 'vscode-languageserver-protocol'
5
+ import { TextDocumentSaveReason , LSPAny } from 'vscode-languageserver-protocol'
6
6
import { getFile , updateFile } from './customRequests'
7
7
import { LanguageClientManager } from './languageClient'
8
8
import { LanguageClientId , LanguageClientOptions } from './languageClientOptions'
@@ -47,6 +47,8 @@ export interface Infrastructure {
47
47
* @param id The language server id
48
48
*/
49
49
openConnection ( id : LanguageClientId ) : Promise < MessageTransports >
50
+
51
+ getInitializationOptions ? ( ) : LSPAny
50
52
}
51
53
52
54
async function openWebsocketConnection ( url : URL | string ) : Promise < MessageTransports > {
@@ -133,4 +135,21 @@ export abstract class CodinGameInfrastructure implements Infrastructure {
133
135
throw new Error ( 'Unable to connect to server' )
134
136
}
135
137
}
138
+
139
+ public getInitializationOptions ( ) : LSPAny {
140
+ // Provide all open model content to the backend so it's able to write them on the disk
141
+ // BEFORE starting the server or registering the workspace folders
142
+ // The didOpen notification already contain the file content but some LSP (like gopls)
143
+ // don't use it and needs the file to be up-to-date on the disk before the workspace folder is added
144
+ const files = monaco . editor
145
+ . getModels ( )
146
+ . filter ( ( model ) => model . uri . scheme === 'file' )
147
+ . reduce ( ( map , model ) => {
148
+ map [ model . uri . toString ( true ) ] = model . getValue ( )
149
+ return map
150
+ } , { } as Record < string , string > )
151
+ return {
152
+ files
153
+ }
154
+ }
136
155
}
0 commit comments