-
Notifications
You must be signed in to change notification settings - Fork 732
Expand file tree
/
Copy pathissueFeatureRegistrar.ts
More file actions
1704 lines (1609 loc) · 61 KB
/
issueFeatureRegistrar.ts
File metadata and controls
1704 lines (1609 loc) · 61 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { basename } from 'path';
import * as yaml from 'js-yaml';
import * as vscode from 'vscode';
import { CurrentIssue } from './currentIssue';
import { IssueCompletionProvider } from './issueCompletionProvider';
import { Remote } from '../api/api';
import { GitApiImpl } from '../api/api1';
import { COPILOT_ACCOUNTS } from '../common/comment';
import { commands } from '../common/executeCommands';
import { Disposable } from '../common/lifecycle';
import Logger from '../common/logger';
import {
ALWAYS_PROMPT_FOR_NEW_ISSUE_REPO,
CREATE_INSERT_FORMAT,
ENABLED,
ISSUE_COMPLETIONS,
ISSUES_SETTINGS_NAMESPACE,
USER_COMPLETIONS,
WORKING_BASE_BRANCH,
} from '../common/settingKeys';
import { editQuery } from '../common/settingsUtils';
import { ITelemetry } from '../common/telemetry';
import { fromRepoUri, RepoUriParams, Schemes, toNewIssueUri } from '../common/uri';
import { EXTENSION_ID } from '../constants';
import {
ASSIGNEES,
extractMetadataFromFile,
IssueFileSystemProvider,
LABELS,
MILESTONE,
NewIssueCache,
NewIssueFileCompletionProvider,
NewIssueFileOptions,
PROJECTS,
} from './issueFile';
import { IssueHoverProvider } from './issueHoverProvider';
import { openCodeLink } from './issueLinkLookup';
import { IssuesTreeData, QueryNode, updateExpandedQueries } from './issuesView';
import { IssueTodoProvider } from './issueTodoProvider';
import { ShareProviderManager } from './shareProviders';
import { StateManager } from './stateManager';
import { UserCompletionProvider } from './userCompletionProvider';
import { UserHoverProvider } from './userHoverProvider';
import {
createGitHubLink,
createGithubPermalink,
createSinglePermalink,
getIssue,
IssueTemplate,
LinkContext,
NewIssue,
PERMALINK_COMPONENT,
PermalinkInfo,
pushAndCreatePR,
USER_EXPRESSION,
YamlIssueTemplate,
} from './util';
import { OctokitCommon } from '../github/common';
import { CopilotRemoteAgentManager } from '../github/copilotRemoteAgent';
import { FolderRepositoryManager, PullRequestDefaults } from '../github/folderRepositoryManager';
import { IProject } from '../github/interface';
import { IssueModel } from '../github/issueModel';
import { IssueOverviewPanel } from '../github/issueOverview';
import { RepositoriesManager } from '../github/repositoriesManager';
import { ISSUE_OR_URL_EXPRESSION, parseIssueExpressionOutput } from '../github/utils';
import { ReviewManager } from '../view/reviewManager';
import { ReviewsManager } from '../view/reviewsManager';
import { PRNode } from '../view/treeNodes/pullRequestNode';
const CREATING_ISSUE_FROM_FILE_CONTEXT = 'issues.creatingFromFile';
export class IssueFeatureRegistrar extends Disposable {
private static readonly ID = 'IssueFeatureRegistrar';
private _newIssueCache: NewIssueCache;
private createIssueInfo:
| {
document: vscode.TextDocument;
newIssue: NewIssue | undefined;
lineNumber: number | undefined;
insertIndex: number | undefined;
}
| undefined;
constructor(
private gitAPI: GitApiImpl,
private manager: RepositoriesManager,
private reviewsManager: ReviewsManager,
private context: vscode.ExtensionContext,
private telemetry: ITelemetry,
private readonly _stateManager: StateManager,
private copilotRemoteAgentManager: CopilotRemoteAgentManager,
) {
super();
this._newIssueCache = new NewIssueCache(context);
}
async initialize() {
this._register(vscode.workspace.registerFileSystemProvider(Schemes.NewIssue, new IssueFileSystemProvider(this._newIssueCache)));
this._register(
vscode.languages.registerCompletionItemProvider(
{ scheme: Schemes.NewIssue },
new NewIssueFileCompletionProvider(this.manager),
' ',
',',
),
);
const view = vscode.window.createTreeView('issues:github', {
showCollapseAll: true,
treeDataProvider: new IssuesTreeData(this._stateManager, this.manager, this.context),
});
this._register(view);
this._register(view.onDidCollapseElement(e => updateExpandedQueries(this.context, e.element, false)));
this._register(view.onDidExpandElement(e => updateExpandedQueries(this.context, e.element, true)));
this._register(
vscode.commands.registerCommand(
'issue.createIssueFromSelection',
(newIssue?: NewIssue, issueBody?: string) => {
/* __GDPR__
"issue.createIssueFromSelection" : {}
*/
this.telemetry.sendTelemetryEvent('issue.createIssueFromSelection');
return this.createTodoIssue(newIssue, issueBody);
},
this,
),
);
this._register(
vscode.commands.registerCommand(
'issue.createIssueFromClipboard',
() => {
/* __GDPR__
"issue.createIssueFromClipboard" : {}
*/
this.telemetry.sendTelemetryEvent('issue.createIssueFromClipboard');
return this.createTodoIssueClipboard();
},
this,
),
);
this._register(
vscode.commands.registerCommand(
'issue.assignToCodingAgent',
(issueModel: any) => {
/* __GDPR__
"issue.assignToCodingAgent" : {}
*/
this.telemetry.sendTelemetryEvent('issue.assignToCodingAgent');
return this.assignToCodingAgent(issueModel);
},
this,
),
);
this._register(
vscode.commands.registerCommand(
'issue.copyGithubPermalink',
(context: LinkContext, additional: LinkContext[] | undefined) => {
/* __GDPR__
"issue.copyGithubPermalink" : {}
*/
this.telemetry.sendTelemetryEvent('issue.copyGithubPermalink');
return this.copyPermalink(this.manager, additional && additional.length > 0 ? additional : [context]);
},
this,
),
);
this._register(
vscode.commands.registerCommand(
'issue.copyGithubHeadLink',
(fileUri: vscode.Uri, additional: vscode.Uri[] | undefined) => {
/* __GDPR__
"issue.copyGithubHeadLink" : {}
*/
this.telemetry.sendTelemetryEvent('issue.copyGithubHeadLink');
return this.copyHeadLink(additional && additional.length > 0 ? additional : [fileUri]);
},
this,
),
);
this._register(
vscode.commands.registerCommand(
'issue.copyGithubPermalinkWithoutRange',
(context: LinkContext, additional: LinkContext[] | undefined) => {
/* __GDPR__
"issue.copyGithubPermalinkWithoutRange" : {}
*/
this.telemetry.sendTelemetryEvent('issue.copyGithubPermalinkWithoutRange');
return this.copyPermalink(this.manager, additional && additional.length > 0 ? additional : [context], false);
},
this,
),
);
this._register(
vscode.commands.registerCommand(
'issue.copyGithubHeadLinkWithoutRange',
(fileUri: vscode.Uri, additional: vscode.Uri[] | undefined) => {
/* __GDPR__
"issue.copyGithubHeadLinkWithoutRange" : {}
*/
this.telemetry.sendTelemetryEvent('issue.copyGithubHeadLinkWithoutRange');
return this.copyHeadLink(additional && additional.length > 0 ? additional : [fileUri], false);
},
this,
),
);
this._register(
vscode.commands.registerCommand(
'issue.copyGithubDevLinkWithoutRange',
(context: LinkContext, additional: LinkContext[] | undefined) => {
/* __GDPR__
"issue.copyGithubDevLinkWithoutRange" : {}
*/
this.telemetry.sendTelemetryEvent('issue.copyGithubDevLinkWithoutRange');
return this.copyPermalink(this.manager, additional && additional.length > 0 ? additional : [context], false, true, true);
},
this,
),
);
this._register(
vscode.commands.registerCommand(
'issue.copyGithubDevLink',
(context: LinkContext, additional: LinkContext[] | undefined) => {
/* __GDPR__
"issue.copyGithubDevLink" : {}
*/
this.telemetry.sendTelemetryEvent('issue.copyGithubDevLink');
return this.copyPermalink(this.manager, additional && additional.length > 0 ? additional : [context], true, true, true);
},
this,
),
);
this._register(
vscode.commands.registerCommand(
'issue.copyGithubDevLinkFile',
(context: LinkContext, additional: LinkContext[] | undefined) => {
/* __GDPR__
"issue.copyGithubDevLinkFile" : {}
*/
this.telemetry.sendTelemetryEvent('issue.copyGithubDevLinkFile');
return this.copyPermalink(this.manager, additional && additional.length > 0 ? additional : [context], false, true, true);
},
this,
),
);
this._register(
vscode.commands.registerCommand(
'issue.copyMarkdownGithubPermalink',
(context: LinkContext, additional: LinkContext[] | undefined) => {
/* __GDPR__
"issue.copyMarkdownGithubPermalink" : {}
*/
this.telemetry.sendTelemetryEvent('issue.copyMarkdownGithubPermalink');
return this.copyMarkdownPermalink(this.manager, additional && additional.length > 0 ? additional : [context]);
},
this,
),
);
this._register(
vscode.commands.registerCommand(
'issue.copyMarkdownGithubPermalinkWithoutRange',
(context: LinkContext, additional: LinkContext[] | undefined) => {
/* __GDPR__
"issue.copyMarkdownGithubPermalinkWithoutRange" : {}
*/
this.telemetry.sendTelemetryEvent('issue.copyMarkdownGithubPermalinkWithoutRange');
return this.copyMarkdownPermalink(this.manager, additional && additional.length > 0 ? additional : [context], false);
},
this,
),
);
this._register(
vscode.commands.registerCommand(
'issue.openGithubPermalink',
() => {
/* __GDPR__
"issue.openGithubPermalink" : {}
*/
this.telemetry.sendTelemetryEvent('issue.openGithubPermalink');
return this.openPermalink(this.manager);
},
this,
),
);
this._register(new ShareProviderManager(this.manager, this.gitAPI));
this._register(
vscode.commands.registerCommand('issue.openIssue', (issueModel: any) => {
/* __GDPR__
"issue.openIssue" : {}
*/
this.telemetry.sendTelemetryEvent('issue.openIssue');
return this.openIssue(issueModel);
}),
);
this._register(
vscode.commands.registerCommand('issue.openIssueOnGitHub', async () => {
const editor = vscode.window.activeTextEditor;
if (!editor) {
vscode.window.showWarningMessage(vscode.l10n.t('No active editor. Open a file and place the cursor on an issue reference.'));
return;
}
const document = editor.document;
const position = editor.selection.active;
const wordRange = document.getWordRangeAtPosition(position, ISSUE_OR_URL_EXPRESSION);
if (!wordRange) {
vscode.window.showWarningMessage(vscode.l10n.t('No issue reference found at cursor position.'));
return;
}
const word = document.getText(wordRange);
const match = word.match(ISSUE_OR_URL_EXPRESSION);
const parsed = parseIssueExpressionOutput(match);
if (!parsed) {
vscode.window.showWarningMessage(vscode.l10n.t('Invalid issue reference.'));
return;
}
const folderManager = this.manager.getManagerForFile(document.uri) ?? this.manager.folderManagers[0];
if (!folderManager) {
vscode.window.showWarningMessage(vscode.l10n.t('No repository found for current file.'));
return;
}
const issue = await getIssue(this._stateManager, folderManager, word, parsed);
if (!issue) {
vscode.window.showWarningMessage(vscode.l10n.t('Unable to resolve issue.'));
return;
}
vscode.commands.executeCommand('vscode.open', vscode.Uri.parse(issue.html_url));
/* __GDPR__
"issue.openOnGitHub" : {}
*/
this.telemetry.sendTelemetryEvent('issue.openOnGitHub');
}),
);
this._register(
vscode.commands.registerCommand(
'issue.startWorking',
(issue: any) => {
/* __GDPR__
"issue.startWorking" : {}
*/
this.telemetry.sendTelemetryEvent('issue.startWorking');
return this.startWorking(issue);
},
this,
),
);
this._register(
vscode.commands.registerCommand(
'issue.startWorkingBranchDescriptiveTitle',
(issue: any) => {
/* __GDPR__
"issue.startWorking" : {}
*/
this.telemetry.sendTelemetryEvent('issue.startWorking');
return this.startWorking(issue);
},
this,
),
);
this._register(
vscode.commands.registerCommand(
'issue.continueWorking',
(issue: any) => {
/* __GDPR__
"issue.continueWorking" : {}
*/
this.telemetry.sendTelemetryEvent('issue.continueWorking');
return this.startWorking(issue);
},
this,
),
);
this._register(
vscode.commands.registerCommand(
'issue.startWorkingBranchPrompt',
(issueModel: any) => {
/* __GDPR__
"issue.startWorkingBranchPrompt" : {}
*/
this.telemetry.sendTelemetryEvent('issue.startWorkingBranchPrompt');
return this.startWorkingBranchPrompt(issueModel);
},
this,
),
);
this._register(
vscode.commands.registerCommand(
'issue.stopWorking',
(issueModel: any) => {
/* __GDPR__
"issue.stopWorking" : {}
*/
this.telemetry.sendTelemetryEvent('issue.stopWorking');
return this.stopWorking(issueModel);
},
this,
),
);
this._register(
vscode.commands.registerCommand(
'issue.stopWorkingBranchDescriptiveTitle',
(issueModel: any) => {
/* __GDPR__
"issue.stopWorking" : {}
*/
this.telemetry.sendTelemetryEvent('issue.stopWorking');
return this.stopWorking(issueModel);
},
this,
),
);
this._register(
vscode.commands.registerCommand(
'issue.statusBar',
() => {
/* __GDPR__
"issue.statusBar" : {}
*/
this.telemetry.sendTelemetryEvent('issue.statusBar');
return this.statusBar();
},
this,
),
);
this._register(
vscode.commands.registerCommand('issue.copyIssueNumber', (issueModel: any) => {
/* __GDPR__
"issue.copyIssueNumber" : {}
*/
this.telemetry.sendTelemetryEvent('issue.copyIssueNumber');
return this.copyIssueNumber(issueModel);
}),
);
this._register(
vscode.commands.registerCommand('issue.copyIssueUrl', (issueModel: any) => {
/* __GDPR__
"issue.copyIssueUrl" : {}
*/
this.telemetry.sendTelemetryEvent('issue.copyIssueUrl');
return this.copyIssueUrl(issueModel);
}),
);
this._register(
vscode.commands.registerCommand(
'issue.refresh',
() => {
/* __GDPR__
"issue.refresh" : {}
*/
this.telemetry.sendTelemetryEvent('issue.refresh');
return this.refreshView();
},
this,
),
);
this._register(
vscode.commands.registerCommand(
'issue.suggestRefresh',
() => {
/* __GDPR__
"issue.suggestRefresh" : {}
*/
this.telemetry.sendTelemetryEvent('issue.suggestRefresh');
return this.suggestRefresh();
},
this,
),
);
this._register(
vscode.commands.registerCommand(
'issue.getCurrent',
() => {
/* __GDPR__
"issue.getCurrent" : {}
*/
this.telemetry.sendTelemetryEvent('issue.getCurrent');
return this.getCurrent();
},
this,
),
);
this._register(
vscode.commands.registerCommand(
'issue.editQuery',
(query: QueryNode) => {
/* __GDPR__
"issue.editQuery" : {}
*/
this.telemetry.sendTelemetryEvent('issue.editQuery');
return editQuery(ISSUES_SETTINGS_NAMESPACE, query.queryLabel);
},
this,
),
);
this._register(
vscode.commands.registerCommand(
'issue.createIssue',
() => {
/* __GDPR__
"issue.createIssue" : {}
*/
this.telemetry.sendTelemetryEvent('issue.createIssue');
return this.createIssue();
},
this,
),
);
this._register(
vscode.commands.registerCommand(
'issue.createIssueFromFile',
async () => {
/* __GDPR__
"issue.createIssueFromFile" : {}
*/
this.telemetry.sendTelemetryEvent('issue.createIssueFromFile');
await vscode.commands.executeCommand('setContext', CREATING_ISSUE_FROM_FILE_CONTEXT, true);
await this.createIssueFromFile();
await vscode.commands.executeCommand('setContext', CREATING_ISSUE_FROM_FILE_CONTEXT, false);
},
this,
),
);
this._register(
vscode.commands.registerCommand('issue.issueCompletion', () => {
/* __GDPR__
"issue.issueCompletion" : {}
*/
this.telemetry.sendTelemetryEvent('issue.issueCompletion');
}),
);
this._register(
vscode.commands.registerCommand('issue.userCompletion', () => {
/* __GDPR__
"issue.userCompletion" : {}
*/
this.telemetry.sendTelemetryEvent('issue.userCompletion');
}),
);
this._register(
vscode.commands.registerCommand('issue.signinAndRefreshList', async () => {
return this.manager.authenticate();
}),
);
this._register(
vscode.commands.registerCommand('issue.goToLinkedCode', async (issueModel: any) => {
return openCodeLink(issueModel, this.manager);
}),
);
this._register(
vscode.commands.registerCommand('issue.chatSummarizeIssue', (issue: any) => {
if (!(issue instanceof IssueModel || issue instanceof PRNode)) {
return;
}
/* __GDPR__
"issue.chatSummarizeIssue" : {}
*/
this.telemetry.sendTelemetryEvent('issue.chatSummarizeIssue');
if (issue instanceof IssueModel) {
commands.executeCommand(commands.NEW_CHAT, { inputValue: vscode.l10n.t('@githubpr Summarize issue {0}/{1}#{2}', issue.remote.owner, issue.remote.repositoryName, issue.number) });
} else {
const pullRequestModel = issue.pullRequestModel;
const remote = pullRequestModel.githubRepository.remote;
commands.executeCommand(commands.NEW_CHAT, { inputValue: vscode.l10n.t('@githubpr Summarize pull request {0}/{1}#{2}', remote.owner, remote.repositoryName, pullRequestModel.number) });
}
}),
);
this._register(
vscode.commands.registerCommand('issue.chatSuggestFix', (issue: any) => {
if (!(issue instanceof IssueModel)) {
return;
}
/* __GDPR__
"issue.chatSuggestFix" : {}
*/
this.telemetry.sendTelemetryEvent('issue.chatSuggestFix');
commands.executeCommand(commands.NEW_CHAT, { inputValue: vscode.l10n.t('@githubpr Find a fix for issue {0}/{1}#{2}', issue.remote.owner, issue.remote.repositoryName, issue.number) });
}),
);
this._register(vscode.commands.registerCommand('issues.configureIssuesViewlet', async () => {
/* __GDPR__
"issues.configureIssuesViewlet" : {}
*/
return vscode.commands.executeCommand(
'workbench.action.openSettings',
`@ext:${EXTENSION_ID} issues`,
);
}));
this._stateManager.tryInitializeAndWait().then(() => {
this.registerCompletionProviders();
this._register(
vscode.languages.registerHoverProvider(
'*',
new IssueHoverProvider(this.manager, this._stateManager, this.context, this.telemetry),
),
);
this._register(
vscode.languages.registerHoverProvider('*', new UserHoverProvider(this.manager, this.telemetry)),
);
const todoProvider = new IssueTodoProvider(this.context, this.copilotRemoteAgentManager);
this._register(
vscode.languages.registerCodeActionsProvider('*', todoProvider, { providedCodeActionKinds: [vscode.CodeActionKind.QuickFix] }),
);
});
}
private documentFilters: Array<vscode.DocumentFilter | string> = [
{ language: 'php' },
{ language: 'powershell' },
{ language: 'jade' },
{ language: 'python' },
{ language: 'r' },
{ language: 'razor' },
{ language: 'ruby' },
{ language: 'rust' },
{ language: 'scminput' },
{ language: 'scss' },
{ language: 'search-result' },
{ language: 'shaderlab' },
{ language: 'shellscript' },
{ language: 'sql' },
{ language: 'swift' },
{ language: 'typescript' },
{ language: 'vb' },
{ language: 'xml' },
{ language: 'yaml' },
{ language: 'markdown' },
{ language: 'bat' },
{ language: 'clojure' },
{ language: 'coffeescript' },
{ language: 'jsonc' },
{ language: 'c' },
{ language: 'cpp' },
{ language: 'csharp' },
{ language: 'css' },
{ language: 'dockerfile' },
{ language: 'fsharp' },
{ language: 'git-commit' },
{ language: 'go' },
{ language: 'groovy' },
{ language: 'handlebars' },
{ language: 'hlsl' },
{ language: 'html' },
{ language: 'ini' },
{ language: 'java' },
{ language: 'javascriptreact' },
{ language: 'javascript' },
{ language: 'json' },
{ language: 'less' },
{ language: 'log' },
{ language: 'lua' },
{ language: 'makefile' },
{ language: 'ignore' },
{ language: 'properties' },
{ language: 'objective-c' },
{ language: 'perl' },
{ language: 'perl6' },
{ language: 'typescriptreact' },
{ language: 'yml' },
'*',
];
private registerCompletionProviders() {
const providers: {
provider: typeof IssueCompletionProvider | typeof UserCompletionProvider;
trigger: string;
disposable: vscode.Disposable | undefined;
configuration: string;
}[] = [
{
provider: IssueCompletionProvider,
trigger: '#',
disposable: undefined,
configuration: `${ISSUE_COMPLETIONS}.${ENABLED}`,
},
{
provider: UserCompletionProvider,
trigger: '@',
disposable: undefined,
configuration: `${USER_COMPLETIONS}.${ENABLED}`,
},
];
for (const element of providers) {
if (vscode.workspace.getConfiguration(ISSUES_SETTINGS_NAMESPACE).get(element.configuration, true)) {
this._register(
(element.disposable = vscode.languages.registerCompletionItemProvider(
this.documentFilters,
new element.provider(this._stateManager, this.manager, this.context),
element.trigger,
)),
);
}
}
this._register(
vscode.workspace.onDidChangeConfiguration(change => {
for (const element of providers) {
if (change.affectsConfiguration(`${ISSUES_SETTINGS_NAMESPACE}.${element.configuration}`)) {
const newValue: boolean = vscode.workspace
.getConfiguration(ISSUES_SETTINGS_NAMESPACE)
.get(element.configuration, true);
if (!newValue && element.disposable) {
element.disposable.dispose();
element.disposable = undefined;
} else if (newValue && !element.disposable) {
this._register(
(element.disposable = vscode.languages.registerCompletionItemProvider(
this.documentFilters,
new element.provider(this._stateManager, this.manager, this.context),
element.trigger,
)),
);
}
break;
}
}
}),
);
}
async createIssue() {
let uri = vscode.window.activeTextEditor?.document.uri;
let folderManager: FolderRepositoryManager | undefined = uri ? this.manager.getManagerForFile(uri) : undefined;
const alwaysPrompt = vscode.workspace.getConfiguration(ISSUES_SETTINGS_NAMESPACE).get<boolean>(ALWAYS_PROMPT_FOR_NEW_ISSUE_REPO);
if (!folderManager || alwaysPrompt) {
folderManager = await this.chooseRepo(vscode.l10n.t('Select the repo to create the issue in.'));
uri = folderManager?.repository.rootUri;
}
if (!folderManager || !uri) {
return;
}
const template = await this.chooseTemplate(folderManager);
this._newIssueCache.clear();
const remoteName = folderManager.repository.state.HEAD?.upstream?.remote;
let remote = remoteName ? folderManager.repository.state.remotes.find(r => r.name === remoteName) : undefined;
if (!remote) {
const potentialRemotes = folderManager.repository.state.remotes.filter(r => r.fetchUrl || r.pushUrl);
interface RemoteChoice extends vscode.QuickPickItem {
remote: Remote;
}
const choices: RemoteChoice[] = potentialRemotes.map(remote => ({
label: `${remote.name}: ${remote.fetchUrl || remote.pushUrl}`,
remote,
}));
const choice = await vscode.window.showQuickPick(choices, { placeHolder: vscode.l10n.t('Select a remote to file this issue to') });
if (!choice) {
return;
}
remote = choice.remote;
}
let options: NewIssueFileOptions = { remote };
if (template) {
options = {
...options,
title: template.title,
body: template.body,
labels: template.labels,
assignees: template.assignees,
};
}
this.makeNewIssueFile(uri, options);
}
async createIssueFromFile() {
const metadata = await extractMetadataFromFile(this.manager);
if (!metadata || !vscode.window.activeTextEditor) {
return;
}
const createSucceeded = await this.doCreateIssue(
this.createIssueInfo?.document,
this.createIssueInfo?.newIssue,
metadata.title,
metadata.body,
metadata.assignees,
metadata.labels,
metadata.milestone,
metadata.projects,
this.createIssueInfo?.lineNumber,
this.createIssueInfo?.insertIndex,
metadata.originUri
);
this.createIssueInfo = undefined;
if (createSucceeded && vscode.window.tabGroups.activeTabGroup.activeTab) {
await vscode.window.activeTextEditor.document.save();
await vscode.window.tabGroups.close(vscode.window.tabGroups.activeTabGroup.activeTab);
this._newIssueCache.clear();
}
}
getCurrent() {
// This is used by the "api" command issues.getCurrent
const currentIssues = this._stateManager.currentIssues();
if (currentIssues.length > 0) {
return {
owner: currentIssues[0].issue.remote.owner,
repo: currentIssues[0].issue.remote.repositoryName,
number: currentIssues[0].issue.number,
};
}
return undefined;
}
refreshView() {
this._stateManager.refreshCacheNeeded();
}
async suggestRefresh() {
await vscode.commands.executeCommand('hideSuggestWidget');
await this._stateManager.refresh();
return vscode.commands.executeCommand('editor.action.triggerSuggest');
}
openIssue(issueModel: any) {
if (issueModel instanceof IssueModel) {
return vscode.env.openExternal(vscode.Uri.parse(issueModel.html_url));
}
return undefined;
}
async doStartWorking(
matchingRepoManager: FolderRepositoryManager | undefined,
issueModel: IssueModel,
needsBranchPrompt?: boolean,
) {
let repoManager = matchingRepoManager;
let githubRepository = issueModel.githubRepository;
let remote = issueModel.remote;
if (!repoManager) {
repoManager = await this.chooseRepo(vscode.l10n.t('Choose which repository you want to work on this issue in.'));
if (!repoManager) {
return;
}
githubRepository = await repoManager.getOrigin();
remote = githubRepository.remote;
}
const remoteNameResult = await repoManager.findUpstreamForItem({ githubRepository, remote });
if (remoteNameResult.needsFork) {
if ((await repoManager.tryOfferToFork(githubRepository)) === undefined) {
return;
}
}
// Determine whether to checkout the default branch based on workingBaseBranch setting
const workingBaseBranchConfig = vscode.workspace.getConfiguration(ISSUES_SETTINGS_NAMESPACE).get<string>(WORKING_BASE_BRANCH);
let checkoutDefaultBranch = false;
if (workingBaseBranchConfig === 'defaultBranch') {
checkoutDefaultBranch = true;
} else if (workingBaseBranchConfig === 'prompt') {
const currentBranchName = repoManager.repository.state.HEAD?.name;
const defaults = await repoManager.getPullRequestDefaults();
const defaultBranchName = defaults.base;
if (!currentBranchName) {
// If we can't determine the current branch, default to the default branch
checkoutDefaultBranch = true;
} else if (currentBranchName === defaultBranchName) {
// If already on the default branch, no need to prompt
checkoutDefaultBranch = false;
} else {
const choice = await vscode.window.showQuickPick([currentBranchName, defaultBranchName], {
placeHolder: vscode.l10n.t('Which branch should be used as the base for the new issue branch?'),
});
if (choice === undefined) {
// User cancelled the prompt
return;
}
checkoutDefaultBranch = choice === defaultBranchName;
}
}
// else workingBaseBranchConfig === 'currentBranch', checkoutDefaultBranch remains false
await this._stateManager.setCurrentIssue(
repoManager,
new CurrentIssue(issueModel, repoManager, this._stateManager, remoteNameResult.remote, needsBranchPrompt),
checkoutDefaultBranch
);
}
async startWorking(issue: any) {
if (issue instanceof IssueModel) {
return this.doStartWorking(this.manager.getManagerForIssueModel(issue), issue);
} else if (issue instanceof vscode.Uri) {
const match = issue.toString().match(ISSUE_OR_URL_EXPRESSION);
const parsed = parseIssueExpressionOutput(match);
const folderManager = this.manager.folderManagers.find(folderManager =>
folderManager.gitHubRepositories.find(repo => repo.remote.owner === parsed?.owner && repo.remote.repositoryName === parsed.name));
if (parsed && folderManager) {
const issueModel = await getIssue(this._stateManager, folderManager, issue.toString(), parsed);
if (issueModel) {
return this.doStartWorking(folderManager, issueModel);
}
}
}
}
async startWorkingBranchPrompt(issueModel: any) {
if (!(issueModel instanceof IssueModel)) {
return;
}
this.doStartWorking(this.manager.getManagerForIssueModel(issueModel), issueModel, true);
}
async stopWorking(issueModel: any) {
let folderManager = this.manager.getManagerForIssueModel(issueModel);
if (!folderManager) {
folderManager = await this.chooseRepo(vscode.l10n.t('Choose which repository you want to stop working on this issue in.'));
if (!folderManager) {
return;
}
}
if (
issueModel instanceof IssueModel &&
this._stateManager.currentIssue(folderManager.repository.rootUri)?.issue.number === issueModel.number
) {
await this._stateManager.setCurrentIssue(folderManager, undefined, true);
}
}
private async statusBarActions(currentIssue: CurrentIssue) {
const openIssueText: string = vscode.l10n.t('{0} Open #{1} {2}', '$(globe)', currentIssue.issue.number, currentIssue.issue.title);
const pullRequestText: string = vscode.l10n.t({ message: '{0} Create pull request for #{1} (pushes branch)', args: ['$(git-pull-request)', currentIssue.issue.number], comment: ['The first placeholder is an icon and shouldn\'t be localized', 'The second placeholder is the ID number of a GitHub Issue.'] });
let defaults: PullRequestDefaults | undefined;
try {
defaults = await currentIssue.manager.getPullRequestDefaults();
} catch (e) {
// leave defaults undefined
}
const stopWorkingText: string = vscode.l10n.t('{0} Stop working on #{1}', '$(primitive-square)', currentIssue.issue.number);
const choices =
currentIssue.branchName && defaults
? [openIssueText, pullRequestText, stopWorkingText]
: [openIssueText, pullRequestText, stopWorkingText];
const response: string | undefined = await vscode.window.showQuickPick(choices, {
placeHolder: vscode.l10n.t('Current issue options'),
});
switch (response) {
case openIssueText:
return this.openIssue(currentIssue.issue);
case pullRequestText: {
const reviewManager = ReviewManager.getReviewManagerForFolderManager(
this.reviewsManager.reviewManagers,
currentIssue.manager,
);
if (reviewManager) {
return pushAndCreatePR(currentIssue.manager, reviewManager, this._stateManager);
}
break;
}
case stopWorkingText:
return this._stateManager.setCurrentIssue(currentIssue.manager, undefined, true);
}
}
async statusBar() {
const currentIssues = this._stateManager.currentIssues();
if (currentIssues.length === 1) {
return this.statusBarActions(currentIssues[0]);
} else {
interface IssueChoice extends vscode.QuickPickItem {
currentIssue: CurrentIssue;
}
const choices: IssueChoice[] = currentIssues.map(currentIssue => {
return {
label: vscode.l10n.t('#{0} from {1}', currentIssue.issue.number, `${currentIssue.issue.githubRepository.remote.owner}/${currentIssue.issue.githubRepository.remote.repositoryName}`),
currentIssue,
};
});
const response: IssueChoice | undefined = await vscode.window.showQuickPick(choices);
if (response) {
return this.statusBarActions(response.currentIssue);
}
}
}
private stringToUint8Array(input: string): Uint8Array {
const encoder = new TextEncoder();
return encoder.encode(input);
}
copyIssueNumber(issueModel: any) {
if (issueModel instanceof IssueModel) {
return vscode.env.clipboard.writeText(issueModel.number.toString());
}