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