Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/problem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import * as path from 'path';
import * as os from 'os';
import {log} from './log';
import {config} from './config';
import {decodeBufferWithConfidence} from './utils';
import {decodeBufferWithConfidence, sanitizeBuildLogText} from './utils';

// the problem list class
export class ProblemList implements vscode.Disposable {
Expand Down Expand Up @@ -50,7 +50,7 @@ export class ProblemList implements vscode.Disposable {

if (!err && content) {
const decoded = decodeBufferWithConfidence(content);
const text = decoded.text;
const text = sanitizeBuildLogText(decoded.text);
// log.verbose(`diagnose logfile encoding: ${decoded.encoding}`);

// init regex of gcc/clang output
Expand Down
16 changes: 14 additions & 2 deletions src/terminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,13 @@ export class Terminal implements vscode.Disposable {

var options = {"cwd": config.workingDirectory};
if (withlog) {
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.

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

COLORTERM: "nocolor",
NO_COLOR: "1",
CLICOLOR: "0"
};
Comment on lines +60 to +66

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 on lines 58 to +66

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.
}

const kind: vscode.TaskDefinition = {
Expand All @@ -79,7 +85,13 @@ export class Terminal implements vscode.Disposable {

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"
};
Comment on lines 86 to +94

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.
}

const kind: vscode.TaskDefinition = {
Expand Down
17 changes: 17 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,23 @@ export function decodeBufferWithConfidence(buffer: Buffer): { encoding: string;
return { encoding: 'utf8-fallback', text: utf8Text };
}

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


// Strip ANSI escape sequences (e.g. colors, cursor controls).
cleaned = cleaned.replace(/\u001B\[[0-?]*[ -/]*[@-~]/g, '');

// Apply backspaces to avoid broken words from in-place terminal updates.
while (/\x08/.test(cleaned)) {
cleaned = cleaned.replace(/[^\n]\x08/g, '').replace(/\x08/g, '');
}
Comment on lines +124 to +127

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.

// Remove other non-printable control chars but keep tab/newline.
cleaned = cleaned.replace(/[\x00-\x08\x0B-\x1F\x7F]/g, '');
return cleaned;
}

// simplistic function for just checking if a string can be parsed as json
export function isJson(text?: string): boolean {
try {
Expand Down
Loading