Skip to content

Commit acbdeb2

Browse files
CopilotOmotola
andauthored
Fix cmake.compileFile truncating long compile commands (#4783)
* Initial plan * Fix cmake.compileFile truncating long commands at ~1024 characters (#4470) Co-authored-by: Omotola <[email protected]> * Address code review: add defensive fallback for empty/undefined arguments Co-authored-by: Omotola <[email protected]> --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: Omotola <[email protected]> Co-authored-by: Omotola <[email protected]>
1 parent 438cbb2 commit acbdeb2

2 files changed

Lines changed: 17 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ Improvements:
2727
- Honor `debugger.workingDirectory` from the CMake File API when debugging a target, so that the `DEBUGGER_WORKING_DIRECTORY` target property is used as the debugger working directory. [#4595](https://github.com/microsoft/vscode-cmake-tools/issues/4595)
2828

2929
Bug Fixes:
30+
- Fix `cmake.compileFile` command truncating long compile commands at ~1024 characters on macOS. The command is now sent to the terminal in chunks to avoid VS Code terminal buffer limitations. [#4470](https://github.com/microsoft/vscode-cmake-tools/issues/4470)
3031
- Fix configure/build sometimes using stale preset values when unsaved changes to included preset files are auto-saved before configure. The extension now explicitly refreshes presets from disk after saving, instead of relying solely on the asynchronous file watcher. [#4502](https://github.com/microsoft/vscode-cmake-tools/issues/4502)
3132
- Reduce overly verbose logging when CMake configure or build fails. The Output panel no longer floods with duplicated output, and the channel is only revealed on error rather than unconditionally. [#4749](https://github.com/microsoft/vscode-cmake-tools/issues/4749)
3233
- Fix Test Results panel not hyperlinking file paths for GoogleTest failures. The default `cmake.ctest.failurePatterns` now includes a pattern matching GoogleTest's `file:line: Failure` output format. [#4589](https://github.com/microsoft/vscode-cmake-tools/issues/4589)

src/drivers/cmakeDriver.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import * as lodash from "lodash";
88

99
import { CMakeExecutable } from '@cmt/cmakeExecutable';
1010
import * as codepages from '@cmt/codePageTable';
11+
import * as shlex from '@cmt/shlex';
1112
import { ConfigureCancelInformation, ConfigureTrigger, DiagnosticsConfiguration } from "@cmt/cmakeProject";
1213
import { CompileCommand } from '@cmt/compilationDatabase';
1314
import { ConfigurationReader, checkBuildOverridesPresent, checkConfigureOverridesPresent, checkTestOverridesPresent, checkPackageOverridesPresent, defaultNumJobs } from '@cmt/config';
@@ -575,7 +576,21 @@ export abstract class CMakeDriver implements vscode.Disposable {
575576
existing = term;
576577
}
577578
existing.show();
578-
existing.sendText(cmd.command + '\r\n');
579+
// Send the command and arguments individually to avoid terminal buffer truncation
580+
// issues with long command lines (see https://github.com/microsoft/vscode/issues/233420).
581+
// The arguments array is always populated by CompilationDatabase, either from the
582+
// compile_commands.json or by parsing the command string.
583+
const args = cmd.arguments;
584+
if (args && args.length > 0) {
585+
existing.sendText(shlex.quote(args[0]), false);
586+
for (let i = 1; i < args.length; i++) {
587+
existing.sendText(` ${shlex.quote(args[i])}`, false);
588+
}
589+
existing.sendText('', true); // Send newline to execute the command
590+
} else {
591+
// Fallback to original behavior if arguments not available
592+
existing.sendText(cmd.command + '\r\n');
593+
}
579594
return existing;
580595
}
581596

0 commit comments

Comments
 (0)