microsoft / python-environment-tools

MIT License
159 stars 15 forks source link

Support for workspace settings #23

Closed karthiknadig closed 3 months ago

karthiknadig commented 4 months ago

Note

DonJayamanne commented 3 months ago

Here is everything (all configuration setings) we need to pass to the native locator

        const pythonPathSettings = (workspace.workspaceFolders || []).map((w) =>
            getPythonSettingAndUntildify(DEFAULT_INTERPRETER_PATH_SETTING_KEY, w.uri.fsPath),
        );
        pythonPathSettings.push(getPythonSettingAndUntildify(DEFAULT_INTERPRETER_PATH_SETTING_KEY));
        // We can have multiple workspaces, each with its own setting.
        const pythonSettings = Array.from(new Set(pythonPathSettings.filter((item) => !!item)).values()).map((p) =>
            // We only want the parent directories.
            path.dirname(p!),
        );
        trackPromiseAndNotifyOnCompletion(
            this.connection
                .sendRequest<{ duration: number }>(
                    'refresh',
                    // Send configuration information to the Python finder.
                    // We need a cleaner configuration object.
                    {
                        // 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.
                        search_paths: (workspace.workspaceFolders || []).map((w) => w.uri.fsPath),
                        // Also send the python paths that are configured in the settings.
                        python_path_settings: pythonSettings,
                        conda_executable: getPythonSettingAndUntildify(CONDAPATH_SETTING_KEY),
                        poetry_path: getPythonSettingAndUntildify('poetryPath'),
                        pipenv_path: getPythonSettingAndUntildify('pipenvPath'),
                        // We do not want to mix this with `search_paths`
                        // Need a better name for `search_paths`.
                        virtual_env_dirs: getCustomVirtualEnvDirs(),
                    },
                )
                .then(({ duration }) => traceInfo(`Native Python Finder completed in ${duration}ms`))
                .catch((ex) => traceError('Error in Native Python Finder', ex)),
        );
DonJayamanne commented 3 months ago

Done