Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 04cba66

Browse files
author
Akos Kitta
committed
Fixed ordering of out/err chunks received from CLI
Signed-off-by: Akos Kitta <a.kitta@arduino.cc>
1 parent 506d28a commit 04cba66

File tree

3 files changed

+39
-27
lines changed

3 files changed

+39
-27
lines changed

‎arduino-ide-extension/src/node/cli-error-parser.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ function range(line: number, column?: number): Range {
105105
};
106106
}
107107

108-
exportfunction tryParse(content: string): ParseResult[] {
108+
function tryParse(content: string): ParseResult[] {
109109
// Shamelessly stolen from the Java IDE: https://github.com/arduino/Arduino/blob/43b0818f7fa8073301db1b80ac832b7b7596b828/arduino-core/src/cc/arduino/Compiler.java#L137
110110
const re = new RegExp(
111111
'(.+\\.\\w+):(\\d+)(:\\d+)*:\\s*((fatal)?\\s*error:\\s*)(.*)\\s*',

‎arduino-ide-extension/src/node/core-service-impl.ts‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -347,11 +347,7 @@ export class CoreServiceImpl extends CoreClientAware implements CoreService {
347347
} {
348348
const content: Buffer[] = [];
349349
const buffer = new AutoFlushingBuffer((chunks) => {
350-
Array.from(chunks.entries()).forEach(([severity, chunk]) => {
351-
if (chunk) {
352-
this.sendResponse(chunk, severity);
353-
}
354-
});
350+
chunks.forEach(([severity, chunk]) => this.sendResponse(chunk, severity));
355351
});
356352
const onData = StreamingResponse.createOnDataHandler({
357353
content,

‎arduino-ide-extension/src/node/utils/buffers.ts‎

Lines changed: 37 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ import { Disposable } from '@theia/core/shared/vscode-languageserver-protocol';
33
import { OutputMessage } from '../../common/protocol';
44

55
export class AutoFlushingBuffer implements Disposable {
6-
private readonly chunks=Chunks.create();
6+
private readonly chunks: Array<[OutputMessage.Severity,Uint8Array]>=[];
77
private readonly toDispose;
88
private timer?: NodeJS.Timeout;
99
private disposed = false;
1010

1111
constructor(
12-
onFlush: (chunks: Map<OutputMessage.Severity, string|undefined>) => void,
12+
onFlush: (chunks: Array<[OutputMessage.Severity, string]>) => void,
1313
taskTimeout: number = AutoFlushingBuffer.DEFAULT_FLUSH_TIMEOUT_MS
1414
) {
1515
const task = () => {
@@ -34,7 +34,9 @@ export class AutoFlushingBuffer implements Disposable {
3434
chunk: Uint8Array,
3535
severity: OutputMessage.Severity = OutputMessage.Severity.Info
3636
): void {
37-
this.chunks.get(severity)?.push(chunk);
37+
if (chunk.length) {
38+
this.chunks.push([severity, chunk]);
39+
}
3840
}
3941

4042
dispose(): void {
@@ -49,32 +51,46 @@ export namespace AutoFlushingBuffer {
4951
export const DEFAULT_FLUSH_TIMEOUT_MS = 32;
5052
}
5153

52-
type Chunks = Map<OutputMessage.Severity, Uint8Array[]>;
54+
type Chunks = Array<[OutputMessage.Severity, Uint8Array]>;
5355
namespace Chunks {
54-
export function create(): Chunks {
55-
return new Map([
56-
[OutputMessage.Severity.Error, []],
57-
[OutputMessage.Severity.Warning, []],
58-
[OutputMessage.Severity.Info, []],
59-
]);
60-
}
6156
export function clear(chunks: Chunks): Chunks {
62-
for (const chunk of chunks.values()) {
63-
chunk.length = 0;
64-
}
57+
chunks.length = 0;
6558
return chunks;
6659
}
6760
export function isEmpty(chunks: Chunks): boolean {
6861
return ![...chunks.values()].some((chunk) => Boolean(chunk.length));
6962
}
7063
export function toString(
7164
chunks: Chunks
72-
): Map<OutputMessage.Severity, string | undefined> {
73-
return new Map(
74-
Array.from(chunks.entries()).map(([severity, buffers]) => [
75-
severity,
76-
buffers.length ? Buffer.concat(buffers).toString() : undefined,
77-
])
78-
);
65+
): Array<[OutputMessage.Severity, string]> {
66+
const result: Array<[OutputMessage.Severity, string]> = [];
67+
let current:
68+
| { severity: OutputMessage.Severity; buffers: Uint8Array[] }
69+
| undefined = undefined;
70+
const appendToResult = () => {
71+
if (current && current.buffers) {
72+
result.push([
73+
current.severity,
74+
Buffer.concat(current.buffers).toString('utf-8'),
75+
]);
76+
}
77+
};
78+
for (const [severity, buffer] of chunks) {
79+
if (!buffer.length) {
80+
continue;
81+
}
82+
if (!current) {
83+
current = { severity, buffers: [buffer] };
84+
} else {
85+
if (current.severity === severity) {
86+
current.buffers.push(buffer);
87+
} else {
88+
appendToResult();
89+
current = { severity, buffers: [buffer] };
90+
}
91+
}
92+
}
93+
appendToResult();
94+
return result;
7995
}
8096
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /