@@ -2,7 +2,7 @@ import { IWebSocket, WebSocketMessageReader, WebSocketMessageWriter, toSocket }
22import { MessageTransports } from 'monaco-languageclient'
33import * as monaco from 'monaco-editor'
44import type * as vscode from 'vscode'
5- import { TextDocumentSaveReason } from 'vscode-languageserver-protocol'
5+ import { TextDocumentSaveReason , LSPAny } from 'vscode-languageserver-protocol'
66import { getFile , updateFile } from './customRequests'
77import { LanguageClientManager } from './languageClient'
88import { LanguageClientId , LanguageClientOptions } from './languageClientOptions'
@@ -47,6 +47,8 @@ export interface Infrastructure {
4747 * @param id The language server id
4848 */
4949 openConnection ( id : LanguageClientId ) : Promise < MessageTransports >
50+
51+ getInitializationOptions ? ( ) : LSPAny
5052}
5153
5254async function openWebsocketConnection ( url : URL | string ) : Promise < MessageTransports > {
@@ -133,4 +135,21 @@ export abstract class CodinGameInfrastructure implements Infrastructure {
133135 throw new Error ( 'Unable to connect to server' )
134136 }
135137 }
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+ }
136155}
0 commit comments