Skip to content

fixbug: format error on vscode-build.log - #329

Open
toucheres wants to merge 5 commits into
xmake-io:devfrom
toucheres:dev
Open

fixbug: format error on vscode-build.log#329
toucheres wants to merge 5 commits into
xmake-io:devfrom
toucheres:dev

Conversation

@toucheres

Copy link
Copy Markdown
Contributor

关闭颜色输出,并新增日志清洗流程

Copilot AI review requested due to automatic review settings March 24, 2026 14:52
@gemini-code-assist

Copy link
Copy Markdown

Summary of Changes

Hello, 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

  • Disable Color Output: Configured terminal environment variables to explicitly disable color output when generating build logs, preventing ANSI escape codes from polluting log files.
  • Log Sanitization Utility: Introduced a new utility function, sanitizeBuildLogText, to clean log content by removing terminal control bytes, ANSI escape sequences, and other non-printable characters.
  • Integrate Sanitization: Applied the new log sanitization function to the decoded build log content within the problem list processing, ensuring that diagnostic parsers receive clean, plain text.

🧠 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 Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

这个拉取请求通过禁用任务执行时的颜色输出并引入日志清理流程,解决了 vscode-build.log 中的格式错误问题。src/terminal.ts 中的更改正确地添加了环境变量来抑制颜色代码,但此逻辑在两个方法中存在重复。src/utils.ts 中新增的 sanitizeBuildLogText 函数能有效地清理日志内容。我的审查意见包括重构重复代码以提高可维护性,以及简化新的清理逻辑中的一部分。

Comment thread src/terminal.ts
Comment on lines +60 to +66
options["env"] = {
XMAKE_LOGFILE: this.logfile,
XMAKE_COLORTERM: "nocolor",
COLORTERM: "nocolor",
NO_COLOR: "1",
CLICOLOR: "0"
};

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

这块用于禁用颜色的环境变量设置在 execv 方法的 88-94 行也存在重复。为了提高代码的可维护性并减少冗余,建议将这部分逻辑提取到一个共享的辅助函数或常量中。

Comment thread src/utils.ts

// 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');

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

用于标准化换行符的两次 replace 调用可以合并为一次,使用更简洁的正则表达式。

Suggested change
let cleaned = text.replace(/\r\n/g, '\n').replace(/\r/g, '\n');
let cleaned = text.replace(/\r\n?/g, '\n');

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

Comment thread src/terminal.ts
Comment on lines 58 to +66
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"
};

Copilot AI Mar 24, 2026

Copy link

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
Comment thread src/terminal.ts
Comment on lines 86 to +94
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"
};

Copilot AI Mar 24, 2026

Copy link

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
Comment thread src/utils.ts
Comment on lines +124 to +127
// Apply backspaces to avoid broken words from in-place terminal updates.
while (/\x08/.test(cleaned)) {
cleaned = cleaned.replace(/[^\n]\x08/g, '').replace(/\x08/g, '');
}

Copilot AI Mar 24, 2026

Copy link

Choose a reason for hiding this comment

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

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.

Suggested change
// 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('');

Copilot uses AI. Check for mistakes.
Comment thread src/terminal.ts
options["env"] = {XMAKE_LOGFILE: this.logfile};
options["env"] = {
XMAKE_LOGFILE: this.logfile,
XMAKE_COLORTERM: "nocolor",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

这个影响有点大,正常编译输出的颜色输出 也没了。很多用户还是需要的

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.

3 participants