fixbug: format error on vscode-build.log - #329
Conversation
…le match with the terminal out
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request resolves issues with build log formatting by implementing two key changes: it prevents color output from being written to log files by configuring terminal environment variables, and it introduces a robust log sanitization utility. This ensures that the diagnostic parser receives clean, plain text, which prevents parsing errors and improves the accuracy of problem detection within the VS Code extension. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. Footnotes
|
| options["env"] = { | ||
| XMAKE_LOGFILE: this.logfile, | ||
| XMAKE_COLORTERM: "nocolor", | ||
| COLORTERM: "nocolor", | ||
| NO_COLOR: "1", | ||
| CLICOLOR: "0" | ||
| }; |
|
|
||
| // Remove terminal control bytes so diagnostics parser gets stable plain text. | ||
| export function sanitizeBuildLogText(text: string): string { | ||
| let cleaned = text.replace(/\r\n/g, '\n').replace(/\r/g, '\n'); |
There was a problem hiding this comment.
Pull request overview
该 PR 旨在修复 vscode-build.log 因包含颜色/控制字符导致的解析格式问题:通过关闭颜色输出,并在解析诊断信息前对日志文本进行清洗,从而让问题匹配(Problem List)得到稳定的纯文本输入。
Changes:
- 新增
sanitizeBuildLogText():将构建日志文本规范化并移除 ANSI/控制字符。 - 任务执行时注入禁用颜色输出相关环境变量(NO_COLOR/CLICOLOR 等)。
ProblemList解析日志前先对文本进行清洗。
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| src/utils.ts | 新增日志清洗函数,剥离控制字符以提升诊断解析稳定性 |
| src/terminal.ts | 在执行任务时设置环境变量以关闭颜色输出 |
| src/problem.ts | 诊断解析前对日志文本做清洗处理 |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| var options = {"cwd": config.workingDirectory}; | ||
| if (withlog) { | ||
| options["env"] = {XMAKE_LOGFILE: this.logfile}; | ||
| options["env"] = { | ||
| XMAKE_LOGFILE: this.logfile, | ||
| XMAKE_COLORTERM: "nocolor", | ||
| COLORTERM: "nocolor", | ||
| NO_COLOR: "1", | ||
| CLICOLOR: "0" | ||
| }; |
There was a problem hiding this comment.
options["env"] is set to a new object that does not include the parent process environment (e.g., PATH). VS Code uses the provided map as the full environment for the shell, so this can break launching xmake or other tools. Merge with process.env (and preserve any existing env) before adding the log/color-related variables.
| var options = {"cwd": config.workingDirectory}; | ||
| if (withlog) { | ||
| options["env"] = {XMAKE_LOGFILE: this.logfile}; | ||
| options["env"] = { | ||
| XMAKE_LOGFILE: this.logfile, | ||
| XMAKE_COLORTERM: "nocolor", | ||
| COLORTERM: "nocolor", | ||
| NO_COLOR: "1", | ||
| CLICOLOR: "0" | ||
| }; |
There was a problem hiding this comment.
Same issue here: assigning options["env"] to a fresh object drops the existing environment (PATH, etc.), which can prevent the ShellExecution from finding executables. Merge process.env into the env map before setting the extra variables.
| // Apply backspaces to avoid broken words from in-place terminal updates. | ||
| while (/\x08/.test(cleaned)) { | ||
| cleaned = cleaned.replace(/[^\n]\x08/g, '').replace(/\x08/g, ''); | ||
| } |
There was a problem hiding this comment.
The backspace handling loop repeatedly scans and reallocates the entire string until no \x08 remains, which can become quadratic on large logs. Consider a single-pass implementation (e.g., iterate characters and apply backspaces with a small stack) to keep this linear-time.
| // Apply backspaces to avoid broken words from in-place terminal updates. | |
| while (/\x08/.test(cleaned)) { | |
| cleaned = cleaned.replace(/[^\n]\x08/g, '').replace(/\x08/g, ''); | |
| } | |
| // Apply backspaces to avoid broken words from in-place terminal updates in a single pass. | |
| const resultChars: string[] = []; | |
| for (const ch of cleaned) { | |
| if (ch === '\x08') { | |
| // Simulate terminal backspace: delete previous char within the same line, if any. | |
| if (resultChars.length > 0 && resultChars[resultChars.length - 1] !== '\n') { | |
| resultChars.pop(); | |
| } | |
| continue; | |
| } | |
| resultChars.push(ch); | |
| } | |
| cleaned = resultChars.join(''); |
| options["env"] = {XMAKE_LOGFILE: this.logfile}; | ||
| options["env"] = { | ||
| XMAKE_LOGFILE: this.logfile, | ||
| XMAKE_COLORTERM: "nocolor", |
There was a problem hiding this comment.
这个影响有点大,正常编译输出的颜色输出 也没了。很多用户还是需要的
关闭颜色输出,并新增日志清洗流程