@@ -39,7 +39,7 @@ class CommentCompletion extends vscode.CompletionItem {
39
39
* CompletionItem Provider that provides "///" on pressing return if previous line
40
40
* contained a "///" documentation comment.
41
41
*/
42
- class CommentCompletionProvider implements vscode . CompletionItemProvider {
42
+ class DocCommentCompletionProvider implements vscode . CompletionItemProvider {
43
43
public async provideCompletionItems (
44
44
document : vscode . TextDocument ,
45
45
position : vscode . Position
@@ -48,22 +48,35 @@ class CommentCompletionProvider implements vscode.CompletionItemProvider {
48
48
if ( position . line === 0 || isLineComment ( document , position . line - 1 ) === false ) {
49
49
return undefined ;
50
50
}
51
+ await this . continueExistingDocCommentBlock ( document , position ) ;
52
+ return [ new CommentCompletion ( "/// " , "///" , "Documentation comment" ) ] ;
53
+ }
54
+
55
+ private async continueExistingDocCommentBlock (
56
+ document : vscode . TextDocument ,
57
+ position : vscode . Position
58
+ ) {
59
+ if ( ! vscode . window . activeTextEditor ) {
60
+ return ;
61
+ }
51
62
// Fixes https://github.com/swiftlang/vscode-swift/issues/1648
52
- const match = / ^ ( \s * ) \/ \/ \s ( .+ ) / . exec ( document . lineAt ( position . line ) . text ) ;
63
+ const match = / ^ ( \s * ) ( \/ \/ ) ? \s ? ( .+ ) ? / . exec ( document . lineAt ( position . line ) . text ) ;
53
64
if ( match ) {
54
- void vscode . window . activeTextEditor ? .edit (
65
+ await vscode . window . activeTextEditor . edit (
55
66
edit => {
56
- void edit . replace (
67
+ edit . replace (
57
68
new vscode . Range ( position . line , 0 , position . line , match [ 0 ] . length ) ,
58
- `${ match [ 1 ] } ///${ match [ 2 ] } `
69
+ `${ match [ 1 ] } /// ${ match [ 3 ] ?? "" } `
59
70
) ;
60
71
} ,
61
72
{ undoStopBefore : false , undoStopAfter : true }
62
73
) ;
63
- return undefined ;
74
+ const newPosition = new vscode . Position ( position . line , match [ 1 ] . length + 4 ) ;
75
+ vscode . window . activeTextEditor . selection = new vscode . Selection (
76
+ newPosition ,
77
+ newPosition
78
+ ) ;
64
79
}
65
- const completion = new CommentCompletion ( "/// " , "///" , "Documentation comment" ) ;
66
- return [ completion ] ;
67
80
}
68
81
}
69
82
@@ -237,8 +250,9 @@ class FunctionDocumentationCompletionProvider implements vscode.CompletionItemPr
237
250
*/
238
251
export class CommentCompletionProviders implements vscode . Disposable {
239
252
functionCommentCompletion : FunctionDocumentationCompletionProvider ;
253
+ docCommentCompletion : DocCommentCompletionProvider ;
240
254
functionCommentCompletionProvider : vscode . Disposable ;
241
- commentCompletionProvider : vscode . Disposable ;
255
+ docCommentCompletionProvider : vscode . Disposable ;
242
256
243
257
constructor ( ) {
244
258
this . functionCommentCompletion = new FunctionDocumentationCompletionProvider ( ) ;
@@ -247,9 +261,10 @@ export class CommentCompletionProviders implements vscode.Disposable {
247
261
this . functionCommentCompletion ,
248
262
"/"
249
263
) ;
250
- this . commentCompletionProvider = vscode . languages . registerCompletionItemProvider (
264
+ this . docCommentCompletion = new DocCommentCompletionProvider ( ) ;
265
+ this . docCommentCompletionProvider = vscode . languages . registerCompletionItemProvider (
251
266
"swift" ,
252
- new CommentCompletionProvider ( ) ,
267
+ this . docCommentCompletion ,
253
268
"\n"
254
269
) ;
255
270
}
@@ -265,6 +280,6 @@ export class CommentCompletionProviders implements vscode.Disposable {
265
280
266
281
dispose ( ) {
267
282
this . functionCommentCompletionProvider . dispose ( ) ;
268
- this . commentCompletionProvider . dispose ( ) ;
283
+ this . docCommentCompletionProvider . dispose ( ) ;
269
284
}
270
285
}
0 commit comments