@@ -82,6 +82,7 @@ export class GitCommitInputBoxCodeActionsProvider implements CodeActionProvider
82
82
provideCodeActions ( document : TextDocument , range : Range | Selection ) : CodeAction [ ] {
83
83
const codeActions : CodeAction [ ] = [ ] ;
84
84
const diagnostics = this . diagnosticsManager . getDiagnostics ( document . uri ) ;
85
+ const wrapAllLinesCodeAction = this . getWrapAllLinesCodeAction ( document , diagnostics ) ;
85
86
86
87
for ( const diagnostic of diagnostics ) {
87
88
if ( ! diagnostic . range . contains ( range ) ) {
@@ -96,17 +97,23 @@ export class GitCommitInputBoxCodeActionsProvider implements CodeActionProvider
96
97
const codeAction = new CodeAction ( l10n . t ( 'Remove empty characters' ) , CodeActionKind . QuickFix ) ;
97
98
codeAction . diagnostics = [ diagnostic ] ;
98
99
codeAction . edit = workspaceEdit ;
99
-
100
100
codeActions . push ( codeAction ) ;
101
+
101
102
break ;
102
103
}
103
104
case DiagnosticCodes . line_length : {
104
105
const workspaceEdit = this . getWrapLineWorkspaceEdit ( document , diagnostic . range ) ;
106
+
105
107
const codeAction = new CodeAction ( l10n . t ( 'Hard wrap line' ) , CodeActionKind . QuickFix ) ;
106
108
codeAction . diagnostics = [ diagnostic ] ;
107
109
codeAction . edit = workspaceEdit ;
108
-
109
110
codeActions . push ( codeAction ) ;
111
+
112
+ if ( wrapAllLinesCodeAction ) {
113
+ wrapAllLinesCodeAction . diagnostics = [ diagnostic ] ;
114
+ codeActions . push ( wrapAllLinesCodeAction ) ;
115
+ }
116
+
110
117
break ;
111
118
}
112
119
}
@@ -116,13 +123,45 @@ export class GitCommitInputBoxCodeActionsProvider implements CodeActionProvider
116
123
}
117
124
118
125
private getWrapLineWorkspaceEdit ( document : TextDocument , range : Range ) : WorkspaceEdit {
126
+ const lineSegments = this . wrapTextDocumentLine ( document , range . start . line ) ;
127
+
128
+ const workspaceEdit = new WorkspaceEdit ( ) ;
129
+ workspaceEdit . replace ( document . uri , range , lineSegments . join ( '\n' ) ) ;
130
+
131
+ return workspaceEdit ;
132
+ }
133
+
134
+ private getWrapAllLinesCodeAction ( document : TextDocument , diagnostics : readonly Diagnostic [ ] ) : CodeAction | undefined {
135
+ const lineLengthDiagnostics = diagnostics . filter ( d => d . code === DiagnosticCodes . line_length ) ;
136
+ if ( lineLengthDiagnostics . length < 2 ) {
137
+ return undefined ;
138
+ }
139
+
140
+ const wrapAllLinesCodeAction = new CodeAction ( l10n . t ( 'Hard wrap all lines' ) , CodeActionKind . QuickFix ) ;
141
+ wrapAllLinesCodeAction . edit = this . getWrapAllLinesWorkspaceEdit ( document , lineLengthDiagnostics ) ;
142
+
143
+ return wrapAllLinesCodeAction ;
144
+ }
145
+
146
+ private getWrapAllLinesWorkspaceEdit ( document : TextDocument , diagnostics : Diagnostic [ ] ) : WorkspaceEdit {
147
+ const workspaceEdit = new WorkspaceEdit ( ) ;
148
+
149
+ for ( const diagnostic of diagnostics ) {
150
+ const lineSegments = this . wrapTextDocumentLine ( document , diagnostic . range . start . line ) ;
151
+ workspaceEdit . replace ( document . uri , diagnostic . range , lineSegments . join ( '\n' ) ) ;
152
+ }
153
+
154
+ return workspaceEdit ;
155
+ }
156
+
157
+ private wrapTextDocumentLine ( document : TextDocument , line : number ) : string [ ] {
119
158
const config = workspace . getConfiguration ( 'git' ) ;
120
159
const inputValidationLength = config . get < number > ( 'inputValidationLength' , 50 ) ;
121
160
const inputValidationSubjectLength = config . get < number | undefined > ( 'inputValidationSubjectLength' , undefined ) ;
122
- const lineLengthThreshold = range . start . line === 0 ? inputValidationSubjectLength ?? inputValidationLength : inputValidationLength ;
161
+ const lineLengthThreshold = line === 0 ? inputValidationSubjectLength ?? inputValidationLength : inputValidationLength ;
123
162
124
163
const lineSegments : string [ ] = [ ] ;
125
- const lineText = document . lineAt ( range . start . line ) . text ;
164
+ const lineText = document . lineAt ( line ) . text ;
126
165
127
166
let position = 0 ;
128
167
while ( lineText . length - position > lineLengthThreshold ) {
@@ -147,10 +186,7 @@ export class GitCommitInputBoxCodeActionsProvider implements CodeActionProvider
147
186
lineSegments . push ( lineText . substring ( position ) ) ;
148
187
}
149
188
150
- const workspaceEdit = new WorkspaceEdit ( ) ;
151
- workspaceEdit . replace ( document . uri , range , lineSegments . join ( '\n' ) ) ;
152
-
153
- return workspaceEdit ;
189
+ return lineSegments ;
154
190
}
155
191
156
192
dispose ( ) {
0 commit comments