@@ -155,6 +155,17 @@ export async function activate(context: ExtensionContext) {
155
155
) ;
156
156
157
157
registerTextDocumentContentProviders ( ) ;
158
+
159
+ // When our extension is activated, make sure ms-python knows
160
+ // TODO(kylei): remove this hack once ms-python has this behavior
161
+ await triggerMsPythonRefreshLanguageServers ( ) ;
162
+
163
+ vscode . workspace . onDidChangeConfiguration ( async ( e ) => {
164
+ if ( e . affectsConfiguration ( `python.pyrefly.disableLanguageServices` ) ) {
165
+ // TODO(kylei): remove this hack once ms-python has this behavior
166
+ await triggerMsPythonRefreshLanguageServers ( ) ;
167
+ }
168
+ } )
158
169
}
159
170
160
171
/**
@@ -170,7 +181,24 @@ function registerTextDocumentContentProviders() {
170
181
} ) ( ) ;
171
182
172
183
vscode . workspace . registerTextDocumentContentProvider ( "contentsasuri" , provider ) ;
184
+ }
173
185
186
+ /**
187
+ * This function will trigger the ms-python extension to reasses which language server to spin up.
188
+ * It does this by changing languageServer setting: this triggers a refresh of active language
189
+ * servers:
190
+ * https://github.com/microsoft/vscode-python/blob/main/src/client/languageServer/watcher.ts#L296
191
+ *
192
+ * We then change the setting back so we don't end up messing up the users settings.
193
+ */
194
+ async function triggerMsPythonRefreshLanguageServers ( ) {
195
+ const config = vscode . workspace . getConfiguration ( 'python' ) ;
196
+ const setting = 'languageServer' ;
197
+ let previousSetting = config . get ( setting ) ;
198
+ // without the target, we will crash here with "Unable to write to Workspace Settings
199
+ // because no workspace is opened. Please open a workspace first and try again."
200
+ await config . update ( setting , previousSetting === 'None' ? 'Default' : 'None' , vscode . ConfigurationTarget . Global ) ;
201
+ await config . update ( setting , previousSetting , vscode . ConfigurationTarget . Global ) ;
174
202
}
175
203
176
204
export function deactivate ( ) : Thenable < void > | undefined {
0 commit comments