mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-11 18:48:33 -05:00
Merge from vscode 05fc61ffb1aee9fd19173c32113daed079f9b7bd (#5074)
* Merge from vscode 05fc61ffb1aee9fd19173c32113daed079f9b7bd * fix tests
This commit is contained in:
@@ -30,9 +30,9 @@ import { LanguageConfigurationRegistry } from 'vs/editor/common/modes/languageCo
|
||||
import { NULL_LANGUAGE_IDENTIFIER } from 'vs/editor/common/modes/nullMode';
|
||||
import { ignoreBracketsInToken } from 'vs/editor/common/modes/supports';
|
||||
import { BracketsUtils, RichEditBracket, RichEditBrackets } from 'vs/editor/common/modes/supports/richEditBrackets';
|
||||
import { IStringStream, ITextSnapshot } from 'vs/platform/files/common/files';
|
||||
import { ITheme, ThemeColor } from 'vs/platform/theme/common/themeService';
|
||||
import { withUndefinedAsNull } from 'vs/base/common/types';
|
||||
import { VSBufferReadableStream, VSBuffer } from 'vs/base/common/buffer';
|
||||
|
||||
const CHEAP_TOKENIZATION_LENGTH_LIMIT = 2048;
|
||||
|
||||
@@ -46,36 +46,54 @@ export function createTextBufferFactory(text: string): model.ITextBufferFactory
|
||||
return builder.finish();
|
||||
}
|
||||
|
||||
export function createTextBufferFactoryFromStream(stream: IStringStream, filter?: (chunk: string) => string): Promise<model.ITextBufferFactory> {
|
||||
return new Promise<model.ITextBufferFactory>((c, e) => {
|
||||
let done = false;
|
||||
let builder = createTextBufferBuilder();
|
||||
interface ITextStream {
|
||||
on(event: 'data', callback: (data: string) => void): void;
|
||||
on(event: 'error', callback: (err: Error) => void): void;
|
||||
on(event: 'end', callback: () => void): void;
|
||||
on(event: string, callback: any): void;
|
||||
}
|
||||
|
||||
export function createTextBufferFactoryFromStream(stream: ITextStream, filter?: (chunk: string) => string, validator?: (chunk: string) => Error | undefined): Promise<model.ITextBufferFactory>;
|
||||
export function createTextBufferFactoryFromStream(stream: VSBufferReadableStream, filter?: (chunk: VSBuffer) => VSBuffer, validator?: (chunk: VSBuffer) => Error | undefined): Promise<model.ITextBufferFactory>;
|
||||
export function createTextBufferFactoryFromStream(stream: ITextStream | VSBufferReadableStream, filter?: (chunk: any) => string | VSBuffer, validator?: (chunk: any) => Error | undefined): Promise<model.ITextBufferFactory> {
|
||||
return new Promise<model.ITextBufferFactory>((resolve, reject) => {
|
||||
const builder = createTextBufferBuilder();
|
||||
|
||||
let done = false;
|
||||
|
||||
stream.on('data', (chunk: string | VSBuffer) => {
|
||||
if (validator) {
|
||||
const error = validator(chunk);
|
||||
if (error) {
|
||||
done = true;
|
||||
reject(error);
|
||||
}
|
||||
}
|
||||
|
||||
stream.on('data', (chunk) => {
|
||||
if (filter) {
|
||||
chunk = filter(chunk);
|
||||
}
|
||||
|
||||
builder.acceptChunk(chunk);
|
||||
builder.acceptChunk((typeof chunk === 'string') ? chunk : chunk.toString());
|
||||
});
|
||||
|
||||
stream.on('error', (error) => {
|
||||
if (!done) {
|
||||
done = true;
|
||||
e(error);
|
||||
reject(error);
|
||||
}
|
||||
});
|
||||
|
||||
stream.on('end', () => {
|
||||
if (!done) {
|
||||
done = true;
|
||||
c(builder.finish());
|
||||
resolve(builder.finish());
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
export function createTextBufferFactoryFromSnapshot(snapshot: ITextSnapshot): model.ITextBufferFactory {
|
||||
export function createTextBufferFactoryFromSnapshot(snapshot: model.ITextSnapshot): model.ITextBufferFactory {
|
||||
let builder = createTextBufferBuilder();
|
||||
|
||||
let chunk: string | null;
|
||||
@@ -111,12 +129,12 @@ function singleLetter(result: number): string {
|
||||
const LIMIT_FIND_COUNT = 999;
|
||||
export const LONG_LINE_BOUNDARY = 10000;
|
||||
|
||||
class TextModelSnapshot implements ITextSnapshot {
|
||||
class TextModelSnapshot implements model.ITextSnapshot {
|
||||
|
||||
private readonly _source: ITextSnapshot;
|
||||
private readonly _source: model.ITextSnapshot;
|
||||
private _eos: boolean;
|
||||
|
||||
constructor(source: ITextSnapshot) {
|
||||
constructor(source: model.ITextSnapshot) {
|
||||
this._source = source;
|
||||
this._eos = false;
|
||||
}
|
||||
@@ -731,7 +749,7 @@ export class TextModel extends Disposable implements model.ITextModel {
|
||||
return fullModelValue;
|
||||
}
|
||||
|
||||
public createSnapshot(preserveBOM: boolean = false): ITextSnapshot {
|
||||
public createSnapshot(preserveBOM: boolean = false): model.ITextSnapshot {
|
||||
return new TextModelSnapshot(this._buffer.createSnapshot(preserveBOM));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user