Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/extensions/copilot/test/simulation/debugTools.stest.ts
13388 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
import { LanguageToolsProvider } from '../../src/extension/onboardDebug/node/languageToolsProvider';
6
import { TestingServiceCollection } from '../../src/platform/test/node/services';
7
import { CancellationToken } from '../../src/util/vs/base/common/cancellation';
8
import { IInstantiationService } from '../../src/util/vs/platform/instantiation/common/instantiation';
9
import { ISimulationTestRuntime, ssuite, stest } from '../base/stest';
10
11
// Use to print the model's suggested tool list for all languages.
12
// Set to true and run with: npm run simulate -- --grep "print all languages" -n=1
13
const PRINT_LANGUAGE_TOOLS = false;
14
15
ssuite({ title: 'Debug tools list', location: 'context' }, () => {
16
17
async function score(testingServiceCollection: TestingServiceCollection, languages: string[], expected: string[]) {
18
const accessor = testingServiceCollection.createTestingAccessor();
19
const tools = accessor.get(IInstantiationService).createInstance(LanguageToolsProvider);
20
const result = await tools.getToolsForLanguages(languages, CancellationToken.None);
21
if (!result.ok) {
22
throw new Error('Expected tools to be found');
23
}
24
25
let found = 0;
26
for (const tool of expected) {
27
if (result.commands.includes(tool)) {
28
found++;
29
}
30
}
31
32
accessor.get(ISimulationTestRuntime).setExplicitScore(found / expected.length);
33
}
34
35
stest({ description: 'javascript' }, async (testingServiceCollection) => {
36
await score(testingServiceCollection, ['javascript'], ['npm', 'node', 'npx', 'mocha']);
37
});
38
39
stest({ description: 'c' }, async (testingServiceCollection) => {
40
await score(testingServiceCollection, ['c'], ['gcc', 'clang', 'make', 'cmake', 'gdb']);
41
});
42
43
stest({ description: 'python' }, async (testingServiceCollection) => {
44
await score(testingServiceCollection, ['python'], ['python', 'pip', 'pytest', 'tox']);
45
});
46
47
stest({ description: 'typescript' }, async (testingServiceCollection) => {
48
await score(testingServiceCollection, ['javascript'], ['npm', 'node', 'npx', 'mocha']);
49
});
50
51
stest({ description: 'ruby' }, async (testingServiceCollection) => {
52
await score(testingServiceCollection, ['ruby'], ['ruby', 'cucumber', 'rake', 'irb']);
53
});
54
55
stest({ description: 'csharp' }, async (testingServiceCollection) => {
56
await score(testingServiceCollection, ['csharp'], ['dotnet', 'msbuild', 'xunit', 'vstest']);
57
});
58
59
stest({ description: 'elixir' }, async (testingServiceCollection) => {
60
await score(testingServiceCollection, ['elixir'], ['mix', 'iex']);
61
});
62
63
stest({ description: 'lua' }, async (testingServiceCollection) => {
64
await score(testingServiceCollection, ['lua'], ['lua', 'busted']);
65
});
66
67
stest({ description: 'go' }, async (testingServiceCollection) => {
68
// it's a short list, because everything in Go is invoked with `go`.
69
// Amusingly the model sometimes just lists "go" 10 times.
70
await score(testingServiceCollection, ['go'], ['go']);
71
});
72
73
if (PRINT_LANGUAGE_TOOLS) {
74
stest({ description: 'print all languages' }, async (testingServiceCollection) => {
75
const accessor = testingServiceCollection.createTestingAccessor();
76
const tools = accessor.get(IInstantiationService).createInstance(LanguageToolsProvider);
77
const allTools = new Set<string>();
78
const allLanguageIds = new Set([
79
...baseLanguageIds,
80
...additionalLanguageIds,
81
...omittedLanguages,
82
]);
83
84
for (const language of allLanguageIds) {
85
if (omittedLanguages.includes(language)) {
86
continue;
87
}
88
89
console.log('Getting tools for', language);
90
const result = await tools.getToolsForLanguages([language], CancellationToken.None);
91
if (!result.ok) {
92
throw new Error('Expected tools to be found');
93
}
94
for (const tool of result.commands) {
95
allTools.add(tool);
96
}
97
}
98
99
console.log(`const KNOWN_DEBUGGABLE_LANGUAGES = ${JSON.stringify([...allLanguageIds].sort())};`);
100
console.log(`const KNOWN_DEBUGGABLE_COMMANDS = ${JSON.stringify([...allTools].sort())};`);
101
});
102
}
103
});
104
105
// Some additional languages popular in the 2024 SO developer survey
106
const additionalLanguageIds = [
107
'dart',
108
'zig',
109
'kotlin',
110
'matlab',
111
];
112
113
// Languages we don't want to bother getting tools for. These are text
114
// languages, markup languages that aren't specific to any one set of tools,
115
// or duplicates (e.g. vue and vue-html).
116
const omittedLanguages = [
117
'bat',
118
'bibtex',
119
'code-refactoring',
120
'coffeescript',
121
'css',
122
'diff',
123
'dockercompose',
124
'dockerfile',
125
'git-commit',
126
'git-rebase',
127
'github-issues',
128
'graphql',
129
'haml',
130
'handlebars',
131
'html',
132
'ini',
133
'jade',
134
'json',
135
'jsonc',
136
'less',
137
'log',
138
'pip-requirements',
139
'plaintext',
140
'pug',
141
'razor',
142
'scss',
143
'shellscript',
144
'slim',
145
'snippets',
146
'stylus',
147
'tex',
148
'text',
149
'toml',
150
'vue-html',
151
'xml',
152
'xsl',
153
'yaml',
154
];
155
156
// Base language list seeded from https://code.visualstudio.com/docs/languages/identifiers#_known-language-identifiers
157
const baseLanguageIds = [
158
'abap',
159
'bat',
160
'bibtex',
161
'clojure',
162
'coffeescript',
163
'c',
164
'cpp',
165
'csharp',
166
'dockercompose',
167
'css',
168
'cuda-cpp',
169
'd',
170
'pascal',
171
'diff',
172
'dockerfile',
173
'erlang',
174
'fsharp',
175
'git-commit',
176
'git-rebase',
177
'go',
178
'groovy',
179
'handlebars',
180
'haml',
181
'haskell',
182
'html',
183
'ini',
184
'java',
185
'javascript',
186
'javascriptreact',
187
'json',
188
'jsonc',
189
'julia',
190
'latex',
191
'less',
192
'lua',
193
'makefile',
194
'markdown',
195
'objective-c',
196
'objective-cpp',
197
'ocaml',
198
'pascal',
199
'perl',
200
'perl6',
201
'php',
202
'plaintext',
203
'powershell',
204
'jade',
205
'pug',
206
'python',
207
'r',
208
'razor',
209
'ruby',
210
'rust',
211
'scss',
212
'sass',
213
'shaderlab',
214
'shellscript',
215
'slim',
216
'sql',
217
'stylus',
218
'svelte',
219
'swift',
220
'typescript',
221
'typescriptreact',
222
'tex',
223
'vb',
224
'vue',
225
'vue-html',
226
'xml',
227
'xsl',
228
'yaml'
229
];
230
231