-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add context to the Copilot Chat #12044
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,7 +19,7 @@ | |
import * as util from '../common'; | ||
import { PlatformInformation } from '../platform'; | ||
import * as telemetry from '../telemetry'; | ||
import { Client, DefaultClient, DoxygenCodeActionCommandArguments, openFileVersions } from './client'; | ||
import { ChatContextResult, Client, DefaultClient, DoxygenCodeActionCommandArguments, openFileVersions } from './client'; | ||
import { ClientCollection } from './clientCollection'; | ||
import { CodeActionDiagnosticInfo, CodeAnalysisDiagnosticIdentifiersAndUri, codeAnalysisAllFixes, codeAnalysisCodeToFixes, codeAnalysisFileToCodeActions } from './codeAnalysis'; | ||
import { CppBuildTaskProvider } from './cppBuildTaskProvider'; | ||
|
@@ -246,6 +246,78 @@ | |
clients.timeTelemetryCollector.setFirstFile(activeEditor.document.uri); | ||
activeDocument = activeEditor.document; | ||
} | ||
|
||
await setupCppChatVariable(util.extensionContext); | ||
} | ||
|
||
export async function setupCppChatVariable(context: vscode.ExtensionContext | undefined): Promise<void> | ||
{ | ||
if (!context) { | ||
return; | ||
} | ||
|
||
vscode.chat.registerChatVariableResolver('cpp', | ||
lukka marked this conversation as resolved.
Show resolved
Hide resolved
|
||
`Describes the the C++ language features that can be used according | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. duplicated word "the the" |
||
to the following information: the C++ language standard version, the target architecture and target operating system.`, { | ||
resolve: async (name, _context, _token) => { | ||
function fixUpLanguage(languageId: string) { | ||
const languageIdToLanguage: { [id: string]: string } = | ||
{ 'c': 'C', 'cpp': 'C++', 'cuda-cpp': 'CUDA C++' }; | ||
return languageIdToLanguage[languageId] || languageId; | ||
} | ||
|
||
function fixUpCompiler(compilerId: string) { | ||
const compilerIdToCompiler: { [id: string]: string } = | ||
{ 'msvc': 'MSVC', 'clang': 'Clang', 'gcc': 'GCC' }; | ||
return compilerIdToCompiler[compilerId] || compilerId; | ||
} | ||
|
||
function fixUpStandardVersion(stdVerId: string) { | ||
const stdVerIdToStdVer: { [id: string]: string } = | ||
{ 'c++98': 'C++98', 'c++03': 'C++03', 'c++11': 'C++11', 'c++14': 'C++14', 'c++17': 'C++17', | ||
'c++20': 'C++20', 'c++23': 'C++23', 'c90' : "C90", 'c99': "C99", 'c11': "C11", 'c17': "C17", | ||
Check warning on line 278 in Extension/src/LanguageServer/extension.ts GitHub Actions / job / build
Check warning on line 278 in Extension/src/LanguageServer/extension.ts GitHub Actions / job / build
|
||
'c23': "C23" }; | ||
Check warning on line 279 in Extension/src/LanguageServer/extension.ts GitHub Actions / job / build
Check warning on line 279 in Extension/src/LanguageServer/extension.ts GitHub Actions / job / build
|
||
return stdVerIdToStdVer[stdVerId] || stdVerId; | ||
} | ||
|
||
function fixTargetPlatform(targetPlatformId: string) { | ||
const platformIdToPlatform: { [id: string]: string } = { 'windows': 'Windows', 'Linux': 'Linux', 'macos': 'macOS' }; | ||
return platformIdToPlatform[targetPlatformId] || targetPlatformId; | ||
} | ||
|
||
if (name !== 'cpp') { | ||
return undefined; | ||
} | ||
|
||
// Return undefined if the active document is not a C++/C/CUDA/Header file. | ||
const currentDoc = vscode.window.activeTextEditor?.document; | ||
if (!currentDoc || (!util.isCpp(currentDoc) && !util.isHeaderFile(currentDoc.uri))) { | ||
return undefined; | ||
} | ||
|
||
const chatContext: ChatContextResult | undefined = await getChatContext(); | ||
if (!chatContext) { | ||
return undefined; | ||
} | ||
|
||
telemetry.logCppChatVariableEvent('cpp', | ||
{ "language": chatContext.language, "compiler": chatContext.compiler, "standardVersion": chatContext.standardVersion, | ||
"targetPlatform": chatContext.targetPlatform, "targetArchitecture": chatContext.targetArchitecture }); | ||
Check warning on line 305 in Extension/src/LanguageServer/extension.ts GitHub Actions / job / build
Check warning on line 305 in Extension/src/LanguageServer/extension.ts GitHub Actions / job / build
|
||
|
||
const language = fixUpLanguage(chatContext.language); | ||
const compiler = fixUpCompiler(chatContext.compiler); | ||
const standardVersion = fixUpStandardVersion(chatContext.standardVersion); | ||
const targetPlatform = fixTargetPlatform(chatContext.targetPlatform); | ||
const value = `I am working on a project of the following nature: | ||
- Using ${language}. Prefer a solution written in ${language} to any other language. Call out which language you are using in the answer. | ||
- Using the ${language} standard language version ${standardVersion}. Prefer solutions using the new and more recent features introduced in ${standardVersion}. Call out which standard version you are using in the answer. | ||
- Using the ${compiler} compiler. Prefer solutions supported by the ${compiler} compiler. | ||
- Targeting the ${targetPlatform} platform. Prefer solutions and API that are supported on ${targetPlatform}. | ||
- Targeting the ${chatContext.targetArchitecture} architecture. Prefer solutions and techniques that are supported on the ${chatContext.targetArchitecture} architecture. | ||
`; | ||
return [ { level: vscode.ChatVariableLevel.Full, value: value } ]; | ||
} | ||
}); | ||
} | ||
|
||
export function updateLanguageConfigurations(): void { | ||
|
@@ -1305,3 +1377,7 @@ | |
} | ||
} | ||
} | ||
|
||
export async function getChatContext(): Promise<ChatContextResult | undefined> { | ||
return clients?.ActiveClient?.getChatContext() ?? undefined; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We will need approval to use these APIs before this PR can be approved.