Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add configuration request #23782

Merged
merged 1 commit into from
Jul 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ class NativeGlobalPythonFinderImpl extends DisposableBase implements NativeGloba
constructor() {
super();
this.connection = this.start();
void this.configure();
this.firstRefreshResults = this.refreshFirstTime();
}

Expand Down Expand Up @@ -320,22 +321,12 @@ class NativeGlobalPythonFinderImpl extends DisposableBase implements NativeGloba
);

trackPromiseAndNotifyOnCompletion(
this.connection
.sendRequest<{ duration: number }>(
'refresh',
// Send configuration information to the Python finder.
{
// This has a special meaning in locator, its lot a low priority
// as we treat this as workspace folders that can contain a large number of files.
project_directories: getWorkspaceFolderPaths(),
// We do not want to mix this with `search_paths`
environment_directories: getCustomVirtualEnvDirs(),
conda_executable: getPythonSettingAndUntildify<string>(CONDAPATH_SETTING_KEY),
poetry_executable: getPythonSettingAndUntildify<string>('poetryPath'),
},
)
.then(({ duration }) => this.outputChannel.info(`Refresh completed in ${duration}ms`))
.catch((ex) => this.outputChannel.error('Refresh error', ex)),
this.configure().then(() =>
this.connection
.sendRequest<{ duration: number }>('refresh')
.then(({ duration }) => this.outputChannel.info(`Refresh completed in ${duration}ms`))
.catch((ex) => this.outputChannel.error('Refresh error', ex)),
),
);

completed.promise.finally(() => disposable.dispose());
Expand All @@ -344,8 +335,44 @@ class NativeGlobalPythonFinderImpl extends DisposableBase implements NativeGloba
discovered: discovered.event,
};
}

private lastConfiguration?: ConfigurationOptions;

/**
* Configuration request, this must always be invoked before any other request.
* Must be invoked when ever there are changes to any data related to the configuration details.
*/
private async configure() {
const options: ConfigurationOptions = {
workspaceDirectories: getWorkspaceFolderPaths(),
// We do not want to mix this with `search_paths`
environmentDirectories: getCustomVirtualEnvDirs(),
condaExecutable: getPythonSettingAndUntildify<string>(CONDAPATH_SETTING_KEY),
poetryExecutable: getPythonSettingAndUntildify<string>('poetryPath'),
};
// No need to send a configuration request, is there are no changes.
if (JSON.stringify(options) === JSON.stringify(this.lastConfiguration || {})) {
return;
}
try {
this.lastConfiguration = options;
await this.connection.sendRequest('configure', options);
} catch (ex) {
this.outputChannel.error('Refresh error', ex);
}
}
}

type ConfigurationOptions = {
workspaceDirectories: string[];
/**
* Place where virtual envs and the like are stored
* Should not contain workspace folders.
*/
environmentDirectories: string[];
condaExecutable: string | undefined;
poetryExecutable: string | undefined;
};
/**
* Gets all custom virtual environment locations to look for environments.
*/
Expand Down
Loading