Copilot Chat Extension Model
Key Points
- Copilot extensions add custom commands / context to GitHub Copilot Chat in VS, VS Code, JetBrains.
- Two extension types: chat participants (
@myparticipant) and slash commands (/mycommand). - Build for IDE-specific or cross-IDE.
- Use cases: project-specific assistance, internal docs lookup, custom code generation.
Concept
User: @myproject /createcontroller User
Copilot Chat → @myproject extension → produces code → user accepts.
Extensions register with the IDE; user invokes via @ or /.
VS Code Copilot extension
// package.json
{
"name": "myproject-copilot",
"main": "./extension.js",
"contributes": {
"chatParticipants": [{
"id": "myproject",
"name": "myproject",
"fullName": "MyProject Assistant",
"description": "Helps with MyProject conventions",
"commands": [
{ "name": "createcontroller", "description": "Generate a controller" }
]
}]
}
}
// extension.js
const vscode = require('vscode');
function activate(ctx) {
const handler = async (request, context, stream, token) => {
if (request.command === 'createcontroller') {
stream.markdown('Generating controller for: ' + request.prompt);
// call Copilot API or your own
}
};
const participant = vscode.chat.createChatParticipant('myproject', handler);
participant.iconPath = vscode.Uri.joinPath(ctx.extensionUri, 'icon.png');
}
module.exports = { activate };
Visual Studio Copilot extension
For Visual Studio (full IDE): use Visual Studio extension SDK + Copilot APIs (preview/GA varies).
C# / VSIX based.
JetBrains Copilot
JetBrains has its own AI / Copilot. Extension model differs.
What can extensions do
- Read open files / selection.
- Stream Markdown / code to chat.
- Reference files via
references. - Call external APIs (your backend).
- Use Copilot's LLM (passes through).
Example: project conventions
const handler = async (request, context, stream) => {
if (request.command === 'review') {
const editor = vscode.window.activeTextEditor;
const code = editor?.document.getText() ?? '';
// Send to your backend with project context
const response = await fetch('https://my-backend/review', {
method: 'POST',
body: JSON.stringify({ code, conventions: ourConventions })
});
stream.markdown(await response.text());
}
};
Use cases
- Internal SDK docs: query company knowledge base.
- Project-specific generators: generate code matching your conventions.
- Architectural review: against ADRs, design rules.
- PR templates: generate description.
Distribution
- Marketplace: VS Code marketplace, JetBrains marketplace.
- Internal: company VSIX feed; private extensions.
.NET-specific examples
- Aspire scaffolder: generate AppHost integrations.
- Entity generator: from DB schema.
- Test scaffolder: from Razor views.
Senior considerations
- Privacy: extension can access source code; handle sensitive data carefully.
- Auth: tokens for backend calls.
- Testing: hard; mock chat API.
- Versioning: extensions break with IDE updates.