mirror of
https://github.com/Iheuzio/gpt-contextfiles.git
synced 2025-07-18 14:00:48 +00:00
Merge pull request #2 from Iheuzio/fix/format-queries
fix(queries): Fixes the queries formatting
This commit is contained in:
commit
43e3b9781e
130
extension.js
130
extension.js
@ -133,71 +133,87 @@ const refreshFilesCommand = vscode.commands.registerCommand('extension.refreshFi
|
|||||||
|
|
||||||
// Helper function to generate the HTML content for the webview panel
|
// Helper function to generate the HTML content for the webview panel
|
||||||
function getWebviewContent(fileContents, question) {
|
function getWebviewContent(fileContents, question) {
|
||||||
const fileList = selectedFiles
|
const fileList = selectedFiles
|
||||||
.map(
|
.map(
|
||||||
file =>
|
file =>
|
||||||
`<div><input type="checkbox" ${
|
`<div><input type="checkbox" ${
|
||||||
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('');
|
||||||
|
|
||||||
return `
|
const formattedContents = selectedFiles
|
||||||
<html>
|
.map(file => {
|
||||||
<body>
|
const document = vscode.workspace.textDocuments.find(doc => doc.uri.fsPath === file.uri.fsPath);
|
||||||
<h1>GPT Context</h1>
|
if (document) {
|
||||||
<form id="questionForm">
|
const lines = document.getText().split('\n');
|
||||||
<label for="question">Enter your question:</label>
|
const formattedLines = lines.map(line => `\t${line}`).join('\n');
|
||||||
<input type="text" id="question" name="question" required>
|
return `${file.uri.fsPath}:\n\`\`\`\n${formattedLines}\n\`\`\``;
|
||||||
<button type="submit">Submit</button>
|
}
|
||||||
<button type="button" onclick="clearSelectedFiles()">Clear</button>
|
return '';
|
||||||
<button type="button" onclick="refreshSelectedFiles()">Refresh</button>
|
})
|
||||||
</form>
|
.join('\n\n');
|
||||||
${
|
|
||||||
fileContents ? `<div><pre>${fileContents}</pre></div>` : ''
|
|
||||||
}
|
|
||||||
<div>
|
|
||||||
<h2>Selected Files:</h2>
|
|
||||||
${fileList}
|
|
||||||
</div>
|
|
||||||
<div><pre>${question ? question : ''}</pre></div>
|
|
||||||
<script>
|
|
||||||
const vscode = acquireVsCodeApi();
|
|
||||||
|
|
||||||
function toggleFileSelection(uri) {
|
return `
|
||||||
vscode.postMessage({
|
<html>
|
||||||
command: 'toggleFileSelection',
|
<body>
|
||||||
uri: uri
|
<h1>GPT Context</h1>
|
||||||
});
|
<form id="questionForm">
|
||||||
|
<div>
|
||||||
|
<label for="question">Enter your question:</label>
|
||||||
|
<input type="text" id="question" name="question" required>
|
||||||
|
<button type="submit">Submit</button>
|
||||||
|
<button type="button" onclick="clearSelectedFiles()">Clear</button>
|
||||||
|
<button type="button" onclick="refreshSelectedFiles()">Refresh</button>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<div><pre>${question ? question : ''}</pre></div>
|
||||||
|
${
|
||||||
|
fileContents ? `<div><pre>${formattedContents}</pre></div>` : ''
|
||||||
}
|
}
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<h2>Selected Files:</h2>
|
||||||
|
${fileList}
|
||||||
|
</div>
|
||||||
|
<script>
|
||||||
|
const vscode = acquireVsCodeApi();
|
||||||
|
|
||||||
function clearSelectedFiles() {
|
function toggleFileSelection(uri) {
|
||||||
vscode.postMessage({
|
vscode.postMessage({
|
||||||
command: 'clearSelectedFiles'
|
command: 'toggleFileSelection',
|
||||||
});
|
uri: uri
|
||||||
}
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function refreshSelectedFiles() {
|
function clearSelectedFiles() {
|
||||||
vscode.postMessage({
|
vscode.postMessage({
|
||||||
command: 'refreshFiles'
|
command: 'clearSelectedFiles'
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const form = document.getElementById('questionForm');
|
function refreshSelectedFiles() {
|
||||||
form.addEventListener('submit', event => {
|
vscode.postMessage({
|
||||||
event.preventDefault();
|
command: 'refreshFiles'
|
||||||
const question = document.getElementById('question').value;
|
});
|
||||||
vscode.postMessage({
|
}
|
||||||
command: 'submitQuestion',
|
|
||||||
text: question
|
const form = document.getElementById('questionForm');
|
||||||
});
|
form.addEventListener('submit', event => {
|
||||||
});
|
event.preventDefault();
|
||||||
</script>
|
const question = document.getElementById('question').value;
|
||||||
</body>
|
vscode.postMessage({
|
||||||
</html>
|
command: 'submitQuestion',
|
||||||
`;
|
text: question
|
||||||
|
});
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Activates the extension
|
// Activates the extension
|
||||||
function activate(context) {
|
function activate(context) {
|
||||||
// Register the file data provider
|
// Register the file data provider
|
||||||
|
Loading…
Reference in New Issue
Block a user