This repository has been archived by the owner on Jun 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
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
9 changed files
with
948 additions
and
68 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,70 +1,162 @@ | ||
/* eslint-disable @typescript-eslint/naming-convention */ | ||
|
||
import path = require("path"); | ||
import * as vscode from "vscode"; | ||
import { getProfiles } from "./config"; | ||
import { getExtensionsPath, getVSCodePath } from "./utils"; | ||
|
||
export const CommandTypes = ["vscode-extension-profiles.Select", "vscode-extension-profiles.Edite", "vscode-extension-profiles.Delete"] as const; | ||
import { getExtensionList, getProfiles, setExtensionList } from "./config"; | ||
import { getAllExtensions } from "./storage"; | ||
import { ExtensionList } from "./types"; | ||
export const CommandTypes = [ | ||
"vscode-extension-profiles.Apply", | ||
"vscode-extension-profiles.Refresh", | ||
"vscode-extension-profiles.Edite", | ||
"vscode-extension-profiles.Delete", | ||
] as const; | ||
|
||
type Args = { ctx: vscode.ExtensionContext }; | ||
|
||
export const Commands: Record<typeof CommandTypes[number], (args: Args) => any> = { | ||
"vscode-extension-profiles.Select": selectProfile, | ||
"vscode-extension-profiles.Apply": applyProfile, | ||
"vscode-extension-profiles.Edite": editeProfile, | ||
"vscode-extension-profiles.Refresh": refreshExtensionList, | ||
"vscode-extension-profiles.Delete": deleteProfile, | ||
}; | ||
|
||
const isDev = true; | ||
// Select profile ... | ||
function selectProfile({ ctx }: Args): any { | ||
console.log(ctx); | ||
// vscode.commands.executeCommand('workbench.extensions.installExtension', 'extensionId'); | ||
// let list = vscode.commands.executeCommand("workbench.extensions.search", "@installed "); | ||
// console.log(list); | ||
console.log("extension", getExtensionsPath()); | ||
console.log("code path", getVSCodePath()); | ||
// console.log(vscode.extensions.all.filter((e) => /^(?!\/Applications\/Visual Studio Code.app\/).*$/g.test(e.extensionPath))); | ||
let items: vscode.QuickPickItem[] = []; | ||
async function applyProfile({ ctx }: Args) { | ||
const profiles = getProfiles(); | ||
const profilesKeys = Object.keys(profiles); | ||
if (profilesKeys.length <= 0) { | ||
vscode.window.showErrorMessage("Extension profiles: No profiles found, please create a profile first.", { modal: true }); | ||
return; | ||
} | ||
|
||
console.log(Object.keys(getProfiles())); | ||
let fsPath; | ||
if (vscode.workspace.workspaceFolders !== undefined) { | ||
fsPath = vscode.workspace.workspaceFolders[0].uri.fsPath; | ||
} else { | ||
vscode.window.showErrorMessage("Extension profiles: Working folder not found, open a folder an try again", { modal: true }); | ||
return; | ||
} | ||
|
||
// console.log(vscode.extensions.all.filter((e) => /^(?!\/Applications\/Visual Studio Code.app\/).*$/g.test(e.extensionPath))); | ||
let itemsProfiles: vscode.QuickPickItem[] = []; | ||
|
||
for (const item of Object.keys(getProfiles())) { | ||
items.push({ | ||
for (const item of profilesKeys) { | ||
itemsProfiles.push({ | ||
label: item, | ||
}); | ||
} | ||
|
||
// for (const item of getAllExtensions()) { | ||
// items.push({ | ||
// label: item.packageJSON.displayName || item.packageJSON.name || item.id, | ||
// description: item.id, | ||
// detail: item.packageJSON.description, | ||
// picked: true, | ||
// }); | ||
// } | ||
|
||
vscode.window.showQuickPick(items).then((selection) => { | ||
let profile = ""; | ||
vscode.window.showQuickPick(itemsProfiles, { placeHolder: "Select profile" }).then((selection) => { | ||
// the user canceled the selection | ||
if (!selection) { | ||
return; | ||
} | ||
|
||
console.log(selection); | ||
profile = selection.label; | ||
}); | ||
console.log(profile); | ||
|
||
let itemsWorkspace: vscode.QuickPickItem[] = []; | ||
|
||
// let uuid = await getWorkspaceUUID(vscode.Uri.parse(fsPath)); | ||
} | ||
|
||
async function refreshExtensionList() { | ||
let oldConfig = getExtensionList(), | ||
keysConfig = Object.keys(oldConfig); | ||
let newConfig: ExtensionList = {}; | ||
|
||
for (const item of await getAllExtensions()) { | ||
if (!item.label) { | ||
item.label = item.id; | ||
if (keysConfig.length > 0) { | ||
for (const key of keysConfig) { | ||
if (item.id === key) { | ||
if (oldConfig[key].label) { | ||
// Если в конфиге указано имя расширения | ||
item.label === oldConfig[key].label; | ||
} | ||
break; | ||
} | ||
} | ||
} | ||
} | ||
|
||
newConfig[item.id] = { | ||
uuid: item.uuid, | ||
label: item.label, | ||
}; | ||
} | ||
|
||
await setExtensionList(newConfig); | ||
|
||
vscode.window.showInformationMessage("Extension profiles: Updated the list of installed extensions"); | ||
} | ||
|
||
// Select profile ... | ||
// async function selectProfile({ ctx }: Args) { | ||
// console.log(ctx); | ||
// // vscode.commands.executeCommand('workbench.extensions.installExtension', 'extensionId'); | ||
// // vscode.commands.executeCommand("workbench.action.reloadWindow"); | ||
// // let list = vscode.commands.executeCommand("workbench.extensions.search", "@installed "); | ||
// // let list = vscode.commands.executeCommand("workbench.action.openDefaultKeybindingsFile"); | ||
// // console.log(list); | ||
// let fsPath; | ||
// if (vscode.workspace.workspaceFolders !== undefined) { | ||
// fsPath = vscode.workspace.workspaceFolders[0].uri.fsPath; | ||
// } else { | ||
// vscode.window.showErrorMessage("vscode-extension-profiles: Working folder not found, open a folder an try again"); | ||
// return; | ||
// } | ||
|
||
// console.log(await getWorkspaceUUID(vscode.Uri.parse(fsPath))); | ||
|
||
// // console.log(vscode.extensions.all.filter((e) => /^(?!\/Applications\/Visual Studio Code.app\/).*$/g.test(e.extensionPath))); | ||
// let items: vscode.QuickPickItem[] = []; | ||
|
||
// console.log(Object.keys(getProfiles())); | ||
|
||
// for (const item of Object.keys(getProfiles())) { | ||
// items.push({ | ||
// label: item, | ||
// }); | ||
// } | ||
|
||
// // for (const item of getAllExtensions()) { | ||
// // items.push({ | ||
// // label: item.packageJSON.displayName || item.packageJSON.name || item.id, | ||
// // description: item.id, | ||
// // detail: item.packageJSON.description, | ||
// // picked: true, | ||
// // }); | ||
// // } | ||
|
||
// vscode.window | ||
// .showQuickPick(items, { | ||
// canPickMany: true, | ||
// }) | ||
// .then((selection) => { | ||
// // the user canceled the selection | ||
// if (!selection) { | ||
// return; | ||
// } | ||
|
||
// console.log(selection); | ||
// }); | ||
// } | ||
// Edite profile ... | ||
function editeProfile({ ctx }: Args): any { | ||
async function editeProfile({ ctx }: Args) { | ||
console.log(ctx); | ||
vscode.window.showInformationMessage("editeProfile"); | ||
} | ||
|
||
// Delete profile ... | ||
function deleteProfile({ ctx }: Args): any { | ||
async function deleteProfile({ ctx }: Args) { | ||
console.log(ctx); | ||
vscode.window.showInformationMessage("deleteProfile"); | ||
} | ||
|
||
function ReloadWindow() { | ||
async function ReloadWindow() { | ||
vscode.commands.executeCommand("workbench.action.reloadWindow"); | ||
} |
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,13 +1,18 @@ | ||
import * as vscode from "vscode"; | ||
import { ConfigList, ExtensionList } from "./types"; | ||
|
||
export const CONFIG_KEY = "vscode-extension-profiles"; | ||
export const CONFIG_KEY_LIST = "list"; | ||
export const CONFIG_LIST_EXTENSIONS = "extensions"; | ||
|
||
type ConfigList = { | ||
[key: string]: String[]; | ||
}; | ||
|
||
export function getProfiles(): ConfigList[] { | ||
export function getProfiles(): ConfigList { | ||
return vscode.workspace.getConfiguration(CONFIG_KEY).get<any>(CONFIG_KEY_LIST); | ||
} | ||
|
||
export function getExtensionList(): ExtensionList { | ||
return vscode.workspace.getConfiguration(CONFIG_KEY).get<any>(CONFIG_LIST_EXTENSIONS); | ||
} | ||
|
||
export async function setExtensionList(value: ExtensionList) { | ||
await vscode.workspace.getConfiguration(CONFIG_KEY).update(CONFIG_LIST_EXTENSIONS, value, vscode.ConfigurationTarget.Global); | ||
} |
This file was deleted.
Oops, something went wrong.
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,45 @@ | ||
import { open } from "sqlite"; | ||
import * as sqlite3 from "sqlite3"; | ||
import * as vscode from "vscode"; | ||
import { ExtensionValue, StorageValue } from "./types"; | ||
import { getGlobalStorage } from "./utils"; | ||
|
||
|
||
export async function getDisabledExtensionsInStorage() { | ||
let pathDB = getGlobalStorage() + "/state.vscdb"; | ||
|
||
const db = await open({ | ||
filename: pathDB, | ||
driver: sqlite3.Database, | ||
}); | ||
|
||
let data = (await db.get("SELECT key, value FROM ItemTable WHERE key = ?", "extensionsIdentifiers/disabled")) as StorageValue; | ||
let value = JSON.parse(data.value) as ExtensionValue[]; | ||
|
||
return value; | ||
} | ||
|
||
export async function getAllExtensions() { | ||
const disabled = await getDisabledExtensionsInStorage(); | ||
const enabled = getEnabledExtensions(); | ||
|
||
// https://github.com/microsoft/vscode/issues/15466 | ||
// vscode.extensions.getExtension not working disabled extensions | ||
// for (const item of disabled) { | ||
// let ext = vscode.extensions.getExtension(item.id); | ||
// item.label = ext?.packageJSON.displayName || item.id; | ||
// } | ||
|
||
return [...disabled, ...enabled]; | ||
} | ||
|
||
export function getEnabledExtensions() { | ||
|
||
return vscode.extensions.all | ||
.filter((e) => /^(?!\/Applications\/Visual Studio Code.app\/).*$/g.test(e.extensionPath)) | ||
.map(item =>({ | ||
id: item.id, | ||
uuid: item?.packageJSON.uuid, | ||
label: item?.packageJSON.displayName | ||
})); | ||
} |
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,13 @@ | ||
export type StorageValue = { key: string; value: string }; | ||
export type ExtensionValue = { id: string; uuid: string; label?: string }; | ||
|
||
export type ConfigList = { | ||
[key: string]: [string]; | ||
}; | ||
|
||
export type ExtensionList = { | ||
[key: string]: { | ||
uuid: string; | ||
label?: string; | ||
}; | ||
}; |
Oops, something went wrong.