-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathextension.js
74 lines (59 loc) · 1.9 KB
/
extension.js
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
const vscode = require('vscode');
const registerCommands = require('./src/commands');
const registerProviders = require('./src/providers');
const { ConfigParser } = require('./src/parser');
const userConfig = require('./src/user-config');
const { ACTIONS } = require('./src/constants');
/**
* @param {vscode.ExtensionContext} context
*/
async function activate(context) {
registerCommands(userConfig);
let { file, type, accessPath } = userConfig.getConfig();
if (!file) {
const prompt = await vscode.window.showInformationMessage(
`Welcome to alias-resolver extension! Do you want to configure the extension now?`,
ACTIONS.CONFIGURE,
ACTIONS.CLOSE
);
if (!prompt || prompt === ACTIONS.CLOSE) {
return;
}
({
file,
type,
accessPath,
} = await userConfig.configureExtensionSettings());
if (!file) {
return;
}
}
// TODO: Refactor how this is handle so there's no repeated code
vscode.workspace.onDidChangeConfiguration((event) => {
if (event.affectsConfiguration('alias-resolver')) {
const { file, type, accessPath } = userConfig.getConfig();
vscode.workspace.findFiles(file, '**/node_modules/**').then((result) => {
const path = result[0].path;
const config = require(path);
vscode.window.showInformationMessage(
`Using ${file} to resolve alias paths`
);
ConfigParser.createMappingsFromConfig(config, { type, accessPath });
});
}
});
vscode.workspace.findFiles(file, '**/node_modules/**').then((result) => {
const path = result[0].path;
const config = require(path);
vscode.window.showInformationMessage(
`Using ${file} to resolve alias paths`
);
ConfigParser.createMappingsFromConfig(config, { type, accessPath });
registerProviders(context);
});
}
function deactivate() {}
module.exports = {
activate,
deactivate,
};