Compare commits

...
Author SHA1 Message Date
Colen Garoutte-Carson 1668eea80a Temporarily work around build break 2024-10-18 18:27:26 -07:00
2 changed files with 85 additions and 94 deletions
+4 -5
View File
@@ -27,7 +27,6 @@ import { registerRelatedFilesProvider } from './copilotProviders';
import { CppBuildTaskProvider } from './cppBuildTaskProvider';
import { getCustomConfigProviders } from './customProviders';
import { getLanguageConfig } from './languageConfig';
import { CppConfigurationLanguageModelTool } from './lmTool';
import { PersistentState } from './persistentState';
import { NodeType, TreeNode } from './referencesModel';
import { CppSettings } from './settings';
@@ -252,10 +251,10 @@ export async function activate(): Promise<void> {
activeDocument = activeEditor.document;
}
if (util.extensionContext && new CppSettings().experimentalFeatures) {
const tool = vscode.lm.registerTool('cpptools-lmtool-configuration', new CppConfigurationLanguageModelTool());
disposables.push(tool);
}
// if (util.extensionContext && new CppSettings().experimentalFeatures) {
// const tool = vscode.lm.registerTool('cpptools-lmtool-configuration', new CppConfigurationLanguageModelTool());
// disposables.push(tool);
// }
await registerRelatedFilesProvider();
}
+81 -89
View File
@@ -4,100 +4,92 @@
* ------------------------------------------------------------------------------------------ */
'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'
// // }
// // };
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'
}
};
// // const plainTextContentType = 'text/plain';
const plainTextContentType = 'text/plain';
// export class CppConfigurationLanguageModelTool implements vscode.LanguageModelTool<void> {
// public async invoke(options: vscode.LanguageModelToolInvocationOptions<void>, token: vscode.CancellationToken): Promise<vscode.LanguageModelToolResult> {
// const result: vscode.LanguageModelToolResult = new vscode.LanguageModelToolResult([]);
// // if (options.requestedContentTypes.includes(plainTextContentType)) {
// // result[plainTextContentType] = await this.getContext(token);
// // }
// return result;
// }
export class CppConfigurationLanguageModelTool implements vscode.LanguageModelTool<void> {
public async invoke(options: vscode.LanguageModelToolInvocationOptions<void>, token: vscode.CancellationToken): Promise<vscode.LanguageModelToolResult> {
const result: vscode.LanguageModelToolResult = {};
if (options.requestedContentTypes.includes(plainTextContentType)) {
result[plainTextContentType] = await this.getContext(token);
}
return result;
}
// // 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.';
// // }
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.';
// // }
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
// // });
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];
// // }
// // }
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 "";
// // }
// // }
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.
}
}
}
// // private async reportError(): Promise<void> {
// // try {
// // logger.getOutputChannelLogger().appendLine(localize("copilot.cppcontext.error", "Error while retrieving the #cpp context."));
// // }
// // catch {
// // // Intentionally swallow any exception.
// // }
// // }
// }