@@ -24,6 +24,8 @@ import { ITelemetry } from '../common/telemetry';
24
24
const ISSUE_COMPLETIONS_CONFIGURATION = 'issueCompletions.enabled' ;
25
25
const USER_COMPLETIONS_CONFIGURATION = 'userCompletions.enabled' ;
26
26
27
+ const NEW_ISSUE_SCHEME = 'newIssue'
28
+
27
29
export class IssueFeatureRegistrar implements vscode . Disposable {
28
30
private _stateManager : StateManager ;
29
31
private createIssueInfo : { document : vscode . TextDocument , newIssue : NewIssue | undefined , assignee : string | undefined , lineNumber : number | undefined , insertIndex : number | undefined } | undefined ;
@@ -180,7 +182,7 @@ export class IssueFeatureRegistrar implements vscode.Disposable {
180
182
this . context . subscriptions . push ( vscode . languages . registerHoverProvider ( '*' , new IssueHoverProvider ( this . manager , this . _stateManager , this . context , this . telemetry ) ) ) ;
181
183
this . context . subscriptions . push ( vscode . languages . registerHoverProvider ( '*' , new UserHoverProvider ( this . manager , this . telemetry ) ) ) ;
182
184
this . context . subscriptions . push ( vscode . languages . registerCodeActionsProvider ( '*' , new IssueTodoProvider ( this . context ) ) ) ;
183
- this . context . subscriptions . push ( vscode . workspace . registerFileSystemProvider ( 'newIssue' , new IssueFileSystemProvider ( ) ) ) ;
185
+ this . context . subscriptions . push ( vscode . workspace . registerFileSystemProvider ( NEW_ISSUE_SCHEME , new IssueFileSystemProvider ( ) ) ) ;
184
186
} ) ;
185
187
}
186
188
@@ -223,20 +225,12 @@ export class IssueFeatureRegistrar implements vscode.Disposable {
223
225
}
224
226
225
227
async createIssue ( ) {
226
- try {
227
- const defaults = await this . manager . getPullRequestDefaults ( ) ;
228
- return vscode . env . openExternal ( vscode . Uri . parse ( `https://github.com/${ defaults . owner } /${ defaults . repo } /issues/new/choose` ) ) ;
229
- } catch ( e ) {
230
- vscode . window . showErrorMessage ( 'Unable to determine where to create the issue.' ) ;
231
- }
228
+ return this . makeNewIssueFile ( ) ;
232
229
}
233
230
234
231
async createIssueFromFile ( ) {
235
- if ( this . createIssueInfo === undefined ) {
236
- return ;
237
- }
238
232
let text : string ;
239
- if ( ! vscode . window . activeTextEditor ) {
233
+ if ( ! vscode . window . activeTextEditor || ( vscode . window . activeTextEditor . document . uri . scheme !== NEW_ISSUE_SCHEME ) ) {
240
234
return ;
241
235
}
242
236
text = vscode . window . activeTextEditor . document . getText ( ) ;
@@ -259,9 +253,9 @@ export class IssueFeatureRegistrar implements vscode.Disposable {
259
253
if ( ! title || ! body ) {
260
254
return ;
261
255
}
262
- await this . doCreateIssue ( this . createIssueInfo . document , this . createIssueInfo . newIssue , title , body , this . createIssueInfo . assignee , this . createIssueInfo . lineNumber , this . createIssueInfo . insertIndex ) ;
256
+ await this . doCreateIssue ( this . createIssueInfo ? .document , this . createIssueInfo ? .newIssue , title , body , this . createIssueInfo ? .assignee , this . createIssueInfo ? .lineNumber , this . createIssueInfo ? .insertIndex ) ;
263
257
this . createIssueInfo = undefined ;
264
- vscode . commands . executeCommand ( 'workbench.action.closeActiveEditor' ) ;
258
+ await vscode . commands . executeCommand ( 'workbench.action.closeActiveEditor' ) ;
265
259
}
266
260
267
261
async editQuery ( query : vscode . TreeItem ) {
@@ -431,22 +425,25 @@ export class IssueFeatureRegistrar implements vscode.Disposable {
431
425
quickInput . hide ( ) ;
432
426
} ) ;
433
427
quickInput . onDidTriggerButton ( async ( ) => {
434
-
435
428
title = quickInput . value ;
436
429
quickInput . busy = true ;
437
430
this . createIssueInfo = { document, newIssue, assignee, lineNumber, insertIndex } ;
438
431
439
- const bodyPath = vscode . Uri . parse ( 'newIssue:/NewIssue.md' ) ;
440
- const text = `${ title } \n\n${ body ?? '' } \n\n<!--Edit the body of your new issue then click the ✓ \"Create Issue\" button in the top right of the editor. The first line will be the issue title. Leave an empty line after the title.-->` ;
441
- await vscode . workspace . fs . writeFile ( bodyPath , this . stringToUint8Array ( text ) ) ;
442
- await vscode . window . showTextDocument ( bodyPath ) ;
432
+ this . makeNewIssueFile ( title , body ) ;
443
433
quickInput . busy = false ;
444
434
quickInput . hide ( ) ;
445
435
} ) ;
446
436
quickInput . show ( ) ;
447
437
}
448
438
449
- private async doCreateIssue ( document : vscode . TextDocument , newIssue : NewIssue | undefined , title : string , issueBody : string | undefined , assignee : string | undefined , lineNumber : number | undefined , insertIndex : number | undefined ) {
439
+ private async makeNewIssueFile ( title ?: string , body ?: string ) {
440
+ const bodyPath = vscode . Uri . parse ( `${ NEW_ISSUE_SCHEME } :/NewIssue.md` ) ;
441
+ const text = `${ title ?? 'Issue Title' } \n\n${ body ?? '' } \n\n<!--Edit the body of your new issue then click the ✓ \"Create Issue\" button in the top right of the editor. The first line will be the issue title. Leave an empty line after the title.-->` ;
442
+ await vscode . workspace . fs . writeFile ( bodyPath , this . stringToUint8Array ( text ) ) ;
443
+ await vscode . window . showTextDocument ( bodyPath ) ;
444
+ }
445
+
446
+ private async doCreateIssue ( document : vscode . TextDocument | undefined , newIssue : NewIssue | undefined , title : string , issueBody : string | undefined , assignee : string | undefined , lineNumber : number | undefined , insertIndex : number | undefined ) {
450
447
let origin : PullRequestDefaults | undefined ;
451
448
try {
452
449
origin = await this . manager . getPullRequestDefaults ( ) ;
@@ -464,13 +461,20 @@ export class IssueFeatureRegistrar implements vscode.Disposable {
464
461
assignee
465
462
} ) ;
466
463
if ( issue ) {
467
- if ( ( insertIndex !== undefined ) && ( lineNumber !== undefined ) ) {
464
+ if ( ( document !== undefined ) && ( insertIndex !== undefined ) && ( lineNumber !== undefined ) ) {
468
465
const edit : vscode . WorkspaceEdit = new vscode . WorkspaceEdit ( ) ;
469
466
const insertText : string = vscode . workspace . getConfiguration ( ISSUES_CONFIGURATION ) . get ( 'createInsertFormat' , 'number' ) === 'number' ? `#${ issue . number } ` : issue . html_url ;
470
467
edit . insert ( document . uri , new vscode . Position ( lineNumber , insertIndex ) , ` ${ insertText } ` ) ;
471
468
await vscode . workspace . applyEdit ( edit ) ;
472
469
} else {
473
- await vscode . env . openExternal ( vscode . Uri . parse ( issue . html_url ) ) ;
470
+ const copyIssueUrl = 'Copy URL' ;
471
+ const openIssue = 'Open Issue' ;
472
+ vscode . window . showInformationMessage ( 'Issue created' , copyIssueUrl , openIssue ) . then ( async ( result ) => {
473
+ switch ( result ) {
474
+ case copyIssueUrl : await vscode . env . clipboard . writeText ( issue . html_url ) ; break ;
475
+ case openIssue : await vscode . env . openExternal ( vscode . Uri . parse ( issue . html_url ) ) ; break ;
476
+ }
477
+ } )
474
478
}
475
479
this . _stateManager . refreshCacheNeeded ( ) ;
476
480
}
0 commit comments