88 onDidOpenTextDocument ,
99 onDidChangeTextDocument ,
1010 getOpenTextDocuments ,
11+ getConfiguration ,
12+ onDidChangeConfiguration ,
1113} from '../../common/vscodeApis/workspaceApis' ;
1214import { isPipInstallableToml } from './provider/venvUtils' ;
1315
@@ -19,23 +21,38 @@ async function setPyProjectTomlContextKey(doc: TextDocument): Promise<void> {
1921 }
2022}
2123
22- export function registerPyProjectTomlCreateEnvFeatures ( disposables : IDisposableRegistry ) : void {
24+ async function setShowCreateEnvButtonContextKey ( ) : Promise < void > {
25+ const config = getConfiguration ( 'python' ) ;
26+ const showCreateEnvButton = config . get < string > ( 'createEnvironment.contentButton' , 'show' ) === 'show' ;
27+ await executeCommand ( 'setContext' , 'showCreateEnvButton' , showCreateEnvButton ) ;
28+ }
29+
30+ export function registerCreateEnvButtonFeatures ( disposables : IDisposableRegistry ) : void {
2331 disposables . push (
2432 onDidOpenTextDocument ( async ( doc : TextDocument ) => {
2533 if ( doc . fileName . endsWith ( 'pyproject.toml' ) ) {
2634 await setPyProjectTomlContextKey ( doc ) ;
2735 }
2836 } ) ,
2937 onDidChangeTextDocument ( async ( e : TextDocumentChangeEvent ) => {
30- if ( e . document . fileName . endsWith ( 'pyproject.toml' ) ) {
31- await setPyProjectTomlContextKey ( e . document ) ;
38+ const doc = e . document ;
39+ if ( doc . fileName . endsWith ( 'pyproject.toml' ) ) {
40+ await setPyProjectTomlContextKey ( doc ) ;
3241 }
3342 } ) ,
43+ onDidChangeConfiguration ( async ( ) => {
44+ await setShowCreateEnvButtonContextKey ( ) ;
45+ } ) ,
3446 ) ;
3547
36- getOpenTextDocuments ( ) . forEach ( async ( doc : TextDocument ) => {
37- if ( doc . fileName . endsWith ( 'pyproject.toml' ) ) {
38- await setPyProjectTomlContextKey ( doc ) ;
39- }
40- } ) ;
48+ setShowCreateEnvButtonContextKey ( ) ;
49+
50+ const docs = getOpenTextDocuments ( ) . filter (
51+ ( doc ) => doc . fileName . endsWith ( 'pyproject.toml' ) && isPipInstallableToml ( doc . getText ( ) ) ,
52+ ) ;
53+ if ( docs . length > 0 ) {
54+ executeCommand ( 'setContext' , 'pipInstallableToml' , true ) ;
55+ } else {
56+ executeCommand ( 'setContext' , 'pipInstallableToml' , false ) ;
57+ }
4158}
0 commit comments