@@ -12,9 +12,6 @@ enum SeverityNumber {
1212 Error = 2
1313}
1414
15- // The arguments field may contain a script to evaluate on startup. The result of this evaluation is stored in this variable
16- var processedArgs = '' ;
17-
1815const criticalWarningTypes = [
1916 'cppcheckError' ,
2017 'cppcheckLimit' ,
@@ -66,19 +63,6 @@ export async function activate(context: vscode.ExtensionContext) {
6663 // Create a diagnostic collection.
6764 const diagnosticCollection = vscode . languages . createDiagnosticCollection ( "Cppcheck" ) ;
6865 context . subscriptions . push ( diagnosticCollection ) ;
69-
70- // If an argument requires us to run a script we do it here
71- const config = vscode . workspace . getConfiguration ( ) ;
72- const args = config . get < string > ( "cppcheck-official.arguments" , "" ) ;
73- if ( args . includes ( '${' ) ) {
74- const scriptCommand = args . split ( "${" ) [ 1 ] . split ( "}" ) [ 0 ] ;
75- const scriptOutput = await runCommand ( scriptCommand ) ;
76- // We expect that the script output that is to be used as arguments will be wrapped with ${}
77- const scriptOutputTrimmed = scriptOutput . split ( "${" ) [ 1 ] . split ( "}" ) [ 0 ] ;
78- processedArgs = args . split ( "${" ) [ 0 ] + scriptOutputTrimmed + args . split ( "}" ) ?. [ 1 ] ;
79- } else {
80- processedArgs = args ;
81- }
8266
8367 // set up a map of timers per document URI for debounce for continuous analysis triggers
8468 // I.e. document has been changed -> DEBOUNCE_MS time passed since last change -> run cppcheck
@@ -106,6 +90,19 @@ export async function activate(context: vscode.ExtensionContext) {
10690 const userPath = config . get < string > ( "cppcheck-official.path" ) ?. trim ( ) || "" ;
10791 const commandPath = userPath ? resolvePath ( userPath ) : "cppcheck" ;
10892
93+ var args = config . get < string > ( "cppcheck-official.arguments" , "" ) ;
94+ var processedArgs = '' ;
95+ // If argument field contains command to run script we do so here
96+ if ( args . includes ( '${' ) ) {
97+ const scriptCommand = args . split ( "${" ) [ 1 ] . split ( "}" ) [ 0 ] ;
98+ const scriptOutput = await runCommand ( scriptCommand ) ;
99+ // We expect that the script output that is to be used as arguments will be wrapped with ${}
100+ const scriptOutputTrimmed = scriptOutput . split ( "${" ) [ 1 ] . split ( "}" ) [ 0 ] ;
101+ processedArgs = args . split ( "${" ) [ 0 ] + scriptOutputTrimmed + args . split ( "}" ) ?. [ 1 ] ;
102+ } else {
103+ processedArgs = args ;
104+ }
105+
109106 // If disabled, clear any existing diagnostics for this doc.
110107 if ( ! isEnabled ) {
111108 diagnosticCollection . delete ( document . uri ) ;
@@ -126,6 +123,7 @@ export async function activate(context: vscode.ExtensionContext) {
126123 await runCppcheckOnFileXML (
127124 document ,
128125 commandPath ,
126+ processedArgs ,
129127 minSevString ,
130128 diagnosticCollection
131129 ) ;
@@ -175,6 +173,7 @@ export async function activate(context: vscode.ExtensionContext) {
175173async function runCppcheckOnFileXML (
176174 document : vscode . TextDocument ,
177175 commandPath : string ,
176+ processedArgs : string ,
178177 minSevString : string ,
179178 diagnosticCollection : vscode . DiagnosticCollection
180179) : Promise < void > {
0 commit comments