Skip to content

Commit e4ecda9

Browse files
kinto0facebook-github-bot
authored andcommitted
ms-python <> pyrefly integration (disabling theirs when ours is turned on + vice-versa)
Summary: ms-python insiders came out last night and it is not looking good for my [patch](microsoft/vscode-python#24987). When I put up the PR, I was not able to test pylance fully and put too much faith in the test framework (it's really good but not this good apparently). It works great on a window reload, but that isn't good enough for testing. two issues: - installing pyrefly refreshes something but does not keep pylance disabled (green = pylance syntax highlighting) {F1977750850} I'm not sure what causes this. these settings are [re-checked on any extension install](https://github.com/microsoft/vscode-python/blob/a3dd3aa1bca82be1fb5c44f04c689233010eaeab/src/client/languageServer/watcher.ts#L345) (hence the flicker) and we [check for existence of pyrefly](https://github.com/microsoft/vscode-python/blob/a3dd3aa1bca82be1fb5c44f04c689233010eaeab/src/client/common/configSettings.ts#L283). - changing the disableLanguageServices setting does not actually trigger the change {F1977750864} This is an easier fix: I must've messed up testing it [here](microsoft/vscode-python#24987 (comment)) In the meantime, this hack fixes both of these issues from within pyrefly with no side effects, but only if a workspace is opened (it does not work on the default workspace [because settings are not watched there](https://github.com/microsoft/vscode-python/blob/a3dd3aa1bca82be1fb5c44f04c689233010eaeab/src/client/languageServer/watcher.ts#L295)) Reviewed By: SamChou19815 Differential Revision: D74327314 fbshipit-source-id: 7d97476572731e8771af44af60c81d0d2334054d
1 parent 2a7d271 commit e4ecda9

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

lsp/src/extension.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,17 @@ export async function activate(context: ExtensionContext) {
155155
);
156156

157157
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+
})
158169
}
159170

160171
/**
@@ -170,7 +181,24 @@ function registerTextDocumentContentProviders() {
170181
})();
171182

172183
vscode.workspace.registerTextDocumentContentProvider("contentsasuri", provider);
184+
}
173185

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);
174202
}
175203

176204
export function deactivate(): Thenable<void> | undefined {

0 commit comments

Comments
 (0)