@@ -23,7 +23,7 @@ import {
2323 ProviderOptions ,
2424 ServiceFeatures ,
2525 ServiceOptions ,
26- ServiceOptionsMap , ServiceStruct , SessionInitialConfig ,
26+ ServiceOptionsMap , ServiceStruct , SessionLspConfig ,
2727 SupportedServices ,
2828 Tooltip
2929} from "./types/language-service" ;
@@ -169,11 +169,20 @@ export class LanguageProvider {
169169 * @param session The Ace edit session to update with the file path.
170170 * @param config config to set
171171 */
172- setSessionFilePath ( session : Ace . EditSession , config : SessionInitialConfig ) {
172+ setSessionFilePath ( session : Ace . EditSession , config : SessionLspConfig ) {
173173 this . $getSessionLanguageProvider ( session ) ?. setFilePath ( config . filePath , config . joinWorkspaceURI ) ;
174174 }
175175
176- private $registerSession = ( session : Ace . EditSession , editor : Ace . Editor , config ?: SessionInitialConfig ) => {
176+ /**
177+ * Registers a new editing session with the editor and associates it with a language provider.
178+ * If a language provider for the specified editing session does not already exist, it initializes
179+ * and stores a new session-specific language provider.
180+ *
181+ * @param session - The Ace EditSession object to be registered, representing a specific editing session.
182+ * @param editor - The Ace Editor instance associated with the editing session.
183+ * @param [config] - An optional configuration object for initializing the session.
184+ */
185+ registerSession = ( session : Ace . EditSession , editor : Ace . Editor , config ?: SessionLspConfig ) => {
177186 if ( ! this . $sessionLanguageProviders [ session [ "id" ] ] ) {
178187 this . $sessionLanguageProviders [ session [ "id" ] ] = new SessionLanguageProvider ( this , session , editor , this . $messageController , config ) ;
179188 }
@@ -182,6 +191,18 @@ export class LanguageProvider {
182191 }
183192 }
184193
194+ /**
195+ * Sets the Language Server Protocol (LSP) configuration for the given session.
196+ *
197+ * @param session - The editor session to which the LSP configuration will be applied.
198+ * @param config - The LSP configuration to set for the session.
199+ * @return The updated editor session with the applied LSP configuration.
200+ */
201+ setSessionLspConfig ( session : Ace . EditSession , config : SessionLspConfig ) {
202+ session . lspConfig = config ;
203+ return session ;
204+ }
205+
185206 private $getSessionLanguageProvider ( session : Ace . EditSession ) : SessionLanguageProvider {
186207 return this . $sessionLanguageProviders [ session [ "id" ] ] ;
187208 }
@@ -197,12 +218,14 @@ export class LanguageProvider {
197218 * @param editor - The Ace editor instance to be registered.
198219 * @param [config] - Configuration options for the session.
199220 */
200- registerEditor ( editor : Ace . Editor , config ?: SessionInitialConfig ) {
221+ registerEditor ( editor : Ace . Editor , config ?: SessionLspConfig ) {
201222 if ( ! this . editors . includes ( editor ) )
202223 this . $registerEditor ( editor ) ;
203- this . $registerSession ( editor . session , editor , config ) ;
224+ config = config ?? editor . session . lspConfig ;
225+ this . registerSession ( editor . session , editor , config ) ;
204226 }
205227
228+
206229 codeActionCallback : ( codeActions : CodeActionsByService [ ] ) => void ;
207230
208231 /**
@@ -278,7 +301,11 @@ export class LanguageProvider {
278301 AceEditor . getConstructor ( editor ) ;
279302
280303 editor . setOption ( "useWorker" , false ) ;
281- editor . on ( "changeSession" , ( { session} ) => this . $registerSession ( session , editor ) ) ;
304+
305+
306+ if ( ! this . options . manualSessionControl ) {
307+ editor . on ( "changeSession" , ( { session} ) => this . registerSession ( session , editor , session . lspConfig ) ) ;
308+ }
282309
283310 if ( this . options . functionality ! . completion || this . options . functionality ! . inlineCompletion ) {
284311 this . $registerCompleters ( editor ) ;
@@ -405,11 +432,19 @@ export class LanguageProvider {
405432 }
406433
407434 /**
408- * Sets global options for the specified service.
435+ * Configures global options that apply to all documents handled by the specified language service.
436+ *
437+ * Global options serve as default settings for all documents processed by a service when no
438+ * document-specific options are provided. These options affect language service behavior across
439+ * the entire workspace, including validation rules, formatting preferences, completion settings,
440+ * and service-specific configurations.
409441 *
410- * @param serviceName - The name of the service for which to set global options.
411- * @param options - The options to set for the specified service.
412- * @param {boolean } [merge=false] - Indicates whether to merge the provided options with the existing options. Defaults to false.
442+ * @param serviceName - The identifier of the language service to configure. Must be a valid
443+ * service name from the supported services (e.g., 'typescript', 'json', 'html').
444+ * @param options - The global configuration options specific to the language service. The structure
445+ * varies by service type.
446+ * @param {boolean } [merge=false] - Indicates whether to merge the provided options with the existing options.
447+ * Defaults to false.
413448 */
414449 setGlobalOptions < T extends keyof ServiceOptionsMap > ( serviceName : T & string , options : ServiceOptionsMap [ T ] , merge = false ) {
415450 this . $messageController . setGlobalOptions ( serviceName , options , merge ) ;
@@ -437,12 +472,25 @@ export class LanguageProvider {
437472 *
438473 * @param session - The Ace editor session to configure.
439474 * @param options - The configuration options to be applied to the session.
475+ * @deprecated Use `setDocumentOptions` instead. This method will be removed in the future.
440476 */
441477 setSessionOptions < OptionsType extends ServiceOptions > ( session : Ace . EditSession , options : OptionsType ) {
442478 let sessionLanguageProvider = this . $getSessionLanguageProvider ( session ) ;
443479 sessionLanguageProvider . setOptions ( options ) ;
444480 }
445481
482+ /**
483+ * Sets configuration options for a document associated with the specified editor session.
484+ *
485+ * @param session - The Ace editor session representing the document to configure.
486+ * @param options - The service options to apply. The exact shape depends on the language services
487+ * active for this session (e.g. JSON schema settings).
488+ */
489+ setDocumentOptions < OptionsType extends ServiceOptions > ( session : Ace . EditSession , options : OptionsType ) {
490+ let sessionLanguageProvider = this . $getSessionLanguageProvider ( session ) ;
491+ sessionLanguageProvider . setOptions ( options ) ;
492+ }
493+
446494 /**
447495 * Configures the specified features for a given service.
448496 *
0 commit comments