-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Add C++ configuration as a language model tool (luca) #12685
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
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
b266ae4
#cpp chat variable
lukka f75d9a2
Adapt to lmTool API
benmcmorran 5a46e60
Fix lint errors
benmcmorran ed21456
Address PR comments
benmcmorran e469744
drop undefined return type, and apply suggested cancellation logic,
lukka 7105e65
- register #cpp only upon expFeatures enabled.
lukka 7c3ff32
add a when: clause and report a error log entry on failures
lukka 80b9013
lint
lukka 6afe49a
fix the settings.json lint to use the standard one
lukka f9be661
more linting
lukka 94449b2
Merge branch 'main' into dev/lukka/cppcontext
Colengms File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| /* -------------------------------------------------------------------------------------------- | ||
| * Copyright (c) Microsoft Corporation. All Rights Reserved. | ||
| * See 'LICENSE' in the project root for license information. | ||
| * ------------------------------------------------------------------------------------------ */ | ||
| 'use strict'; | ||
|
|
||
| import * as vscode from 'vscode'; | ||
| import { localize } from 'vscode-nls'; | ||
| import * as util from '../common'; | ||
| import * as logger from '../logger'; | ||
| import * as telemetry from '../telemetry'; | ||
| import { ChatContextResult } from './client'; | ||
| import { getClients } from './extension'; | ||
|
|
||
| const knownValues: { [Property in keyof ChatContextResult]?: { [id: string]: string } } = { | ||
| language: { | ||
| 'c': 'C', | ||
| 'cpp': 'C++', | ||
| 'cuda-cpp': 'CUDA C++' | ||
| }, | ||
| compiler: { | ||
| 'msvc': 'MSVC', | ||
| 'clang': 'Clang', | ||
| 'gcc': 'GCC' | ||
| }, | ||
| standardVersion: { | ||
| '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", | ||
| 'c23': "C23" | ||
| }, | ||
| targetPlatform: { | ||
| 'windows': 'Windows', | ||
| 'Linux': 'Linux', | ||
| 'macos': 'macOS' | ||
| } | ||
| }; | ||
|
|
||
| class StringLanguageModelToolResult implements vscode.LanguageModelToolResult { | ||
| public constructor(public readonly value: string) { } | ||
| public toString(): string { return this.value; } | ||
| } | ||
|
|
||
| export class CppConfigurationLanguageModelTool implements vscode.LanguageModelTool { | ||
| public async invoke(_parameters: any, token: vscode.CancellationToken): Promise<vscode.LanguageModelToolResult> { | ||
| return new StringLanguageModelToolResult(await this.getContext(token)); | ||
| } | ||
|
|
||
| private async getContext(token: vscode.CancellationToken): Promise<string> { | ||
| try { | ||
| const currentDoc = vscode.window.activeTextEditor?.document; | ||
| if (!currentDoc || (!util.isCpp(currentDoc) && !util.isHeaderFile(currentDoc.uri))) { | ||
| return 'The active document is not a C, C++, or CUDA file.'; | ||
| } | ||
|
|
||
| const chatContext: ChatContextResult | undefined = await (getClients()?.ActiveClient?.getChatContext(token) ?? undefined); | ||
| if (!chatContext) { | ||
| return 'No configuration information is available for the active document.'; | ||
| } | ||
|
|
||
| telemetry.logLanguageModelToolEvent( | ||
| 'cpp', | ||
| { | ||
| "language": chatContext.language, | ||
| "compiler": chatContext.compiler, | ||
| "standardVersion": chatContext.standardVersion, | ||
| "targetPlatform": chatContext.targetPlatform, | ||
| "targetArchitecture": chatContext.targetArchitecture | ||
| }); | ||
|
|
||
| for (const key in knownValues) { | ||
| const knownKey = key as keyof ChatContextResult; | ||
| if (knownValues[knownKey] && chatContext[knownKey]) { | ||
| chatContext[knownKey] = knownValues[knownKey][chatContext[knownKey]] || chatContext[knownKey]; | ||
| } | ||
| } | ||
|
|
||
| return `The user is working on a ${chatContext.language} project. The project uses language version ${chatContext.standardVersion}, compiles using the ${chatContext.compiler} compiler, targets the ${chatContext.targetPlatform} platform, and targets the ${chatContext.targetArchitecture} architecture.`; | ||
| } | ||
| catch { | ||
| await this.reportError(); | ||
| return ""; | ||
| } | ||
| } | ||
|
|
||
| private async reportError(): Promise<void> { | ||
| try { | ||
| logger.getOutputChannelLogger().appendLine(localize("copilot.cppcontext.error", "Error while retrieving the #cpp context.")); | ||
| } | ||
| catch { | ||
| // Intentionally swallow any exception. | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.