MCPcopy Create free account
hub / github.com/facebook/pyrefly / overridePythonPath

Function overridePythonPath

lsp/src/extension.ts:61–85  ·  view source on GitHub ↗

* This function adds the pythonPath to any section with configuration of 'python'. * Our language server expects the pythonPath from VSCode configurations but this setting is not stored in VSCode * configurations. The Python extension used to store pythonPath in this section but no longer does. De

(
  pythonEnv: PythonEnvironment,
  configurationItems: ConfigurationItem[],
  configuration: (object | null)[],
)

Source from the content-addressed store, hash-verified

59 * - {setting: 'value', pythonPath: '/usr/bin/python3'} is returned
60 */
61async function overridePythonPath(
62 pythonEnv: PythonEnvironment,
63 configurationItems: ConfigurationItem[],
64 configuration: (object | null)[],
65): Promise<(object | null)[]> {
66 const newResult = await Promise.all(
67 configuration.map(async (item, index) => {
68 if (
69 configurationItems.length <= index ||
70 configurationItems[index].section !== 'python'
71 ) {
72 return item;
73 }
74 const scopeUri = configurationItems[index].scopeUri;
75 const pythonPath = await pythonEnv.getInterpreterPath(
76 scopeUri === undefined ? undefined : vscode.Uri.parse(scopeUri),
77 );
78 if (pythonPath === undefined) {
79 return item;
80 }
81 return {...item, pythonPath};
82 }),
83 );
84 return newResult;
85}
86
87export async function activate(context: ExtensionContext) {
88 // Initialize the output channel if it doesn't exist

Callers 1

activateFunction · 0.85

Calls 4

getInterpreterPathMethod · 0.80
allMethod · 0.45
mapMethod · 0.45
parseMethod · 0.45

Tested by

no test coverage detected