Skip to content

Commit

Permalink
feat: enhance VSCode path detection and add command category
Browse files Browse the repository at this point in the history
fix #3
  • Loading branch information
wolfsilver committed Dec 24, 2024
1 parent 753c38b commit 9e0ef75
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
14 changes: 12 additions & 2 deletions extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,14 @@ let step = 0;


function getVSCodePath() {
const app = path.dirname(require.main.filename);
const app = require.main
? path.dirname(require.main.filename)
: globalThis._VSCODE_FILE_ROOT;
if (!app) {
vscode.window.showInformationMessage("Unable to locate the installation path of VSCode. This extension won't work.");
return false;
}

BASE_PATH = path.join(app, "vs", "workbench");
}

Expand Down Expand Up @@ -68,6 +75,7 @@ async function patch() {
const config = vscode.workspace.getConfiguration("git-submodule-sort");
const data = await fs.promises.readFile(path.resolve(BASE_PATH, backUpFileName), 'utf8')
const ast = parse(data, {
sourceType: 'module',
plugins: [
"classStaticBlock",
],
Expand Down Expand Up @@ -194,7 +202,9 @@ function transformer(ast, sortRepositoriesBody) {
* @param {vscode.ExtensionContext} context
*/
function activate(context) {
getVSCodePath();
if (getVSCodePath() === false) {
return;
}

// The command has been defined in the package.json file
// Now provide the implementation of the command with registerCommand
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
"commands": [
{
"command": "git-submodule-sort.patch",
"title": "Enable git submodule sort"
"title": "Enable git submodule sort",
"category": "Git"
}
],
"configuration": {
Expand Down

0 comments on commit 9e0ef75

Please sign in to comment.