From 7befc52b872c256d2fc4ab7eecbc8d06f7515a15 Mon Sep 17 00:00:00 2001 From: luca <681992+lukka@users.noreply.github.com> Date: Fri, 7 Feb 2025 19:10:31 -0800 Subject: [PATCH 1/4] add test frameworks traits to VSCode Copilot Chat --- Extension/src/LanguageServer/client.ts | 1 + Extension/src/LanguageServer/lmTool.ts | 5 ++++- .../scenarios/SingleRootProject/tests/lmTool.test.ts | 12 +++++++----- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/Extension/src/LanguageServer/client.ts b/Extension/src/LanguageServer/client.ts index 1386e3f62..2d0c757d8 100644 --- a/Extension/src/LanguageServer/client.ts +++ b/Extension/src/LanguageServer/client.ts @@ -554,6 +554,7 @@ export interface ChatContextResult { compiler: string; targetPlatform: string; targetArchitecture: string; + testFrameworks: string[]; } interface FolderFilesEncodingChanged { diff --git a/Extension/src/LanguageServer/lmTool.ts b/Extension/src/LanguageServer/lmTool.ts index 40f48e7dd..642d64097 100644 --- a/Extension/src/LanguageServer/lmTool.ts +++ b/Extension/src/LanguageServer/lmTool.ts @@ -168,7 +168,10 @@ export class CppConfigurationLanguageModelTool implements vscode.LanguageModelTo contextString += `The project targets the ${chatContext.targetArchitecture} architecture. `; telemetryProperties["targetArchitecture"] = chatContext.targetArchitecture; } - + if (chatContext.testFrameworks) { + contextString += `The project uses the following C++ test frameworks: ${chatContext.testFrameworks.join(', ')} . `; + telemetryProperties["testFrameworks"] = chatContext.testFrameworks.join(','); + } return contextString; } catch { diff --git a/Extension/test/scenarios/SingleRootProject/tests/lmTool.test.ts b/Extension/test/scenarios/SingleRootProject/tests/lmTool.test.ts index f91e394e5..e6815f089 100644 --- a/Extension/test/scenarios/SingleRootProject/tests/lmTool.test.ts +++ b/Extension/test/scenarios/SingleRootProject/tests/lmTool.test.ts @@ -130,8 +130,8 @@ describe('CppConfigurationLanguageModelTool Tests', () => { }); const arrangeChatContextFromCppTools = ({ chatContextFromCppTools, isCpp, isHeaderFile }: - { chatContextFromCppTools?: ChatContextResult; isCpp?: boolean; isHeaderFile?: boolean } = - { chatContextFromCppTools: undefined, isCpp: undefined, isHeaderFile: false } + { chatContextFromCppTools?: ChatContextResult; isCpp?: boolean; isHeaderFile?: boolean } = + { chatContextFromCppTools: undefined, isCpp: undefined, isHeaderFile: false } ) => { activeClientStub.getChatContext.resolves(chatContextFromCppTools); sinon.stub(util, 'isCpp').returns(isCpp ?? true); @@ -145,7 +145,8 @@ describe('CppConfigurationLanguageModelTool Tests', () => { standardVersion: 'c++20', compiler: 'msvc', targetPlatform: 'windows', - targetArchitecture: 'x64' + targetArchitecture: 'x64', + testFrameworks: ['gtest', 'catch2'] } }); @@ -157,12 +158,13 @@ describe('CppConfigurationLanguageModelTool Tests', () => { "compiler": 'MSVC', "standardVersion": 'C++20', "targetPlatform": 'Windows', - "targetArchitecture": 'x64' + "targetArchitecture": 'x64', + 'testFrameworks': 'gtest,catch2' }))); ok(result, 'result should not be undefined'); const text = result.content[0] as vscode.LanguageModelTextPart; ok(text, 'result should contain a text part'); - ok(text.value === 'The user is working on a C++ project. The project uses language version C++20. The project compiles using the MSVC compiler. The project targets the Windows platform. The project targets the x64 architecture. '); + ok(text.value === 'The user is working on a C++ project. The project uses language version C++20. The project compiles using the MSVC compiler. The project targets the Windows platform. The project targets the x64 architecture. The project uses the following C++ test frameworks: gtest, catch2 .'); }); const testGetProjectContext = async ({ From ea9ef3f28625af2c7b72afa943148b4945b0b42b Mon Sep 17 00:00:00 2001 From: luca <681992+lukka@users.noreply.github.com> Date: Fri, 14 Feb 2025 15:40:46 -0800 Subject: [PATCH 2/4] add test framework traits for #cpp --- Extension/src/LanguageServer/client.ts | 2 +- Extension/src/LanguageServer/lmTool.ts | 6 +++--- .../test/scenarios/SingleRootProject/tests/lmTool.test.ts | 5 +++-- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/Extension/src/LanguageServer/client.ts b/Extension/src/LanguageServer/client.ts index 2d0c757d8..8a7ae0cec 100644 --- a/Extension/src/LanguageServer/client.ts +++ b/Extension/src/LanguageServer/client.ts @@ -554,7 +554,7 @@ export interface ChatContextResult { compiler: string; targetPlatform: string; targetArchitecture: string; - testFrameworks: string[]; + usedTestFrameworks: string[]; } interface FolderFilesEncodingChanged { diff --git a/Extension/src/LanguageServer/lmTool.ts b/Extension/src/LanguageServer/lmTool.ts index 642d64097..38256c3fb 100644 --- a/Extension/src/LanguageServer/lmTool.ts +++ b/Extension/src/LanguageServer/lmTool.ts @@ -168,9 +168,9 @@ export class CppConfigurationLanguageModelTool implements vscode.LanguageModelTo contextString += `The project targets the ${chatContext.targetArchitecture} architecture. `; telemetryProperties["targetArchitecture"] = chatContext.targetArchitecture; } - if (chatContext.testFrameworks) { - contextString += `The project uses the following C++ test frameworks: ${chatContext.testFrameworks.join(', ')} . `; - telemetryProperties["testFrameworks"] = chatContext.testFrameworks.join(','); + if (chatContext.usedTestFrameworks?.length > 0) { + contextString += `The active document contains the content of the file '${currentDoc.fileName}' which is located in a directory structure where other files are including headers for the following C++ test frameworks: ${chatContext.usedTestFrameworks.join(', ')} . `; + telemetryProperties["testFrameworks"] = chatContext.usedTestFrameworks.join(','); } return contextString; } diff --git a/Extension/test/scenarios/SingleRootProject/tests/lmTool.test.ts b/Extension/test/scenarios/SingleRootProject/tests/lmTool.test.ts index e6815f089..73ce82412 100644 --- a/Extension/test/scenarios/SingleRootProject/tests/lmTool.test.ts +++ b/Extension/test/scenarios/SingleRootProject/tests/lmTool.test.ts @@ -146,7 +146,7 @@ describe('CppConfigurationLanguageModelTool Tests', () => { compiler: 'msvc', targetPlatform: 'windows', targetArchitecture: 'x64', - testFrameworks: ['gtest', 'catch2'] + usedTestFrameworks: ['gtest', 'catch2'] } }); @@ -164,7 +164,8 @@ describe('CppConfigurationLanguageModelTool Tests', () => { ok(result, 'result should not be undefined'); const text = result.content[0] as vscode.LanguageModelTextPart; ok(text, 'result should contain a text part'); - ok(text.value === 'The user is working on a C++ project. The project uses language version C++20. The project compiles using the MSVC compiler. The project targets the Windows platform. The project targets the x64 architecture. The project uses the following C++ test frameworks: gtest, catch2 .'); + const traits_text = `The user is working on a C++ project. The project uses language version C++20. The project compiles using the MSVC compiler. The project targets the Windows platform. The project targets the x64 architecture. The active document contains the content of the file 'undefined' which is located in a directory structure where other files are including headers for the following C++ test frameworks: gtest, catch2 . `; + ok(text.value === traits_text); }); const testGetProjectContext = async ({ From 5fe53531af610745dc00e564cc23ce14fb7815f6 Mon Sep 17 00:00:00 2001 From: luca <681992+lukka@users.noreply.github.com> Date: Tue, 18 Feb 2025 18:36:23 -0800 Subject: [PATCH 3/4] update prompt --- Extension/src/LanguageServer/lmTool.ts | 4 ++-- .../scenarios/SingleRootProject/tests/lmTool.test.ts | 10 ++++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/Extension/src/LanguageServer/lmTool.ts b/Extension/src/LanguageServer/lmTool.ts index 38256c3fb..7ad5aafb1 100644 --- a/Extension/src/LanguageServer/lmTool.ts +++ b/Extension/src/LanguageServer/lmTool.ts @@ -169,8 +169,8 @@ export class CppConfigurationLanguageModelTool implements vscode.LanguageModelTo telemetryProperties["targetArchitecture"] = chatContext.targetArchitecture; } if (chatContext.usedTestFrameworks?.length > 0) { - contextString += `The active document contains the content of the file '${currentDoc.fileName}' which is located in a directory structure where other files are including headers for the following C++ test frameworks: ${chatContext.usedTestFrameworks.join(', ')} . `; - telemetryProperties["testFrameworks"] = chatContext.usedTestFrameworks.join(','); + contextString += `The project uses the following C++ test frameworks: ${chatContext.usedTestFrameworks.join(', ')}. `; + telemetryProperties["testFrameworks"] = chatContext.usedTestFrameworks.join(', '); } return contextString; } diff --git a/Extension/test/scenarios/SingleRootProject/tests/lmTool.test.ts b/Extension/test/scenarios/SingleRootProject/tests/lmTool.test.ts index 73ce82412..03a36af3f 100644 --- a/Extension/test/scenarios/SingleRootProject/tests/lmTool.test.ts +++ b/Extension/test/scenarios/SingleRootProject/tests/lmTool.test.ts @@ -159,12 +159,12 @@ describe('CppConfigurationLanguageModelTool Tests', () => { "standardVersion": 'C++20', "targetPlatform": 'Windows', "targetArchitecture": 'x64', - 'testFrameworks': 'gtest,catch2' + 'testFrameworks': 'gtest, catch2' }))); ok(result, 'result should not be undefined'); const text = result.content[0] as vscode.LanguageModelTextPart; ok(text, 'result should contain a text part'); - const traits_text = `The user is working on a C++ project. The project uses language version C++20. The project compiles using the MSVC compiler. The project targets the Windows platform. The project targets the x64 architecture. The active document contains the content of the file 'undefined' which is located in a directory structure where other files are including headers for the following C++ test frameworks: gtest, catch2 . `; + const traits_text = `The user is working on a C++ project. The project uses language version C++20. The project compiles using the MSVC compiler. The project targets the Windows platform. The project targets the x64 architecture. The project uses the following C++ test frameworks: gtest, catch2. `; ok(text.value === traits_text); }); @@ -187,7 +187,8 @@ describe('CppConfigurationLanguageModelTool Tests', () => { standardVersion: 'c++20', compiler: compiler, targetPlatform: 'windows', - targetArchitecture: 'x64' + targetArchitecture: 'x64', + usedTestFrameworks: [] } }); @@ -228,7 +229,8 @@ describe('CppConfigurationLanguageModelTool Tests', () => { standardVersion: 'gnu++17', compiler: 'javac', targetPlatform: 'arduino', - targetArchitecture: 'bar' + targetArchitecture: 'bar', + usedTestFrameworks: [] } }); const telemetryProperties: Record = {}; From 1083d4e02500440797a91f4511b0cd12f9c1d2bc Mon Sep 17 00:00:00 2001 From: luca <681992+lukka@users.noreply.github.com> Date: Wed, 5 Mar 2025 17:49:45 -0800 Subject: [PATCH 4/4] drop unnecessary `?.`, and use sensible names for test framework in tests. --- Extension/src/LanguageServer/lmTool.ts | 2 +- .../test/scenarios/SingleRootProject/tests/lmTool.test.ts | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Extension/src/LanguageServer/lmTool.ts b/Extension/src/LanguageServer/lmTool.ts index 7ad5aafb1..1802034e1 100644 --- a/Extension/src/LanguageServer/lmTool.ts +++ b/Extension/src/LanguageServer/lmTool.ts @@ -168,7 +168,7 @@ export class CppConfigurationLanguageModelTool implements vscode.LanguageModelTo contextString += `The project targets the ${chatContext.targetArchitecture} architecture. `; telemetryProperties["targetArchitecture"] = chatContext.targetArchitecture; } - if (chatContext.usedTestFrameworks?.length > 0) { + if (chatContext.usedTestFrameworks.length > 0) { contextString += `The project uses the following C++ test frameworks: ${chatContext.usedTestFrameworks.join(', ')}. `; telemetryProperties["testFrameworks"] = chatContext.usedTestFrameworks.join(', '); } diff --git a/Extension/test/scenarios/SingleRootProject/tests/lmTool.test.ts b/Extension/test/scenarios/SingleRootProject/tests/lmTool.test.ts index 03a36af3f..3b45b308e 100644 --- a/Extension/test/scenarios/SingleRootProject/tests/lmTool.test.ts +++ b/Extension/test/scenarios/SingleRootProject/tests/lmTool.test.ts @@ -146,7 +146,7 @@ describe('CppConfigurationLanguageModelTool Tests', () => { compiler: 'msvc', targetPlatform: 'windows', targetArchitecture: 'x64', - usedTestFrameworks: ['gtest', 'catch2'] + usedTestFrameworks: ['GTest', 'Catch2'] } }); @@ -159,12 +159,12 @@ describe('CppConfigurationLanguageModelTool Tests', () => { "standardVersion": 'C++20', "targetPlatform": 'Windows', "targetArchitecture": 'x64', - 'testFrameworks': 'gtest, catch2' + 'testFrameworks': 'GTest, Catch2' }))); ok(result, 'result should not be undefined'); const text = result.content[0] as vscode.LanguageModelTextPart; ok(text, 'result should contain a text part'); - const traits_text = `The user is working on a C++ project. The project uses language version C++20. The project compiles using the MSVC compiler. The project targets the Windows platform. The project targets the x64 architecture. The project uses the following C++ test frameworks: gtest, catch2. `; + const traits_text = `The user is working on a C++ project. The project uses language version C++20. The project compiles using the MSVC compiler. The project targets the Windows platform. The project targets the x64 architecture. The project uses the following C++ test frameworks: GTest, Catch2. `; ok(text.value === traits_text); });