Skip to content
Open
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
25 changes: 18 additions & 7 deletions src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
import * as path from 'path';
import * as vscode from 'vscode';
import { PythonFunctionLensProvider } from './PythonFunctionLensProvider';
import * as path from 'path';


function getArgsKey(uri: vscode.Uri, qualifiedName: string): string {
return `${uri.toString()}::${qualifiedName}`;
}

function resolvePythonPath(configPath: string, uri: vscode.Uri): string {
if (path.isAbsolute(configPath)) return configPath;

const workspaceFolder = vscode.workspace.getWorkspaceFolder(uri);
if (!workspaceFolder) return configPath;

return path.join(workspaceFolder.uri.fsPath, configPath);
}

export function activate(context: vscode.ExtensionContext) {
const selector = { language: 'python', scheme: 'file' };
const provider = new PythonFunctionLensProvider();
Expand Down Expand Up @@ -50,8 +59,8 @@ export function activate(context: vscode.ExtensionContext) {
const relForPytest = relativePath.split(path.sep).join('/');
const key = getArgsKey(uri, funcName);
const argsInput = context.globalState.get<string>(key);
const pythonPath = vscode.workspace.getConfiguration('pythonFuncRunner').get<string>('pythonPath') ?? 'python';
const config = vscode.workspace.getConfiguration('pythonFuncRunner');
const rawPythonPath = vscode.workspace.getConfiguration('pythonFuncRunner').get<string>('pythonPath') ?? 'python';
const pythonPath = resolvePythonPath(rawPythonPath, uri); const config = vscode.workspace.getConfiguration('pythonFuncRunner');
const globalArgs = config.get<string>('extraPytestArgs') ?? '';
const safePythonPath = `"${pythonPath}"`;
const commandParts = [safePythonPath, '-m', 'pytest'];
Expand All @@ -78,8 +87,8 @@ export function activate(context: vscode.ExtensionContext) {
async (uri: vscode.Uri, funcName: string) => {

const config = vscode.workspace.getConfiguration('pythonFuncRunner');
const pythonPath = config.get<string>('pythonPath') ?? 'python';

const rawPythonPath = config.get<string>('pythonPath') ?? 'python';
const pythonPath = resolvePythonPath(rawPythonPath, uri);
const filePath = uri.fsPath;
const relativePath = vscode.workspace.asRelativePath(filePath);
const relForPytest = relativePath.split(path.sep).join('/');
Expand Down Expand Up @@ -120,7 +129,8 @@ export function activate(context: vscode.ExtensionContext) {
const key = getArgsKey(uri, '__main__');
const argsInput = context.globalState.get<string>(key);
const filePath = uri.fsPath;
const pythonPath = vscode.workspace.getConfiguration('pythonFuncRunner').get<string>('pythonPath') ?? 'python';
const rawPythonPath = vscode.workspace.getConfiguration('pythonFuncRunner').get<string>('pythonPath') ?? 'python';
const pythonPath = resolvePythonPath(rawPythonPath, uri);

const command = [
`"${pythonPath}"`,
Expand All @@ -139,7 +149,8 @@ export function activate(context: vscode.ExtensionContext) {
const argsInput = context.globalState.get<string>(key);
const filePath = uri.fsPath;
const workspaceFolder = vscode.workspace.getWorkspaceFolder(uri);
const pythonPath = vscode.workspace.getConfiguration('pythonFuncRunner').get<string>('pythonPath') ?? 'python';
const rawPythonPath = vscode.workspace.getConfiguration('pythonFuncRunner').get<string>('pythonPath') ?? 'python';
const pythonPath = resolvePythonPath(rawPythonPath, uri);

const debugConfig: vscode.DebugConfiguration = {
name: 'Debug __main__',
Expand Down