1- import { QuickInputButtons , TaskExecution , TaskRevealKind , Terminal , Uri , window } from 'vscode' ;
1+ import { QuickInputButtons , TaskExecution , TaskRevealKind , Terminal , Uri } from 'vscode' ;
22import {
33 EnvironmentManagers ,
44 InternalEnvironmentManager ,
@@ -40,6 +40,10 @@ import { pickPackageOptions } from '../common/pickers/packages';
4040import { pickProject , pickProjectMany } from '../common/pickers/projects' ;
4141import { TerminalManager } from './terminal/terminalManager' ;
4242import { runInTerminal } from './terminal/runInTerminal' ;
43+ import { quoteArgs } from './execution/execUtils' ;
44+ import { showErrorMessage } from '../common/errors/utils' ;
45+ import { activeTextEditor } from '../common/window.apis' ;
46+ import { clipboardWriteText } from '../common/env.apis' ;
4347
4448export async function refreshManagerCommand ( context : unknown ) : Promise < void > {
4549 if ( context instanceof EnvManagerTreeItem ) {
@@ -278,7 +282,7 @@ export async function setEnvironmentCommand(
278282 }
279283 } else {
280284 traceError ( `Invalid context for setting environment command: ${ context } ` ) ;
281- window . showErrorMessage ( 'Invalid context for setting environment' ) ;
285+ showErrorMessage ( 'Invalid context for setting environment' ) ;
282286 }
283287}
284288
@@ -296,7 +300,7 @@ export async function resetEnvironmentCommand(
296300 if ( manager ) {
297301 manager . set ( uri , undefined ) ;
298302 } else {
299- window . showErrorMessage ( `No environment manager found for: ${ uri . fsPath } ` ) ;
303+ showErrorMessage ( `No environment manager found for: ${ uri . fsPath } ` ) ;
300304 traceError ( `No environment manager found for ${ uri . fsPath } ` ) ;
301305 }
302306 return ;
@@ -308,7 +312,7 @@ export async function resetEnvironmentCommand(
308312 return ;
309313 }
310314 traceError ( `Invalid context for unset environment command: ${ context } ` ) ;
311- window . showErrorMessage ( 'Invalid context for unset environment' ) ;
315+ showErrorMessage ( 'Invalid context for unset environment' ) ;
312316}
313317
314318export async function setEnvManagerCommand ( em : EnvironmentManagers , wm : PythonProjectManager ) : Promise < void > {
@@ -338,7 +342,7 @@ export async function addPythonProject(
338342 pc : ProjectCreators ,
339343) : Promise < PythonProject | PythonProject [ ] | undefined > {
340344 if ( wm . getProjects ( ) . length === 0 ) {
341- window . showErrorMessage ( 'Please open a folder/project before adding a workspace' ) ;
345+ showErrorMessage ( 'Please open a folder/project before adding a workspace' ) ;
342346 return ;
343347 }
344348
@@ -554,9 +558,24 @@ export async function runAsTaskCommand(item: unknown, api: PythonEnvironmentApi)
554558 ) ;
555559 }
556560 } else if ( item === undefined ) {
557- const uri = window . activeTextEditor ?. document . uri ;
561+ const uri = activeTextEditor ( ) ?. document . uri ;
558562 if ( uri ) {
559563 return runAsTaskCommand ( uri , api ) ;
560564 }
561565 }
562566}
567+
568+ export async function copyPathToClipboard ( item : unknown ) : Promise < void > {
569+ if ( item instanceof ProjectItem ) {
570+ const projectPath = item . project . uri . fsPath ;
571+ await clipboardWriteText ( projectPath ) ;
572+ traceInfo ( `Copied project path to clipboard: ${ projectPath } ` ) ;
573+ } else if ( item instanceof ProjectEnvironment || item instanceof PythonEnvTreeItem ) {
574+ const run = item . environment . execInfo . activatedRun ?? item . environment . execInfo . run ;
575+ const envPath = quoteArgs ( [ run . executable , ...( run . args ?? [ ] ) ] ) . join ( ' ' ) ;
576+ await clipboardWriteText ( envPath ) ;
577+ traceInfo ( `Copied environment path to clipboard: ${ envPath } ` ) ;
578+ } else {
579+ traceVerbose ( `Invalid context for copy path to clipboard: ${ item } ` ) ;
580+ }
581+ }
0 commit comments