-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Expand file tree
/
Copy pathinstructionsProvider.ts
More file actions
51 lines (38 loc) · 1.58 KB
/
instructionsProvider.ts
File metadata and controls
51 lines (38 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import * as vscode from 'vscode';
import { getChatResourceFileSystem } from './chatResourceFileSystem';
const INSTRUCTIONS_PATH = 'instructions/workspace-context.instructions.md';
export function createInstructionsProvider(context: vscode.ExtensionContext): vscode.ChatInstructionsProvider {
const fs = getChatResourceFileSystem(context);
const instructionsUri = fs.registerResource(INSTRUCTIONS_PATH, generateDynamicInstructions);
return {
async provideInstructions(_context, _token): Promise<vscode.ChatResource[]> {
return [{ uri: instructionsUri }];
}
};
}
function generateDynamicInstructions(): string {
const workspaceFolders = vscode.workspace.workspaceFolders;
const activeEditor = vscode.window.activeTextEditor;
const currentFile = activeEditor?.document.fileName || 'none';
const languageId = activeEditor?.document.languageId || 'none';
return `# Workspace Context Instructions
These instructions are dynamically generated based on your current workspace state.
## Current Context
- **Active File**: ${currentFile}
- **Language**: ${languageId}
- **Workspace Folders**: ${workspaceFolders?.length || 0}
- **Timestamp**: ${new Date().toLocaleString()}
## Guidelines
When working with this workspace:
1. Consider the current file context when providing suggestions
2. Use language-specific best practices for ${languageId}
3. Reference workspace structure when relevant
4. Keep code examples consistent with the project style
## Dynamic Behavior
These instructions update based on:
- Current active file
- Workspace configuration
- Time of day
- Available workspace folders
`;
}