-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrename.test.js
65 lines (57 loc) · 1.66 KB
/
rename.test.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
const assert = require('node:assert');
const path = require('node:path');
const vscode = require('vscode');
const { showFile, sleepCI } = require('../util');
const stylesUri = vscode.Uri.file(
path.resolve(__dirname, 'fixtures', 'styles.scss')
);
before(async () => {
await showFile(stylesUri);
await sleepCI();
});
after(async () => {
await vscode.commands.executeCommand('workbench.action.closeAllEditors');
});
/**
* @param {import('vscode').Uri} documentUri
* @param {import('vscode').Position} position
* @returns {Promise<{ range: import('vscode').Range, placeholder: string }>}
*/
async function prepareRename(documentUri, position) {
const result = await vscode.commands.executeCommand(
'vscode.prepareRename',
documentUri,
position
);
return result;
}
/**
* @param {import('vscode').Uri} documentUri
* @param {import('vscode').Position} position
* @param {string} newName
* @returns {Promise<import('vscode').WorkspaceEdit>}
*/
async function rename(documentUri, position, newName) {
const result = await vscode.commands.executeCommand(
'vscode.executeDocumentRenameProvider',
documentUri,
position,
newName
);
return result;
}
test('renames symbol across workspace', async () => {
const preparation = await prepareRename(
stylesUri,
new vscode.Position(3, 20)
);
assert.ok(preparation, 'Should have a result from prepare rename');
assert.equal(preparation.placeholder, 'color-primary');
const result = await rename(
stylesUri,
preparation.range.start,
'color-secondary'
);
assert.ok(result, 'Should have returned a workspace edit response');
assert.equal(result.entries().length, 3);
});