extension.ts 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import * as vscode from 'vscode';
  2. import {
  3. copySelection,
  4. copyActiveFile,
  5. copySingleItem,
  6. copySelectedFiles,
  7. copyMultiFiles,
  8. } from './copyContext';
  9. import { CopyAiCodeActionProvider } from './codeActionProvider';
  10. export function activate(context: vscode.ExtensionContext) {
  11. console.log('[copy-ai-ctx] activating...');
  12. context.subscriptions.push(
  13. vscode.commands.registerCommand('copy-ai-ctx.copySelection', () => {
  14. copySelection();
  15. }),
  16. );
  17. context.subscriptions.push(
  18. vscode.commands.registerCommand('copy-ai-ctx.copyFile', () => {
  19. copyActiveFile();
  20. }),
  21. );
  22. context.subscriptions.push(
  23. vscode.commands.registerCommand('copy-ai-ctx.copySelectedFiles', (args) => {
  24. if (!args) {
  25. // keyboard shortcut invocation: fallback to active editor file
  26. const editor = vscode.window.activeTextEditor;
  27. if (!editor) return;
  28. copySingleItem(editor.document.uri);
  29. return;
  30. }
  31. copySingleItem(args as vscode.Uri);
  32. }),
  33. );
  34. context.subscriptions.push(
  35. vscode.commands.registerCommand('copy-ai-ctx.copyMultiFiles', (...args) => {
  36. if (args.length < 2) {
  37. // keyboard shortcut invocation: fallback to active editor file
  38. const editor = vscode.window.activeTextEditor;
  39. if (!editor) return;
  40. copyMultiFiles([editor.document.uri]);
  41. return;
  42. }
  43. // args[0] = clicked resource URI
  44. // args[1] might be array (standard) or individual URI (variadic)
  45. const resources = Array.isArray(args[1]) ? args[1] : args.slice(1);
  46. if (resources.length === 0) return;
  47. copyMultiFiles(resources);
  48. }),
  49. );
  50. console.log('[copy-ai-ctx] activated');
  51. // Register CodeAction provider (lightbulb on selection)
  52. context.subscriptions.push(
  53. vscode.languages.registerCodeActionsProvider(
  54. { pattern: '**' },
  55. new CopyAiCodeActionProvider(),
  56. {
  57. providedCodeActionKinds:
  58. CopyAiCodeActionProvider.providedCodeActionKinds,
  59. },
  60. ),
  61. );
  62. }
  63. export function deactivate() {
  64. // cleanup if needed
  65. }