/
index.js
68 lines (61 loc) · 1.67 KB
/
index.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
'use strict';
const {
LanguageClient,
SettingMonitor,
ExecuteCommandRequest,
} = require('vscode-languageclient/node');
const { workspace, commands: Commands, window: Window } = require('vscode');
/**
* @param {vscode.ExtensionContext} context
*/
exports.activate = ({ subscriptions }) => {
const serverPath = require.resolve('./server.js');
const client = new LanguageClient(
'stylelint',
{
run: {
module: serverPath,
},
debug: {
module: serverPath,
options: {
execArgv: ['--nolazy', '--inspect=6004'],
},
},
},
{
documentSelector: [{ scheme: 'file' }, { scheme: 'untitled' }],
diagnosticCollectionName: 'stylelint',
synchronize: {
configurationSection: 'stylelint',
fileEvents: workspace.createFileSystemWatcher(
'**/{.stylelintrc{,.js,.json,.yaml,.yml},stylelint.config.js,.stylelintignore}',
),
},
},
);
subscriptions.push(
Commands.registerCommand('stylelint.executeAutofix', async () => {
const textEditor = Window.activeTextEditor;
if (!textEditor) {
return;
}
const textDocument = {
uri: textEditor.document.uri.toString(),
version: textEditor.document.version,
};
const params = {
command: 'stylelint.applyAutoFix',
// https://github.com/microsoft/TypeScript/issues/43362
/* prettier-ignore */
'arguments': [textDocument],
};
await client.sendRequest(ExecuteCommandRequest.type, params).then(undefined, () => {
Window.showErrorMessage(
'Failed to apply stylelint fixes to the document. Please consider opening an issue with steps to reproduce.',
);
});
}),
);
subscriptions.push(new SettingMonitor(client, 'stylelint.enable').start());
};