-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
28 changed files
with
188 additions
and
128 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,3 @@ | ||
import { Observable } from 'rxjs' | ||
import { EnvironmentPrefix } from './environments' | ||
|
||
export type ExtensionContext = { | ||
rootDir: string | ||
micromambaDir: string | ||
micromambaPath: string | ||
} | ||
|
||
export type ActiveEnvironmentPrefix = EnvironmentPrefix | undefined | ||
|
||
export interface DisposableLike { | ||
dispose: () => void | ||
} | ||
|
||
export interface ActiveEnvironmentManager { | ||
readonly prefix$: Observable<ActiveEnvironmentPrefix> | ||
activate(prefix: EnvironmentPrefix): void | ||
deactivate(): void | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,38 @@ | ||
import * as vscode from 'vscode' | ||
import { DisposableLike, ExtensionContext } from '../_definitions' | ||
import { DisposableLike } from '../_definitions' | ||
import { Observable } from 'rxjs' | ||
import { concatMap } from 'rxjs/operators' | ||
import { EnvironmentInfo, findMicromambaEnvironmentQuickPickItems } from '../environments' | ||
import sh from '../helpers/sh' | ||
import { MicromambaInfo } from '../helpers/makeMicromambaInfo' | ||
|
||
const setContext = <T>(key: string, value: T): void => { | ||
vscode.commands.executeCommand('setContext', key, value) | ||
} | ||
|
||
export const activateContextFlags = ( | ||
extContext: ExtensionContext, | ||
mInfo: MicromambaInfo, | ||
info$: Observable<EnvironmentInfo>, | ||
): DisposableLike => { | ||
const sub = info$ | ||
.pipe( | ||
concatMap(async (info) => ({ | ||
info, | ||
items: await findMicromambaEnvironmentQuickPickItems(extContext), | ||
concatMap(async (eInfo) => ({ | ||
eInfo, | ||
items: await findMicromambaEnvironmentQuickPickItems(mInfo), | ||
})), | ||
) | ||
.subscribe(async ({ info, items }) => { | ||
const name = info.environmentName | ||
.subscribe(async ({ eInfo, items }) => { | ||
const name = eInfo.environmentName | ||
const item = items.find((x) => x.data.content.name === name) | ||
const hasCreatedEnvs = items.length > 0 | ||
const hasActivatedEnv = !!item | ||
const hasMicromambaDir = await sh.testd(extContext.micromambaDir) | ||
const hasMicromambaDir = await sh.testd(mInfo.micromambaDir) | ||
setContext('corker.micromamba.can.activate.environment', hasCreatedEnvs) | ||
setContext('corker.micromamba.can.deactivate.environment', hasActivatedEnv) | ||
setContext('corker.micromamba.can.remove.environment', hasActivatedEnv) | ||
setContext('corker.micromamba.can.clear.all', hasMicromambaDir) | ||
setContext('corker.micromamba.can.use.global.home.dir', mInfo.isLocal) | ||
setContext('corker.micromamba.can.use.local.home.dir', !mInfo.isLocal) | ||
}) | ||
return { dispose: () => sub.unsubscribe() } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,19 @@ | ||
import * as vscode from 'vscode' | ||
import { skip } from 'rxjs/operators' | ||
import { ActiveEnvironmentManager, ActiveEnvironmentPrefix, DisposableLike } from '../_definitions' | ||
import { DisposableLike } from '../_definitions' | ||
import { EnvironmentManager } from '../environments/makeEnvironmentManager' | ||
|
||
export function activateWorkspaceState( | ||
context: vscode.ExtensionContext, | ||
manager: ActiveEnvironmentManager, | ||
manager: EnvironmentManager, | ||
): DisposableLike { | ||
const key = 'micromamba.active.environment.name' | ||
const { workspaceState } = context | ||
const prefix = workspaceState.get<ActiveEnvironmentPrefix>(key) | ||
const prefix = workspaceState.get<string | undefined>(key) | ||
if (prefix) manager.activate(prefix) | ||
else manager.deactivate() | ||
const sub = manager.prefix$ | ||
.pipe(skip(1)) | ||
.subscribe((x: ActiveEnvironmentPrefix) => workspaceState.update(key, x)) | ||
.subscribe((x) => workspaceState.update(key, x)) | ||
return { dispose: (): void => sub.unsubscribe() } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,11 @@ | ||
import { ActiveEnvironmentManager, ExtensionContext } from '../_definitions' | ||
import { ExtensionContext } from 'vscode' | ||
import { EnvironmentManager } from '../environments/makeEnvironmentManager' | ||
import { MicromambaInfo } from '../helpers/makeMicromambaInfo' | ||
|
||
export type CommandLike = (context: CommandContext) => Promise<void> | ||
|
||
export interface CommandContext { | ||
extContext: ExtensionContext | ||
manager: ActiveEnvironmentManager | ||
ctx: ExtensionContext | ||
info: MicromambaInfo | ||
manager: EnvironmentManager | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { Uri, window } from 'vscode' | ||
import { CommandLike } from './_definitions' | ||
import { setGlobalMicromambaHomeDir } from '../helpers/makeMicromambaInfo' | ||
import { isWindows } from '../helpers/infra' | ||
import os from 'os' | ||
import { join } from 'path' | ||
import sh from '../helpers/sh' | ||
|
||
export const runUseGlobalHomeDirCommand: CommandLike = async ({ ctx, manager }) => { | ||
if (isWindows) { | ||
const uris = await window.showOpenDialog({ | ||
canSelectFolders: true, | ||
openLabel: 'Home', | ||
title: 'micromamba: Global home directory', | ||
defaultUri: Uri.file('C:/') | ||
}) | ||
if (!uris) return | ||
const homeDir = join(uris[0].fsPath, '.micromamba') | ||
await sh.mkdirp(homeDir) | ||
await setGlobalMicromambaHomeDir(ctx, homeDir) | ||
manager.deactivate() | ||
window.showInformationMessage(`micromamba: Global home directory: ${homeDir}`) | ||
} else { | ||
const homeDir = join(os.homedir(), '.vscode-micromamba') | ||
await sh.mkdirp(homeDir) | ||
await setGlobalMicromambaHomeDir(ctx, homeDir) | ||
manager.deactivate() | ||
window.showInformationMessage(`micromamba: Global home directory: ${homeDir}`) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { setGlobalMicromambaHomeDir } from '../helpers/makeMicromambaInfo' | ||
import { CommandLike } from './_definitions' | ||
|
||
export const runUseLocalHomeDirCommand: CommandLike = async ({ ctx, manager }) => { | ||
await setGlobalMicromambaHomeDir(ctx, undefined) | ||
manager.deactivate() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.