-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathstart.ts
267 lines (217 loc) · 10.9 KB
/
start.ts
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
import { setup } from './utils';
import * as path from 'path';
import { execaCommand } from 'execa';
import * as fs from 'fs';
import * as assert from 'assert';
const sample = 1; // less for faster, bigger for smooth numbers
(async () => {
const context = await setup(path.join(__dirname, 'servers'), {
'v2.1.6': { npm: '@vue/language-server@2.1.6', bin: './bin/vue-language-server.js' },
});
const libraries: {
name: string;
deps: string[];
version: string;
}[] = [
{ name: 'vanilla', deps: ['vue'], version: 'latest' },
{ name: 'ant-design-vue', deps: ['ant-design-vue'], version: 'latest' },
{ name: 'anu-vue', deps: ['anu-vue'], version: 'latest' },
{ name: 'bootstrap-vue-next', deps: ['bootstrap-vue-next'], version: 'latest' },
{ name: 'element-plus', deps: ['element-plus'], version: 'latest' },
{ name: 'naive-ui', deps: ['naive-ui'], version: 'latest' },
{ name: 'oku-ui', deps: ['@oku-ui/primitives'], version: 'latest' },
{ name: 'quasar', deps: ['quasar'], version: 'latest' },
{ name: 'radix-vue', deps: ['radix-vue'], version: 'latest' },
{ name: 'vuetify', deps: ['vuetify'], version: 'latest' },
{ name: 'vant', deps: ['vant'], version: 'latest' },
// NO TS
// { name: 'primevue', deps: ['primevue'], version: 'latest' },
// { name: 'keen-ui', deps: ['keen-ui'], version: 'latest' },
];
const pathCompletionTsvRows: (string | number)[][] = [['']];
const autoImportTsvRows: (string | number)[][] = [['']];
const setupContextTsvRows: (string | number)[][] = [['']];
const tempPath = path.join(__dirname, 'temp');
if (!fs.existsSync(tempPath)) {
fs.mkdirSync(tempPath);
}
for (const library of libraries) {
console.log(library.name + '...');
pathCompletionTsvRows[0].push(library.name);
autoImportTsvRows[0].push(library.name);
setupContextTsvRows[0].push(library.name);
/**
* Setup
*/
const folder = path.join(tempPath, library.name);
if (!fs.existsSync(folder)) {
fs.mkdirSync(folder);
const dependencies = { vue: 'latest' };
for (const dep of library.deps) {
dependencies[dep] = library.version;
}
fs.writeFileSync(path.join(folder, 'package.json'), JSON.stringify({ dependencies }));
fs.writeFileSync(path.join(folder, 'tsconfig.json'), JSON.stringify({}));
await execaCommand(`pnpm i`, { cwd: folder }).pipeStdout?.(process.stdout);
}
/**
* Path Completion
*/
fs.writeFileSync(path.join(folder, 'App.vue'), [
`<script setup lang="ts">`,
...library.deps.map(dep => `import {} from '${dep}';`),
`import {} from './';`,
`</script>`,
].join('\n'));
const pathCompletionResult = await context.start({
rootPath: folder,
repeatTimes: sample,
}, async (connection, timekeeper, helpers) => {
connection.onRequest('client/registerCapability', () => { /* ignore */ });
connection.onRequest('workspace/configuration', () => { /* ignore */ });
await helpers.initialize({ typescript: { tsdk: path.join(__dirname, 'node_modules', 'typescript', 'lib') } });
let document = await helpers.openDocument('./App.vue', 'vue');
await helpers.requestCompletion(document, document.positionAt(document.getText().lastIndexOf(`';`))); // ignore first time
for (let i = 0; i < 50; i++) {
await timekeeper(async () => {
document = await helpers.editDocument(
document,
document.positionAt(0),
document.positionAt(document.getText().length),
document.getText().includes(`'./';`)
? document.getText().replace(`'./';`, `'';`)
: document.getText().replace(`'';`, `'./';`)
);
await helpers.requestCompletion(document, document.positionAt(document.getText().lastIndexOf(`';`)));
});
}
});
/**
* Global Completion
*/
fs.writeFileSync(path.join(folder, 'App.vue'), [
`<script lang="ts">`,
...library.deps.map(dep => `import {} from '${dep}';`),
`/* __complete__ */`,
`</script>`,
].join('\n'));
const autoImportResult = await context.start({
rootPath: folder,
repeatTimes: sample,
}, async (connection, timekeeper, helpers) => {
connection.onRequest('client/registerCapability', () => { /* ignore */ });
connection.onRequest('workspace/configuration', () => { /* ignore */ });
await helpers.initialize({ typescript: { tsdk: path.join(__dirname, 'node_modules', 'typescript', 'lib') } });
let document = await helpers.openDocument('./App.vue', 'vue');
const getActionPos = () => document.positionAt(document.getText().lastIndexOf(`/* __complete__ */`));
const doComplete = async () => {
const completeResult = await helpers.requestCompletion(document, getActionPos());
assert.equal((completeResult as any).items.some(item => item.label === 'watch'), true);
};
await helpers.requestCompletion(document, getActionPos()); // ignore first time
for (let i = 0; i < 10; i++) {
await timekeeper(async () => {
document = await helpers.editDocument(document, getActionPos(), getActionPos(), 'w');
await doComplete();
});
await timekeeper(async () => {
document = await helpers.editDocument(document, getActionPos(), getActionPos(), 'a');
await doComplete();
});
await timekeeper(async () => {
document = await helpers.editDocument(document, getActionPos(), getActionPos(), 't');
await doComplete();
});
await timekeeper(async () => {
document = await helpers.editDocument(document, getActionPos(), getActionPos(), 'c');
await doComplete();
});
await timekeeper(async () => {
document = await helpers.editDocument(document, getActionPos(), getActionPos(), 'h');
await doComplete();
});
// delete added text
document = await helpers.editDocument(document, { line: getActionPos().line, character: getActionPos().character - 5 }, getActionPos(), '');
}
});
/**
* setup() Completion
*/
fs.writeFileSync(path.join(folder, 'App.vue'), [
`<script lang="ts">`,
...library.deps.map(dep => `import {} from '${dep}';`),
`export default { setup(props) {`,
`/* __complete__ */`,
`} }`,
`</script>`,
].join('\n'));
const setupContextResult = await context.start({
rootPath: folder,
repeatTimes: sample,
}, async (connection, timekeeper, helpers) => {
connection.onRequest('client/registerCapability', () => { /* ignore */ });
connection.onRequest('workspace/configuration', () => { /* ignore */ });
await helpers.initialize({ typescript: { tsdk: path.join(__dirname, 'node_modules', 'typescript', 'lib') } });
let document = await helpers.openDocument('./App.vue', 'vue');
const getActionPos = () => document.positionAt(document.getText().lastIndexOf(`/* __complete__ */`));
const doComplete = async () => {
const completeResult = await helpers.requestCompletion(document, getActionPos());
assert.equal((completeResult as any).items.some(item => item.label === 'props'), true);
};
await helpers.requestCompletion(document, getActionPos()); // ignore first time
for (let i = 0; i < 10; i++) {
await timekeeper(async () => {
document = await helpers.editDocument(document, getActionPos(), getActionPos(), 'p');
await doComplete();
});
await timekeeper(async () => {
document = await helpers.editDocument(document, getActionPos(), getActionPos(), 'r');
await doComplete();
});
await timekeeper(async () => {
document = await helpers.editDocument(document, getActionPos(), getActionPos(), 'o');
await doComplete();
});
await timekeeper(async () => {
document = await helpers.editDocument(document, getActionPos(), getActionPos(), 'p');
await doComplete();
});
await timekeeper(async () => {
document = await helpers.editDocument(document, getActionPos(), getActionPos(), 's');
await doComplete();
});
// delete added text
document = await helpers.editDocument(document, { line: getActionPos().line, character: getActionPos().character - 5 }, getActionPos(), '');
}
});
const times_1 = Object.values(pathCompletionResult)[0];
for (let j = 0; j < times_1.length; j++) {
if (pathCompletionTsvRows.length <= j + 1) {
pathCompletionTsvRows.push([j + 1]);
}
pathCompletionTsvRows[j + 1].push(times_1[j])
}
const times_2 = Object.values(autoImportResult)[0];
for (let j = 0; j < times_2.length; j++) {
if (autoImportTsvRows.length <= j + 1) {
autoImportTsvRows.push([j + 1]);
}
autoImportTsvRows[j + 1].push(times_2[j])
}
const times_3 = Object.values(setupContextResult)[0];
for (let j = 0; j < times_3.length; j++) {
if (setupContextTsvRows.length <= j + 1) {
setupContextTsvRows.push([j + 1]);
}
setupContextTsvRows[j + 1].push(times_3[j])
}
}
saveTsv(path.join(tempPath, 'path_completion.tsv'), pathCompletionTsvRows.map(arr => arr.join('\t')).join('\n'));
saveTsv(path.join(tempPath, 'global_completion.tsv'), autoImportTsvRows.map(arr => arr.join('\t')).join('\n'));
saveTsv(path.join(tempPath, 'setup_function_completion.tsv'), setupContextTsvRows.map(arr => arr.join('\t')).join('\n'));
})();
function saveTsv(path: string, data: string) {
console.log(data);
console.log(path);
fs.writeFileSync(path, data);
}