Skip to content

Fixing Command Line Truncation#4844

Open
hanniavalera wants to merge 3 commits intomainfrom
dev/hanniavalera/truncFix
Open

Fixing Command Line Truncation#4844
hanniavalera wants to merge 3 commits intomainfrom
dev/hanniavalera/truncFix

Conversation

@hanniavalera
Copy link
Copy Markdown
Contributor

@hanniavalera hanniavalera commented Mar 26, 2026

This change addresses item #4836

This changes visible behavior

This pull request refactors the handling of file compilation commands in the CMakeDriver class to address issues with long command lines being truncated in the VS Code terminal, especially for commands exceeding the PTY input buffer limit (4096 bytes). The solution replaces the previous approach of sending command strings via terminal.sendText() with direct process execution using a pseudoterminal, ensuring all arguments are preserved regardless of length. Additionally, comprehensive unit tests have been added to verify correct argument handling and command execution.

Key changes include:

Refactoring of file compilation terminal logic

  • Removed the _compileTerms map and all logic related to caching and disposing of file compilation terminals, simplifying resource management and reducing potential for stale terminals. [1] [2] [3]
  • Updated the runCompileCommand() method to:
    • Use a VS Code pseudoterminal (vscode.Pseudoterminal) that directly executes the compiler process with arguments as an array, bypassing the PTY buffer limitation and ensuring complete command execution for very long compile commands.
    • Fallback to the previous terminal approach only if argument splitting fails (which should not occur in practice).

Dependency and import cleanup

  • Removed unused imports such as shlex from cmakeDriver.ts since command splitting is now handled elsewhere.

Unit tests for compile command handling

  • Added a new test suite (test/unit-tests/backend/compile-command.test.ts) that:

    • Verifies correct population of arguments from both command strings and pre-split arrays.
    • Tests the extraction of executables and arguments from command arrays.
    • Ensures that long command lines (exceeding 4096 or even 8192 bytes) are fully preserved and executed without truncation.
    • Checks display formatting for command strings and argument quoting.

    As you can see, long command lines exceeding 4096 can be executed without truncation:

image image

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses issue #4836 by changing how “Compile Active File” runs compilation database commands, aiming to avoid VS Code terminal input truncation for long command lines by executing the compiler directly via a pseudoterminal rather than sending text to a shell terminal.

Changes:

  • Refactors CMakeDriver.runCompileCommand() to execute compile commands via a vscode.Pseudoterminal + proc.execute() and removes cached file-compilation terminals.
  • Adds a new backend unit test suite validating compile command argument handling and very long command strings.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.

File Description
src/drivers/cmakeDriver.ts Switches file compilation to a pseudoterminal-backed proc.execute() flow to avoid PTY input truncation; removes terminal caching/disposal logic.
test/unit-tests/backend/compile-command.test.ts Adds tests for argument population/splitting and long command-line preservation/display formatting.

@hanniavalera hanniavalera force-pushed the dev/hanniavalera/truncFix branch from 906637c to b1f64c6 Compare March 27, 2026 15:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants