-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathextension.js
More file actions
101 lines (87 loc) · 2.5 KB
/
extension.js
File metadata and controls
101 lines (87 loc) · 2.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
// @ts-check
'use strict';
const vscode = require('vscode');
const path = require('path');
const { generateMap } = require('./tree.js');
/**
* @param {vscode.ExtensionContext} context
*/
function activate(context) {
function getConfig() {
const cfg = vscode.workspace.getConfiguration('mapify');
return {
maxDepth: cfg.get('maxDepth', 4),
showSemanticLabels: cfg.get('showSemanticLabels', true),
copyToClipboard: cfg.get('copyToClipboard', true),
};
}
/**
* @param {string} rootPath
*/
async function runMapify(rootPath) {
const { maxDepth, showSemanticLabels, copyToClipboard } = getConfig();
const map = await vscode.window.withProgress(
{
location: vscode.ProgressLocation.Notification,
title: 'Mapify: generating project map…',
cancellable: false,
},
async () => generateMap(rootPath, maxDepth, showSemanticLabels)
);
if (copyToClipboard) {
await vscode.env.clipboard.writeText(map);
}
const doc = await vscode.workspace.openTextDocument({
language: 'plaintext',
content: map,
});
await vscode.window.showTextDocument(doc, {
preview: false,
viewColumn: vscode.ViewColumn.Beside,
});
const label = path.basename(rootPath);
const suffix = copyToClipboard ? ' and copied to clipboard.' : '.';
vscode.window.showInformationMessage(`Mapify: map for "${label}" generated${suffix}`);
}
// Command palette → map the whole workspace
context.subscriptions.push(
vscode.commands.registerCommand('mapify.generateMap', async () => {
const folders = vscode.workspace.workspaceFolders;
if (!folders || folders.length === 0) {
vscode.window.showErrorMessage('Mapify: no workspace folder is open.');
return;
}
let rootPath;
if (folders.length === 1) {
rootPath = folders[0].uri.fsPath;
} else {
const picks = folders.map(f => ({
label: f.name,
description: f.uri.fsPath,
fsPath: f.uri.fsPath,
}));
const choice = await vscode.window.showQuickPick(picks, {
placeHolder: 'Select workspace root to map',
});
if (!choice) { return; }
rootPath = choice.fsPath;
}
await runMapify(rootPath);
})
);
// Right-click a folder in Explorer
context.subscriptions.push(
vscode.commands.registerCommand('mapify.generateMapFromFolder', async (uri) => {
if (!uri) {
vscode.window.showErrorMessage('Mapify: right-click a folder in the Explorer.');
return;
}
await runMapify(uri.fsPath);
})
);
}
function deactivate() {}
module.exports = {
activate,
deactivate
};