22// Licensed under the MIT License.
33
44import * as crypto from 'crypto' ;
5- import { Uri } from 'vscode' ;
6- import { ProjectAdapter } from './projectAdapter' ;
75import { PythonProject } from '../../../envExt/types' ;
86
9- /**
10- * Separator used between project ID and test path in project-scoped test IDs.
11- * Using | instead of :: to avoid conflicts with pytest's :: syntax for test paths.
12- */
13- export const PROJECT_ID_SEPARATOR = '|' ;
14-
157/**
168 * Generates a unique project ID by hashing the PythonProject object.
179 * This ensures consistent IDs across extension reloads for the same project.
@@ -31,66 +23,6 @@ export function generateProjectId(pythonProject: PythonProject): string {
3123 return `project-${ hash . substring ( 0 , 12 ) } ` ;
3224}
3325
34- /**
35- * Creates a project-scoped VS Code test item ID.
36- * Format: "{projectId}|{testPath}"
37- *
38- * @param projectId The unique project identifier
39- * @param testPath The test path (e.g., "/workspace/test.py::test_func")
40- * @returns The project-scoped VS Code test ID
41- */
42- export function createProjectScopedVsId ( projectId : string , testPath : string ) : string {
43- return `${ projectId } ${ PROJECT_ID_SEPARATOR } ${ testPath } ` ;
44- }
45-
46- /**
47- * Parses a project-scoped VS Code test ID to extract the project ID and test path.
48- *
49- * @param vsId The VS Code test item ID
50- * @returns Object containing projectId and testPath, or null if invalid
51- */
52- export function parseProjectScopedVsId ( vsId : string ) : { projectId : string ; testPath : string } | null {
53- const separatorIndex = vsId . indexOf ( PROJECT_ID_SEPARATOR ) ;
54- if ( separatorIndex === - 1 ) {
55- return null ;
56- }
57-
58- return {
59- projectId : vsId . substring ( 0 , separatorIndex ) ,
60- testPath : vsId . substring ( separatorIndex + PROJECT_ID_SEPARATOR . length ) ,
61- } ;
62- }
63-
64- /**
65- * Checks if a test file path is within a nested project's directory.
66- * This is used to determine when to query the API for ownership even if
67- * only one project discovered the file.
68- *
69- * @param testFilePath Absolute path to the test file
70- * @param allProjects All projects in the workspace
71- * @param excludeProject Optional project to exclude from the check (typically the discoverer)
72- * @returns True if the file is within any nested project's directory
73- */
74- export function hasNestedProjectForPath (
75- testFilePath : string ,
76- allProjects : ProjectAdapter [ ] ,
77- excludeProject ?: ProjectAdapter ,
78- ) : boolean {
79- return allProjects . some ( ( p ) => p !== excludeProject && testFilePath . startsWith ( p . projectUri . fsPath ) ) ;
80- }
81-
82- /**
83- * Finds the project that owns a specific test file based on project URI.
84- * This is typically used after the API returns ownership information.
85- *
86- * @param projectUri The URI of the owning project (from API)
87- * @param allProjects All projects to search
88- * @returns The ProjectAdapter with matching URI, or undefined if not found
89- */
90- export function findProjectByUri ( projectUri : Uri , allProjects : ProjectAdapter [ ] ) : ProjectAdapter | undefined {
91- return allProjects . find ( ( p ) => p . projectUri . fsPath === projectUri . fsPath ) ;
92- }
93-
9426/**
9527 * Creates a display name for a project including Python version.
9628 * Format: "{projectName} (Python {version})"
0 commit comments