@@ -90,17 +90,18 @@ function executeInsights(show_diff: boolean = false) {
90
90
}
91
91
}
92
92
93
+ /**
94
+ * Execute insights command
95
+ */
93
96
function executeInsights2 ( show_diff : boolean = false , input_document : vscode . TextDocument , options : vscode . TextEditorOptions , input_path : string ) {
94
97
let configuration = vscode . workspace . getConfiguration ( 'vscode-cppinsights' ) ;
95
98
96
-
97
99
// TODO are code variables resolved, e.g. workspaceFolder?
98
100
99
101
// discardDescriptor is required, otherwise cmd is not executed b/c file is used by another process
100
102
// TODO maybe delete tmp file
101
103
tmp . file ( { prefix : path . basename ( input_path ) , postfix : '.cpp' , keep : false , discardDescriptor : true } , function ( err , output_path ) {
102
- // TODO improve condition for cmake usage... getWorkspaceFolder b/c default is ${workspaceFolder}/build
103
- const insights_command = createCall ( configuration , vscode . workspace . getWorkspaceFolder ( input_document . uri ) ? vscode . workspace . getConfiguration ( 'cmake' ) . get ( 'buildDirectory' ) : undefined , input_path , output_path ) ;
104
+ const insights_command = createCall ( configuration , vscode . workspace . getWorkspaceFolder ( input_document . uri ) && configuration . get ( "buildDirectoryPrioritizeCMake" ) ? vscode . workspace . getConfiguration ( 'cmake' ) . get ( 'buildDirectory' ) : undefined , input_path , output_path ) ;
104
105
105
106
console . log ( "Executing " + JSON . stringify ( insights_command ) ) ;
106
107
@@ -154,17 +155,20 @@ function executeInsights2(show_diff: boolean = false, input_document: vscode.Tex
154
155
// });
155
156
}
156
157
158
+ /**
159
+ * Open the output. Either show it in an editor besides the source, or open a diff.
160
+ */
157
161
function openInsightsOutput ( input_document : vscode . TextDocument , output_path : string , configuration : vscode . WorkspaceConfiguration , options : vscode . TextEditorOptions , show_diff : boolean ) {
158
162
let output_uri = vscode . Uri . file ( output_path ) ;
159
163
160
164
// TODO clarify if formatting requires open TextEditor->visually bad, but seems more reliable
161
- let formatting = ( doc : vscode . TextDocument ) => { format ( doc , options , configuration . get ( "experimental" ) != undefined ? configuration . get ( "experimental" ) ! : false ) } ;
165
+ let formatting = ( doc : vscode . TextDocument ) => { configuration . get ( "format" ) ! ? format ( doc , options , configuration . get ( "experimental" ) ! ) : ( ) => { } } ;
162
166
163
167
164
168
// was { language: vscode.window.activeTextEditor?.document.languageId, content: stdout }
165
169
console . log ( "Openning insights output" ) ;
166
170
vscode . workspace . openTextDocument ( output_uri ) . then ( ( output_document ) => {
167
- if ( ! configuration . get ( "diff" ) && ! show_diff ) {
171
+ if ( ! show_diff ) {
168
172
show ( output_document , formatting , options ) ;
169
173
}
170
174
else {
@@ -174,8 +178,11 @@ function openInsightsOutput(input_document: vscode.TextDocument, output_path: st
174
178
} ) ;
175
179
}
176
180
181
+ /**
182
+ * Format the output.
183
+ */
177
184
function format ( doc : vscode . TextDocument , options : vscode . TextEditorOptions , experimental : boolean ) {
178
- let format_options = experimental ? { tabSize : options . tabSize != undefined ? options . tabSize : 4 , insertSpaces : options . insertSpaces || false } as vscode . FormattingOptions : { tabSize : 4 , insertSpaces : false } ;
185
+ let format_options = { tabSize : options . tabSize != undefined ? options . tabSize : 4 , insertSpaces : options . insertSpaces || false } as vscode . FormattingOptions ;
179
186
console . log ( "Formatting " + doc . uri + ' ' + JSON . stringify ( format_options ) ) ;
180
187
181
188
// TODO format options are ignored, only TextEditor options are applied, investigate
@@ -190,12 +197,10 @@ function format(doc: vscode.TextDocument, options: vscode.TextEditorOptions, exp
190
197
edit . replace ( doc . uri , textEdit . range , textEdit . newText ) ;
191
198
}
192
199
jobs . push ( vscode . workspace . applyEdit ( edit ) ) ;
193
- if ( experimental ) {
194
- Promise . all ( jobs ) . then ( ( ) => {
195
- console . log ( "Saving format" ) ;
196
- doc . save ( ) ;
197
- } ) ;
198
- }
200
+ Promise . all ( jobs ) . then ( ( ) => {
201
+ console . log ( "Saving format" ) ;
202
+ doc . save ( ) ;
203
+ } ) ;
199
204
}
200
205
else {
201
206
console . log ( "No format edits" ) ;
@@ -206,6 +211,9 @@ function format(doc: vscode.TextDocument, options: vscode.TextEditorOptions, exp
206
211
} ) ;
207
212
}
208
213
214
+ /**
215
+ * Show the output.
216
+ */
209
217
function show ( doc : vscode . TextDocument , format : ( doc : vscode . TextDocument ) => void , options : vscode . TextEditorOptions ) {
210
218
console . log ( "Showing " + doc . uri ) ;
211
219
@@ -216,6 +224,9 @@ function show(doc: vscode.TextDocument, format: (doc: vscode.TextDocument) => vo
216
224
} ) ;
217
225
}
218
226
227
+ /**
228
+ * Diff the source and output.
229
+ */
219
230
function diff ( left : vscode . TextDocument , right : vscode . TextDocument , format : ( doc : vscode . TextDocument ) => void ) {
220
231
console . log ( "Diffing " + left . uri + ' - ' + right . uri ) ;
221
232
0 commit comments