Merge from vscode 31e03b8ffbb218a87e3941f2b63a249f061fe0e4 (#4986)

This commit is contained in:
Anthony Dresser
2019-04-10 16:29:23 -07:00
committed by GitHub
parent 18c54f41bd
commit 8315dacda4
320 changed files with 5540 additions and 3822 deletions

View File

@@ -4,7 +4,7 @@
*--------------------------------------------------------------------------------------------*/
declare var Buffer: any;
const hasBuffer = (typeof Buffer !== 'undefined');
export const hasBuffer = (typeof Buffer !== 'undefined');
let textEncoder: TextEncoder | null;
let textDecoder: TextDecoder | null;
@@ -20,6 +20,11 @@ export class VSBuffer {
}
public static wrap(actual: Uint8Array): VSBuffer {
if (hasBuffer && !(Buffer.isBuffer(actual))) {
// https://nodejs.org/dist/latest-v10.x/docs/api/buffer.html#buffer_class_method_buffer_from_arraybuffer_byteoffset_length
// Create a zero-copy Buffer wrapper around the ArrayBuffer pointed to by the Uint8Array
actual = Buffer.from(actual.buffer, actual.byteOffset, actual.byteLength);
}
return new VSBuffer(actual);
}
@@ -124,3 +129,44 @@ function readUint8(source: Uint8Array, offset: number): number {
function writeUint8(destination: Uint8Array, value: number, offset: number): void {
destination[offset] = value;
}
export interface VSBufferReadable {
/**
* Read data from the underlying source. Will return
* null to indicate that no more data can be read.
*/
read(): VSBuffer | null;
}
/**
* Helper to fully read a VSBuffer readable into a single buffer.
*/
export function readableToBuffer(readable: VSBufferReadable): VSBuffer {
const chunks: VSBuffer[] = [];
let chunk: VSBuffer | null;
while (chunk = readable.read()) {
chunks.push(chunk);
}
return VSBuffer.concat(chunks);
}
/**
* Helper to convert a buffer into a readable buffer.
*/
export function bufferToReadable(buffer: VSBuffer): VSBufferReadable {
let done = false;
return {
read: () => {
if (done) {
return null;
}
done = true;
return buffer;
}
};
}

View File

@@ -265,33 +265,6 @@ export namespace Event {
return emitter.event;
}
/**
* Similar to `buffer` but it buffers indefinitely and repeats
* the buffered events to every new listener.
*/
export function echo<T>(event: Event<T>, nextTick = false, buffer: T[] = []): Event<T> {
buffer = buffer.slice();
event(e => {
buffer.push(e);
emitter.fire(e);
});
const flush = (listener: (e: T) => any, thisArgs?: any) => buffer.forEach(e => listener.call(thisArgs, e));
const emitter = new Emitter<T>({
onListenerDidAdd(emitter: Emitter<T>, listener: (e: T) => any, thisArgs?: any) {
if (nextTick) {
setTimeout(() => flush(listener, thisArgs));
} else {
flush(listener, thisArgs);
}
}
});
return emitter.event;
}
export interface IChainableEvent<T> {
event: Event<T>;
map<O>(fn: (i: T) => O): IChainableEvent<O>;

View File

@@ -44,4 +44,6 @@ export namespace Schemas {
export const data: string = 'data';
export const command: string = 'command';
export const vscodeRemote: string = 'vscode-remote';
}

View File

@@ -284,7 +284,6 @@ export namespace DataUri {
}
}
export class ResourceGlobMatcher {
private readonly globalExpression: ParsedExpression;
@@ -311,3 +310,16 @@ export class ResourceGlobMatcher {
return !!this.globalExpression(resource.path);
}
}
export function toLocalResource(resource: URI, authority: string | undefined): URI {
if (authority) {
let path = resource.path;
if (path && path[0] !== paths.posix.sep) {
path = paths.posix.sep + path;
}
return resource.with({ scheme: Schemas.vscodeRemote, authority, path });
}
return resource.with({ scheme: Schemas.file });
}