-
-
Notifications
You must be signed in to change notification settings - Fork 1
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
7 changed files
with
76 additions
and
67 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
53 changes: 53 additions & 0 deletions
53
vscode-extension/src/modules/internal/select-env.command.ts
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,53 @@ | ||
import * as vscode from "vscode"; | ||
|
||
export const SelectEnvCommand = "drizzle:select_env"; | ||
|
||
/* Local state */ | ||
let $lastSelectedEnv: string | undefined; | ||
|
||
export async function SelectEnv(configPath: string, executeCommand: string) { | ||
// Find .env files in the workspace | ||
const envFiles = await vscode.workspace.findFiles( | ||
"**/.env*", | ||
"**/node_modules/**", | ||
); | ||
|
||
// Create quick pick items | ||
const items = envFiles.map((file) => ({ | ||
label: vscode.workspace.asRelativePath(file), | ||
path: file.fsPath, | ||
})); | ||
|
||
// Add option to not use an env file | ||
items.unshift({ label: "None", path: "Don't use an env file" }); | ||
|
||
// Move last selected item to top if it exists | ||
if ($lastSelectedEnv) { | ||
const lastSelectedIndex = items.findIndex( | ||
(item) => item.path === $lastSelectedEnv, | ||
); | ||
if (lastSelectedIndex > -1) { | ||
const [lastItem] = items.splice(lastSelectedIndex, 1); | ||
items.unshift(lastItem); | ||
} | ||
} | ||
|
||
// Show quick pick | ||
const selected = await vscode.window.showQuickPick(items, { | ||
placeHolder: "Select an environment file", | ||
}); | ||
|
||
if (selected) { | ||
// Save the selection to workspace configuration (except for "None") | ||
if (selected.label !== "None") { | ||
$lastSelectedEnv = selected.path; | ||
} | ||
|
||
// Call open studio command with the selected env file | ||
await vscode.commands.executeCommand( | ||
executeCommand, | ||
configPath, | ||
selected.label === "None" ? undefined : selected.path, | ||
); | ||
} | ||
} |
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