mirror of
https://github.com/Iheuzio/gpt-contextfiles.git
synced 2025-07-18 14:00:48 +00:00
Merge pull request #3 from Iheuzio/fix/store-variables
fix(selected-files): User can now select individual files to pass into the context using the checkboxes
This commit is contained in:
commit
24e1208329
43
extension.js
43
extension.js
@ -80,7 +80,17 @@ const openGPTContextPanelCommand = vscode.commands.registerCommand('extension.op
|
|||||||
panel.webview.onDidReceiveMessage(message => {
|
panel.webview.onDidReceiveMessage(message => {
|
||||||
if (message.command === 'submitQuestion') {
|
if (message.command === 'submitQuestion') {
|
||||||
const question = message.text;
|
const question = message.text;
|
||||||
|
const selectedUris = message.selectedUris;
|
||||||
|
|
||||||
|
// Update the selectedFiles array based on the selectedUris
|
||||||
|
selectedFiles.forEach(file => {
|
||||||
|
file.selected = selectedUris.includes(file.uri.fsPath);
|
||||||
|
});
|
||||||
|
|
||||||
|
fileDataProvider.refresh();
|
||||||
|
|
||||||
const fileContents = selectedFiles
|
const fileContents = selectedFiles
|
||||||
|
.filter(file => file.selected)
|
||||||
.map(file => {
|
.map(file => {
|
||||||
const document = vscode.workspace.textDocuments.find(doc => doc.uri.fsPath === file.uri.fsPath);
|
const document = vscode.workspace.textDocuments.find(doc => doc.uri.fsPath === file.uri.fsPath);
|
||||||
if (document) {
|
if (document) {
|
||||||
@ -136,13 +146,14 @@ function getWebviewContent(fileContents, question) {
|
|||||||
const fileList = selectedFiles
|
const fileList = selectedFiles
|
||||||
.map(
|
.map(
|
||||||
file =>
|
file =>
|
||||||
`<div><input type="checkbox" ${
|
`<div><input type="checkbox" data-uri="${file.uri.fsPath}" ${
|
||||||
file.selected ? 'checked' : ''
|
file.selected ? 'checked' : ''
|
||||||
} onchange="toggleFileSelection('${file.uri.fsPath}')" /> ${file.uri.fsPath}</div>`
|
} onchange="toggleFileSelection('${file.uri.fsPath}')" /> ${file.uri.fsPath}</div>`
|
||||||
)
|
)
|
||||||
.join('');
|
.join('');
|
||||||
|
|
||||||
const formattedContents = selectedFiles
|
const formattedContents = selectedFiles
|
||||||
|
.filter(file => file.selected)
|
||||||
.map(file => {
|
.map(file => {
|
||||||
const document = vscode.workspace.textDocuments.find(doc => doc.uri.fsPath === file.uri.fsPath);
|
const document = vscode.workspace.textDocuments.find(doc => doc.uri.fsPath === file.uri.fsPath);
|
||||||
if (document) {
|
if (document) {
|
||||||
@ -202,9 +213,18 @@ function getWebviewContent(fileContents, question) {
|
|||||||
form.addEventListener('submit', event => {
|
form.addEventListener('submit', event => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
const question = document.getElementById('question').value;
|
const question = document.getElementById('question').value;
|
||||||
|
const checkboxes = document.querySelectorAll('input[type="checkbox"]');
|
||||||
|
const selectedUris = [];
|
||||||
|
checkboxes.forEach(checkbox => {
|
||||||
|
if (checkbox.checked) {
|
||||||
|
const uri = checkbox.getAttribute('data-uri');
|
||||||
|
selectedUris.push(uri);
|
||||||
|
}
|
||||||
|
});
|
||||||
vscode.postMessage({
|
vscode.postMessage({
|
||||||
command: 'submitQuestion',
|
command: 'submitQuestion',
|
||||||
text: question
|
text: question,
|
||||||
|
selectedUris: selectedUris
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
@ -216,27 +236,12 @@ function getWebviewContent(fileContents, question) {
|
|||||||
|
|
||||||
// Activates the extension
|
// Activates the extension
|
||||||
function activate(context) {
|
function activate(context) {
|
||||||
// Register the file data provider
|
|
||||||
vscode.window.registerTreeDataProvider('gpt-contextfiles', fileDataProvider);
|
|
||||||
|
|
||||||
// Register the commands
|
|
||||||
context.subscriptions.push(addFilesCommand);
|
context.subscriptions.push(addFilesCommand);
|
||||||
context.subscriptions.push(openGPTContextPanelCommand);
|
context.subscriptions.push(openGPTContextPanelCommand);
|
||||||
context.subscriptions.push(refreshSelectedFilesCommand);
|
context.subscriptions.push(refreshSelectedFilesCommand);
|
||||||
context.subscriptions.push(clearSelectedFilesCommand);
|
context.subscriptions.push(clearSelectedFilesCommand);
|
||||||
context.subscriptions.push(refreshFilesCommand);
|
context.subscriptions.push(refreshFilesCommand);
|
||||||
|
vscode.window.registerTreeDataProvider('selectedFiles', fileDataProvider);
|
||||||
// Refresh the file data provider when a file is added or removed from the workspace
|
|
||||||
vscode.workspace.onDidChangeWorkspaceFolders(() => {
|
|
||||||
fileDataProvider.refresh();
|
|
||||||
});
|
|
||||||
|
|
||||||
// Refresh the file data provider when a file is created, deleted, or renamed within the workspace
|
|
||||||
vscode.workspace.onDidChangeTextDocument(() => {
|
|
||||||
fileDataProvider.refresh();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
exports.activate = activate;
|
||||||
activate
|
|
||||||
};
|
|
||||||
|
Loading…
Reference in New Issue
Block a user