@@ -52,7 +52,7 @@ class BamlLanguageClient(project: Project) :
5252 // Phase 2: Full version switching notification processing
5353 @JsonNotification(" baml_src_generator_version" )
5454 fun generatorVersionNotification (payload : GeneratorVersionPayload ) {
55- log.info(" 🔄 PROCESSING generator version notification: ${payload.version} for ${ payload.root_path} " )
55+ log.info(" 🔄 language server requested that we run a different version: $ payload" )
5656
5757 // Process in background to avoid blocking LSP communication
5858 ApplicationManager .getApplication().executeOnPooledThread {
@@ -61,63 +61,56 @@ class BamlLanguageClient(project: Project) :
6161 }
6262
6363 private fun processVersionSwitchRequest (payload : GeneratorVersionPayload ) {
64- try {
65- log.info(" Processing version switch request: ${payload.version} " )
66-
67- if (BamlIdeConfig .shouldIgnoreLanguageServerDynamicVersioning()) {
68- log.warn(" Debug mode detected - skipping version switching to preserve existing debug logic" )
69- return
70- }
71-
72- // 1. Validate notification is for current project (equivalent to VSCode's isPathWithinParent)
73- if (! isNotificationForCurrentProject(payload.root_path)) {
74- log.debug(" Ignoring version notification for different project: ${payload.root_path} " )
75- return
76- }
64+ if (BamlIdeConfig .shouldIgnoreLanguageServerDynamicVersioning()) {
65+ log.info(" Running in development mode, ignoring version switch request" )
66+ return
67+ }
7768
78- // 2. Check if restart already in progress (equivalent to VSCode's isRestarting flag )
79- if (languageServerService.isCurrentlyRestarting( )) {
80- log.info( " Language server restart already in progress, ignoring request " )
81- return
82- }
69+ // 1. Validate notification is for current project (equivalent to VSCode's isPathWithinParent )
70+ if (! isNotificationForCurrentProject(payload.root_path )) {
71+ log.debug( " Ignoring version notification for different project: ${payload.root_path} " )
72+ return
73+ }
8374
84- // 3. Validate semantic version (equivalent to VSCode's semver.valid check )
85- if (! isValidSemanticVersion(payload.version )) {
86- log.warn( " Invalid semantic version received: ${payload.version} " )
87- return
88- }
75+ // 2. Check if restart already in progress (equivalent to VSCode's isRestarting flag )
76+ if (languageServerService.isCurrentlyRestarting( )) {
77+ log.info( " Language server restart already in progress, ignoring request " )
78+ return
79+ }
8980
90- // 4. Check minimum version requirement (equivalent to VSCode's >= 0.86.0 check)
91- if (! isMinimumVersionSupported (payload.version)) {
92- log.warn(" Ignoring version ${payload.version} - below minimum supported version " )
93- return
94- }
81+ // 3. Validate semantic version (equivalent to VSCode's semver.valid check)
82+ if (! isValidSemanticVersion (payload.version)) {
83+ log.warn(" Invalid semantic version received: ${payload.version} " )
84+ return
85+ }
9586
96- // 5. Resolve target CLI path (equivalent to VSCode's resolveCliPath call)
97- runBlocking {
98- // 6. Check if restart is needed (equivalent to VSCode's path comparison)
99- if (languageServerService.getCurrentCliVersion() != payload.version) {
100- // Update version tracking even if no restart needed
101- languageServerService.updateCurrentServer(payload.version)
102- // 7. Execute restart (equivalent to VSCode's executeLanguageServerRestart)
103- log.info(" Restarting language server with new version" )
104- service<BamlLanguageServerService >().setRestartingFlag(true )
105- // https://github.com/redhat-developer/lsp4ij/blob/main/docs/DeveloperGuide.md#install-language-server
106- // Stops the language server if it is currently starting or already started.
107- // Resets the installer's internal state.
108- // Executes the installation via checkInstallation(context).
109- // If the server was previously running, it restarts it once the installation completes.
110- val context = ServerInstallationContext ()
111- .setForceInstall(true )
112- LanguageServerManager .getInstance(project)
113- .install(" baml-language-server" , context)
114- }
115- log.info(" Already using correct CLI version, no restart needed" )
87+ // 4. Check minimum version requirement (equivalent to VSCode's >= 0.86.0 check)
88+ if (! isMinimumVersionSupported(payload.version)) {
89+ log.warn(" Ignoring version ${payload.version} - below minimum supported version" )
90+ return
91+ }
11692
93+ // 5. Resolve target CLI path (equivalent to VSCode's resolveCliPath call)
94+ runBlocking {
95+ // 6. Check if restart is needed (equivalent to VSCode's path comparison)
96+ if (languageServerService.getCurrentCliVersion() != payload.version) {
97+ // Update version tracking even if no restart needed
98+ languageServerService.updateCurrentServer(payload.version)
99+ // 7. Execute restart (equivalent to VSCode's executeLanguageServerRestart)
100+ log.info(" Restarting language server with new version" )
101+ service<BamlLanguageServerService >().setRestartingFlag(true )
102+ // https://github.com/redhat-developer/lsp4ij/blob/main/docs/DeveloperGuide.md#install-language-server
103+ // Stops the language server if it is currently starting or already started.
104+ // Resets the installer's internal state.
105+ // Executes the installation via checkInstallation(context).
106+ // If the server was previously running, it restarts it once the installation completes.
107+ val context = ServerInstallationContext ()
108+ .setForceInstall(true )
109+ LanguageServerManager .getInstance(project)
110+ .install(" baml-language-server" , context)
117111 }
112+ log.info(" Already using correct CLI version, no restart needed" )
118113
119- } catch (e: Exception ) {
120- log.error(" Error processing version switch request" , e)
121114 }
122115 }
123116
0 commit comments