mirror of
https://github.com/coder/code-server.git
synced 2026-05-08 13:27:25 +02:00
Update to VS Code 1.52.1
This commit is contained in:
@@ -36,7 +36,7 @@ export interface IAction extends IDisposable {
|
||||
export interface IActionRunner extends IDisposable {
|
||||
run(action: IAction, context?: any): Promise<any>;
|
||||
readonly onDidRun: Event<IRunEvent>;
|
||||
readonly onDidBeforeRun: Event<IRunEvent>;
|
||||
readonly onBeforeRun: Event<IRunEvent>;
|
||||
}
|
||||
|
||||
export interface IActionViewItem extends IDisposable {
|
||||
@@ -178,8 +178,8 @@ export interface IRunEvent {
|
||||
|
||||
export class ActionRunner extends Disposable implements IActionRunner {
|
||||
|
||||
private _onDidBeforeRun = this._register(new Emitter<IRunEvent>());
|
||||
readonly onDidBeforeRun: Event<IRunEvent> = this._onDidBeforeRun.event;
|
||||
private _onBeforeRun = this._register(new Emitter<IRunEvent>());
|
||||
readonly onBeforeRun: Event<IRunEvent> = this._onBeforeRun.event;
|
||||
|
||||
private _onDidRun = this._register(new Emitter<IRunEvent>());
|
||||
readonly onDidRun: Event<IRunEvent> = this._onDidRun.event;
|
||||
@@ -189,7 +189,7 @@ export class ActionRunner extends Disposable implements IActionRunner {
|
||||
return Promise.resolve(null);
|
||||
}
|
||||
|
||||
this._onDidBeforeRun.fire({ action: action });
|
||||
this._onBeforeRun.fire({ action: action });
|
||||
|
||||
try {
|
||||
const result = await this.runAction(action, context);
|
||||
@@ -235,6 +235,17 @@ export class Separator extends Action {
|
||||
}
|
||||
}
|
||||
|
||||
export class ActionWithMenuAction extends Action {
|
||||
|
||||
get actions(): IAction[] {
|
||||
return this._actions;
|
||||
}
|
||||
|
||||
constructor(id: string, private _actions: IAction[], label?: string, cssClass?: string, enabled?: boolean, actionCallback?: (event?: any) => Promise<any>) {
|
||||
super(id, label, cssClass, enabled, actionCallback);
|
||||
}
|
||||
}
|
||||
|
||||
export class SubmenuAction extends Action {
|
||||
|
||||
get actions(): IAction[] {
|
||||
@@ -242,7 +253,7 @@ export class SubmenuAction extends Action {
|
||||
}
|
||||
|
||||
constructor(id: string, label: string, private _actions: IAction[], cssClass?: string) {
|
||||
super(id, label, cssClass, true);
|
||||
super(id, label, cssClass, !!_actions?.length);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { mergeSort } from 'vs/base/common/arrays';
|
||||
import { URI } from 'vs/base/common/uri';
|
||||
|
||||
/**
|
||||
@@ -18,3 +19,133 @@ export function getPathFromAmdModule(requirefn: typeof require, relativePath: st
|
||||
export function getUriFromAmdModule(requirefn: typeof require, relativePath: string): URI {
|
||||
return URI.parse(requirefn.toUrl(relativePath));
|
||||
}
|
||||
|
||||
export abstract class LoaderStats {
|
||||
abstract get amdLoad(): [string, number][];
|
||||
abstract get amdInvoke(): [string, number][];
|
||||
abstract get nodeRequire(): [string, number][];
|
||||
abstract get nodeEval(): [string, number][];
|
||||
abstract get nodeRequireTotal(): number;
|
||||
|
||||
|
||||
static get(): LoaderStats {
|
||||
|
||||
|
||||
const amdLoadScript = new Map<string, number>();
|
||||
const amdInvokeFactory = new Map<string, number>();
|
||||
const nodeRequire = new Map<string, number>();
|
||||
const nodeEval = new Map<string, number>();
|
||||
|
||||
function mark(map: Map<string, number>, stat: LoaderEvent) {
|
||||
if (map.has(stat.detail)) {
|
||||
// console.warn('BAD events, DOUBLE start', stat);
|
||||
// map.delete(stat.detail);
|
||||
return;
|
||||
}
|
||||
map.set(stat.detail, -stat.timestamp);
|
||||
}
|
||||
|
||||
function diff(map: Map<string, number>, stat: LoaderEvent) {
|
||||
let duration = map.get(stat.detail);
|
||||
if (!duration) {
|
||||
// console.warn('BAD events, end WITHOUT start', stat);
|
||||
// map.delete(stat.detail);
|
||||
return;
|
||||
}
|
||||
if (duration >= 0) {
|
||||
// console.warn('BAD events, DOUBLE end', stat);
|
||||
// map.delete(stat.detail);
|
||||
return;
|
||||
}
|
||||
map.set(stat.detail, duration + stat.timestamp);
|
||||
}
|
||||
|
||||
const stats = mergeSort(require.getStats().slice(0), (a, b) => a.timestamp - b.timestamp);
|
||||
|
||||
for (const stat of stats) {
|
||||
switch (stat.type) {
|
||||
case LoaderEventType.BeginLoadingScript:
|
||||
mark(amdLoadScript, stat);
|
||||
break;
|
||||
case LoaderEventType.EndLoadingScriptOK:
|
||||
case LoaderEventType.EndLoadingScriptError:
|
||||
diff(amdLoadScript, stat);
|
||||
break;
|
||||
|
||||
case LoaderEventType.BeginInvokeFactory:
|
||||
mark(amdInvokeFactory, stat);
|
||||
break;
|
||||
case LoaderEventType.EndInvokeFactory:
|
||||
diff(amdInvokeFactory, stat);
|
||||
break;
|
||||
|
||||
case LoaderEventType.NodeBeginNativeRequire:
|
||||
mark(nodeRequire, stat);
|
||||
break;
|
||||
case LoaderEventType.NodeEndNativeRequire:
|
||||
diff(nodeRequire, stat);
|
||||
break;
|
||||
|
||||
case LoaderEventType.NodeBeginEvaluatingScript:
|
||||
mark(nodeEval, stat);
|
||||
break;
|
||||
case LoaderEventType.NodeEndEvaluatingScript:
|
||||
diff(nodeEval, stat);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
let nodeRequireTotal = 0;
|
||||
nodeRequire.forEach(value => nodeRequireTotal += value);
|
||||
|
||||
function to2dArray(map: Map<string, number>): [string, number][] {
|
||||
let res: [string, number][] = [];
|
||||
map.forEach((value, index) => res.push([index, value]));
|
||||
return res;
|
||||
}
|
||||
|
||||
return {
|
||||
amdLoad: to2dArray(amdLoadScript),
|
||||
amdInvoke: to2dArray(amdInvokeFactory),
|
||||
nodeRequire: to2dArray(nodeRequire),
|
||||
nodeEval: to2dArray(nodeEval),
|
||||
nodeRequireTotal
|
||||
};
|
||||
}
|
||||
|
||||
static toMarkdownTable(header: string[], rows: Array<Array<{ toString(): string } | undefined>>): string {
|
||||
let result = '';
|
||||
|
||||
let lengths: number[] = [];
|
||||
header.forEach((cell, ci) => {
|
||||
lengths[ci] = cell.length;
|
||||
});
|
||||
rows.forEach(row => {
|
||||
row.forEach((cell, ci) => {
|
||||
if (typeof cell === 'undefined') {
|
||||
cell = row[ci] = '-';
|
||||
}
|
||||
const len = cell.toString().length;
|
||||
lengths[ci] = Math.max(len, lengths[ci]);
|
||||
});
|
||||
});
|
||||
|
||||
// header
|
||||
header.forEach((cell, ci) => { result += `| ${cell + ' '.repeat(lengths[ci] - cell.toString().length)} `; });
|
||||
result += '|\n';
|
||||
header.forEach((_cell, ci) => { result += `| ${'-'.repeat(lengths[ci])} `; });
|
||||
result += '|\n';
|
||||
|
||||
// cells
|
||||
rows.forEach(row => {
|
||||
row.forEach((cell, ci) => {
|
||||
if (typeof cell !== 'undefined') {
|
||||
result += `| ${cell + ' '.repeat(lengths[ci] - cell.toString().length)} `;
|
||||
}
|
||||
});
|
||||
result += '|\n';
|
||||
});
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -588,3 +588,17 @@ export function asArray<T>(x: T | T[]): T[] {
|
||||
export function getRandomElement<T>(arr: T[]): T | undefined {
|
||||
return arr[Math.floor(Math.random() * arr.length)];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the first mapped value of the array which is not undefined.
|
||||
*/
|
||||
export function mapFind<T, R>(array: Iterable<T>, mapFn: (value: T) => R | undefined): R | undefined {
|
||||
for (const value of array) {
|
||||
const mapped = mapFn(value);
|
||||
if (mapped !== undefined) {
|
||||
return mapped;
|
||||
}
|
||||
}
|
||||
|
||||
return undefined;
|
||||
}
|
||||
|
||||
@@ -445,6 +445,45 @@ export function first<T>(promiseFactories: ITask<Promise<T>>[], shouldStop: (t:
|
||||
return loop();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the result of the first promise that matches the "shouldStop",
|
||||
* running all promises in parallel. Supports cancelable promises.
|
||||
*/
|
||||
export function firstParallel<T>(promiseList: Promise<T>[], shouldStop?: (t: T) => boolean, defaultValue?: T | null): Promise<T | null>;
|
||||
export function firstParallel<T, R extends T>(promiseList: Promise<T>[], shouldStop: (t: T) => t is R, defaultValue?: R | null): Promise<R | null>;
|
||||
export function firstParallel<T>(promiseList: Promise<T>[], shouldStop: (t: T) => boolean = t => !!t, defaultValue: T | null = null) {
|
||||
if (promiseList.length === 0) {
|
||||
return Promise.resolve(defaultValue);
|
||||
}
|
||||
|
||||
let todo = promiseList.length;
|
||||
const finish = () => {
|
||||
todo = -1;
|
||||
for (const promise of promiseList) {
|
||||
(promise as Partial<CancelablePromise<T>>).cancel?.();
|
||||
}
|
||||
};
|
||||
|
||||
return new Promise<T | null>((resolve, reject) => {
|
||||
for (const promise of promiseList) {
|
||||
promise.then(result => {
|
||||
if (--todo >= 0 && shouldStop(result)) {
|
||||
finish();
|
||||
resolve(result);
|
||||
} else if (todo === 0) {
|
||||
resolve(defaultValue);
|
||||
}
|
||||
})
|
||||
.catch(err => {
|
||||
if (--todo >= 0) {
|
||||
finish();
|
||||
reject(err);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
interface ILimitedTaskFactory<T> {
|
||||
factory: ITask<Promise<T>>;
|
||||
c: (value: T | Promise<T>) => void;
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
|
||||
import { codiconStartMarker } from 'vs/base/common/codicon';
|
||||
import { Emitter, Event } from 'vs/base/common/event';
|
||||
import { localize } from 'vs/nls';
|
||||
|
||||
export interface IIconRegistry {
|
||||
readonly all: IterableIterator<Codicon>;
|
||||
@@ -18,9 +19,12 @@ class Registry implements IIconRegistry {
|
||||
private readonly _onDidRegister = new Emitter<Codicon>();
|
||||
|
||||
public add(icon: Codicon) {
|
||||
if (!this._icons.has(icon.id)) {
|
||||
const existing = this._icons.get(icon.id);
|
||||
if (!existing) {
|
||||
this._icons.set(icon.id, icon);
|
||||
this._onDidRegister.fire(icon);
|
||||
} else if (icon.description) {
|
||||
existing.description = icon.description;
|
||||
} else {
|
||||
console.error(`Duplicate registration of codicon ${icon.id}`);
|
||||
}
|
||||
@@ -43,11 +47,11 @@ const _registry = new Registry();
|
||||
|
||||
export const iconRegistry: IIconRegistry = _registry;
|
||||
|
||||
export function registerIcon(id: string, def: Codicon, description?: string) {
|
||||
return new Codicon(id, def);
|
||||
export function registerCodicon(id: string, def: Codicon, description?: string): Codicon {
|
||||
return new Codicon(id, def, description);
|
||||
}
|
||||
|
||||
export class Codicon {
|
||||
export class Codicon implements CSSIcon {
|
||||
constructor(public readonly id: string, public readonly definition: Codicon | IconDefinition, public description?: string) {
|
||||
_registry.add(this);
|
||||
}
|
||||
@@ -57,6 +61,12 @@ export class Codicon {
|
||||
public get cssSelector() { return '.codicon.codicon-' + this.id; }
|
||||
}
|
||||
|
||||
export interface CSSIcon {
|
||||
readonly classNames: string;
|
||||
}
|
||||
|
||||
|
||||
|
||||
interface IconDefinition {
|
||||
character: string;
|
||||
}
|
||||
@@ -484,8 +494,15 @@ export namespace Codicon {
|
||||
export const redo = new Codicon('redo', { character: '\\ebb0' });
|
||||
export const checkAll = new Codicon('check-all', { character: '\\ebb1' });
|
||||
export const pinnedDirty = new Codicon('pinned-dirty', { character: '\\ebb2' });
|
||||
export const passFilled = new Codicon('pass-filled', { character: '\\ebb3' });
|
||||
export const circleLargeFilled = new Codicon('circle-large-filled', { character: '\\ebb4' });
|
||||
export const circleLargeOutline = new Codicon('circle-large-outline', { character: '\\ebb5' });
|
||||
|
||||
export const dropDownButton = new Codicon('drop-down-button', Codicon.chevronDown.definition, localize('dropDownButton', 'Icon for drop down buttons.'));
|
||||
}
|
||||
|
||||
// common icons
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -76,7 +76,37 @@ export function fromMap<T>(original: Map<string, T>): IStringDictionary<T> {
|
||||
return result;
|
||||
}
|
||||
|
||||
export function diffSets<T>(before: Set<T>, after: Set<T>): { removed: T[], added: T[] } {
|
||||
const removed: T[] = [];
|
||||
const added: T[] = [];
|
||||
for (let element of before) {
|
||||
if (!after.has(element)) {
|
||||
removed.push(element);
|
||||
}
|
||||
}
|
||||
for (let element of after) {
|
||||
if (!before.has(element)) {
|
||||
added.push(element);
|
||||
}
|
||||
}
|
||||
return { removed, added };
|
||||
}
|
||||
|
||||
export function diffMaps<K, V>(before: Map<K, V>, after: Map<K, V>): { removed: V[], added: V[] } {
|
||||
const removed: V[] = [];
|
||||
const added: V[] = [];
|
||||
for (let [index, value] of before) {
|
||||
if (!after.has(index)) {
|
||||
removed.push(value);
|
||||
}
|
||||
}
|
||||
for (let [index, value] of after) {
|
||||
if (!before.has(index)) {
|
||||
added.push(value);
|
||||
}
|
||||
}
|
||||
return { removed, added };
|
||||
}
|
||||
export class SetMap<K, V> {
|
||||
|
||||
private map = new Map<K, Set<V>>();
|
||||
|
||||
@@ -880,9 +880,81 @@ export class LcsDiff {
|
||||
change.modifiedStart -= bestDelta;
|
||||
}
|
||||
|
||||
// There could be multiple longest common substrings.
|
||||
// Give preference to the ones containing longer lines
|
||||
if (this._hasStrings) {
|
||||
for (let i = 1, len = changes.length; i < len; i++) {
|
||||
const aChange = changes[i - 1];
|
||||
const bChange = changes[i];
|
||||
const matchedLength = bChange.originalStart - aChange.originalStart - aChange.originalLength;
|
||||
const aOriginalStart = aChange.originalStart;
|
||||
const bOriginalEnd = bChange.originalStart + bChange.originalLength;
|
||||
const abOriginalLength = bOriginalEnd - aOriginalStart;
|
||||
const aModifiedStart = aChange.modifiedStart;
|
||||
const bModifiedEnd = bChange.modifiedStart + bChange.modifiedLength;
|
||||
const abModifiedLength = bModifiedEnd - aModifiedStart;
|
||||
// Avoid wasting a lot of time with these searches
|
||||
if (matchedLength < 5 && abOriginalLength < 20 && abModifiedLength < 20) {
|
||||
const t = this._findBetterContiguousSequence(
|
||||
aOriginalStart, abOriginalLength,
|
||||
aModifiedStart, abModifiedLength,
|
||||
matchedLength
|
||||
);
|
||||
if (t) {
|
||||
const [originalMatchStart, modifiedMatchStart] = t;
|
||||
if (originalMatchStart !== aChange.originalStart + aChange.originalLength || modifiedMatchStart !== aChange.modifiedStart + aChange.modifiedLength) {
|
||||
// switch to another sequence that has a better score
|
||||
aChange.originalLength = originalMatchStart - aChange.originalStart;
|
||||
aChange.modifiedLength = modifiedMatchStart - aChange.modifiedStart;
|
||||
bChange.originalStart = originalMatchStart + matchedLength;
|
||||
bChange.modifiedStart = modifiedMatchStart + matchedLength;
|
||||
bChange.originalLength = bOriginalEnd - bChange.originalStart;
|
||||
bChange.modifiedLength = bModifiedEnd - bChange.modifiedStart;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return changes;
|
||||
}
|
||||
|
||||
private _findBetterContiguousSequence(originalStart: number, originalLength: number, modifiedStart: number, modifiedLength: number, desiredLength: number): [number, number] | null {
|
||||
if (originalLength < desiredLength || modifiedLength < desiredLength) {
|
||||
return null;
|
||||
}
|
||||
const originalMax = originalStart + originalLength - desiredLength + 1;
|
||||
const modifiedMax = modifiedStart + modifiedLength - desiredLength + 1;
|
||||
let bestScore = 0;
|
||||
let bestOriginalStart = 0;
|
||||
let bestModifiedStart = 0;
|
||||
for (let i = originalStart; i < originalMax; i++) {
|
||||
for (let j = modifiedStart; j < modifiedMax; j++) {
|
||||
const score = this._contiguousSequenceScore(i, j, desiredLength);
|
||||
if (score > 0 && score > bestScore) {
|
||||
bestScore = score;
|
||||
bestOriginalStart = i;
|
||||
bestModifiedStart = j;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (bestScore > 0) {
|
||||
return [bestOriginalStart, bestModifiedStart];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private _contiguousSequenceScore(originalStart: number, modifiedStart: number, length: number): number {
|
||||
let score = 0;
|
||||
for (let l = 0; l < length; l++) {
|
||||
if (!this.ElementsAreEqual(originalStart + l, modifiedStart + l)) {
|
||||
return 0;
|
||||
}
|
||||
score += this._originalStringElements[originalStart + l].length;
|
||||
}
|
||||
return score;
|
||||
}
|
||||
|
||||
private _OriginalIsBoundary(index: number): boolean {
|
||||
if (index <= 0 || index >= this._originalElementsOrHash.length - 1) {
|
||||
return true;
|
||||
|
||||
@@ -629,7 +629,7 @@ export class PauseableEmitter<T> extends Emitter<T> {
|
||||
if (this._mergeFn) {
|
||||
// use the merge function to create a single composite
|
||||
// event. make a copy in case firing pauses this emitter
|
||||
const events = this._eventQueue.toArray();
|
||||
const events = Array.from(this._eventQueue);
|
||||
this._eventQueue.clear();
|
||||
super.fire(this._mergeFn(events));
|
||||
|
||||
|
||||
@@ -106,8 +106,14 @@ function leftPad(value: string, length: number, char: string = '0'): string {
|
||||
return value;
|
||||
}
|
||||
|
||||
function toHexString(value: number, bitsize: number = 32): string {
|
||||
return leftPad((value >>> 0).toString(16), bitsize / 4);
|
||||
export function toHexString(buffer: ArrayBuffer): string;
|
||||
export function toHexString(value: number, bitsize?: number): string;
|
||||
export function toHexString(bufferOrValue: ArrayBuffer | number, bitsize: number = 32): string {
|
||||
if (bufferOrValue instanceof ArrayBuffer) {
|
||||
return Array.from(new Uint8Array(bufferOrValue)).map(b => b.toString(16).padStart(2, '0')).join('');
|
||||
}
|
||||
|
||||
return leftPad((bufferOrValue >>> 0).toString(16), bitsize / 4);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -21,52 +21,52 @@ export const enum MarkdownStringTextNewlineStyle {
|
||||
}
|
||||
|
||||
export class MarkdownString implements IMarkdownString {
|
||||
private readonly _isTrusted: boolean;
|
||||
private readonly _supportThemeIcons: boolean;
|
||||
|
||||
public value: string;
|
||||
public isTrusted?: boolean;
|
||||
public supportThemeIcons?: boolean;
|
||||
|
||||
constructor(
|
||||
private _value: string = '',
|
||||
value: string = '',
|
||||
isTrustedOrOptions: boolean | { isTrusted?: boolean, supportThemeIcons?: boolean } = false,
|
||||
) {
|
||||
if (typeof this._value !== 'string') {
|
||||
this.value = value;
|
||||
if (typeof this.value !== 'string') {
|
||||
throw illegalArgument('value');
|
||||
}
|
||||
|
||||
if (typeof isTrustedOrOptions === 'boolean') {
|
||||
this._isTrusted = isTrustedOrOptions;
|
||||
this._supportThemeIcons = false;
|
||||
this.isTrusted = isTrustedOrOptions;
|
||||
this.supportThemeIcons = false;
|
||||
}
|
||||
else {
|
||||
this._isTrusted = isTrustedOrOptions.isTrusted ?? false;
|
||||
this._supportThemeIcons = isTrustedOrOptions.supportThemeIcons ?? false;
|
||||
this.isTrusted = isTrustedOrOptions.isTrusted ?? undefined;
|
||||
this.supportThemeIcons = isTrustedOrOptions.supportThemeIcons ?? false;
|
||||
}
|
||||
}
|
||||
|
||||
get value() { return this._value; }
|
||||
get isTrusted() { return this._isTrusted; }
|
||||
get supportThemeIcons() { return this._supportThemeIcons; }
|
||||
|
||||
appendText(value: string, newlineStyle: MarkdownStringTextNewlineStyle = MarkdownStringTextNewlineStyle.Paragraph): MarkdownString {
|
||||
// escape markdown syntax tokens: http://daringfireball.net/projects/markdown/syntax#backslash
|
||||
this._value += (this._supportThemeIcons ? escapeCodicons(value) : value)
|
||||
this.value += (this.supportThemeIcons ? escapeCodicons(value) : value)
|
||||
.replace(/[\\`*_{}[\]()#+\-.!]/g, '\\$&')
|
||||
.replace(/([ \t]+)/g, (_match, g1) => ' '.repeat(g1.length))
|
||||
.replace(/^>/gm, '\\>')
|
||||
.replace(/\n/g, newlineStyle === MarkdownStringTextNewlineStyle.Break ? '\\\n' : '\n\n');
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
appendMarkdown(value: string): MarkdownString {
|
||||
this._value += value;
|
||||
|
||||
this.value += value;
|
||||
return this;
|
||||
}
|
||||
|
||||
appendCodeblock(langId: string, code: string): MarkdownString {
|
||||
this._value += '\n```';
|
||||
this._value += langId;
|
||||
this._value += '\n';
|
||||
this._value += code;
|
||||
this._value += '\n```\n';
|
||||
this.value += '\n```';
|
||||
this.value += langId;
|
||||
this.value += '\n';
|
||||
this.value += code;
|
||||
this.value += '\n```\n';
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -126,7 +126,7 @@ export interface Location {
|
||||
/**
|
||||
* Matches the locations path against a pattern consisting of strings (for properties) and numbers (for array indices).
|
||||
* '*' will match a single segment, of any property name or index.
|
||||
* '**' will match a sequece of segments or no segment, of any property name or index.
|
||||
* '**' will match a sequence of segments or no segment, of any property name or index.
|
||||
*/
|
||||
matches: (patterns: JSONPath) => boolean;
|
||||
/**
|
||||
|
||||
@@ -95,6 +95,10 @@ function hasDriveLetter(path: string): boolean {
|
||||
return !!(isWindows && path && path[1] === ':');
|
||||
}
|
||||
|
||||
export function extractDriveLetter(path: string): string | undefined {
|
||||
return hasDriveLetter(path) ? path[0] : undefined;
|
||||
}
|
||||
|
||||
export function normalizeDriveLetter(path: string): string {
|
||||
if (hasDriveLetter(path)) {
|
||||
return path.charAt(0).toUpperCase() + path.slice(1);
|
||||
|
||||
@@ -131,12 +131,4 @@ export class LinkedList<E> {
|
||||
node = node.next;
|
||||
}
|
||||
}
|
||||
|
||||
toArray(): E[] {
|
||||
const result: E[] = [];
|
||||
for (let node = this._first; node !== Node.Undefined; node = node.next) {
|
||||
result.push(node.element);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,8 +6,6 @@
|
||||
import { URI } from 'vs/base/common/uri';
|
||||
import { CharCode } from 'vs/base/common/charCode';
|
||||
import { compareSubstringIgnoreCase, compare, compareSubstring, compareIgnoreCase } from 'vs/base/common/strings';
|
||||
import { isLinux } from 'vs/base/common/platform';
|
||||
import { Schemas } from 'vs/base/common/network';
|
||||
|
||||
export function getOrSet<K, V>(map: Map<K, V>, key: K, value: V): V {
|
||||
let result = map.get(key);
|
||||
@@ -77,6 +75,57 @@ export class StringIterator implements IKeyIterator<string> {
|
||||
}
|
||||
}
|
||||
|
||||
export class ConfigKeysIterator implements IKeyIterator<string> {
|
||||
|
||||
private _value!: string;
|
||||
private _from!: number;
|
||||
private _to!: number;
|
||||
|
||||
constructor(
|
||||
private readonly _caseSensitive: boolean = true
|
||||
) { }
|
||||
|
||||
reset(key: string): this {
|
||||
this._value = key;
|
||||
this._from = 0;
|
||||
this._to = 0;
|
||||
return this.next();
|
||||
}
|
||||
|
||||
hasNext(): boolean {
|
||||
return this._to < this._value.length;
|
||||
}
|
||||
|
||||
next(): this {
|
||||
// this._data = key.split(/[\\/]/).filter(s => !!s);
|
||||
this._from = this._to;
|
||||
let justSeps = true;
|
||||
for (; this._to < this._value.length; this._to++) {
|
||||
const ch = this._value.charCodeAt(this._to);
|
||||
if (ch === CharCode.Period) {
|
||||
if (justSeps) {
|
||||
this._from++;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
justSeps = false;
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
cmp(a: string): number {
|
||||
return this._caseSensitive
|
||||
? compareSubstring(a, this._value, 0, a.length, this._from, this._to)
|
||||
: compareSubstringIgnoreCase(a, this._value, 0, a.length, this._from, this._to);
|
||||
}
|
||||
|
||||
value(): string {
|
||||
return this._value.substring(this._from, this._to);
|
||||
}
|
||||
}
|
||||
|
||||
export class PathIterator implements IKeyIterator<string> {
|
||||
|
||||
private _value!: string;
|
||||
@@ -140,7 +189,7 @@ export class UriIterator implements IKeyIterator<URI> {
|
||||
private _states: UriIteratorState[] = [];
|
||||
private _stateIdx: number = 0;
|
||||
|
||||
constructor(private readonly _ignorePathCasing: boolean | undefined) { }
|
||||
constructor(private readonly _ignorePathCasing: (uri: URI) => boolean) { }
|
||||
|
||||
reset(key: URI): this {
|
||||
this._value = key;
|
||||
@@ -152,10 +201,7 @@ export class UriIterator implements IKeyIterator<URI> {
|
||||
this._states.push(UriIteratorState.Authority);
|
||||
}
|
||||
if (this._value.path) {
|
||||
this._pathIterator = new PathIterator(false, this._ignorePathCasing === undefined
|
||||
? key.scheme === Schemas.file && isLinux
|
||||
: !this._ignorePathCasing
|
||||
);
|
||||
this._pathIterator = new PathIterator(false, !this._ignorePathCasing(key));
|
||||
this._pathIterator.reset(key.path);
|
||||
if (this._pathIterator.value()) {
|
||||
this._states.push(UriIteratorState.Path);
|
||||
@@ -231,7 +277,7 @@ class TernarySearchTreeNode<K, V> {
|
||||
|
||||
export class TernarySearchTree<K, V> {
|
||||
|
||||
static forUris<E>(ignorePathCasing?: boolean): TernarySearchTree<URI, E> {
|
||||
static forUris<E>(ignorePathCasing: (key: URI) => boolean = () => false): TernarySearchTree<URI, E> {
|
||||
return new TernarySearchTree<URI, E>(new UriIterator(ignorePathCasing));
|
||||
}
|
||||
|
||||
@@ -243,6 +289,10 @@ export class TernarySearchTree<K, V> {
|
||||
return new TernarySearchTree<string, E>(new StringIterator());
|
||||
}
|
||||
|
||||
static forConfigKeys<E>(): TernarySearchTree<string, E> {
|
||||
return new TernarySearchTree<string, E>(new ConfigKeysIterator());
|
||||
}
|
||||
|
||||
private _iter: IKeyIterator<K>;
|
||||
private _root: TernarySearchTreeNode<K, V> | undefined;
|
||||
|
||||
@@ -301,6 +351,10 @@ export class TernarySearchTree<K, V> {
|
||||
}
|
||||
|
||||
get(key: K): V | undefined {
|
||||
return this._getNode(key)?.value;
|
||||
}
|
||||
|
||||
private _getNode(key: K) {
|
||||
const iter = this._iter.reset(key);
|
||||
let node = this._root;
|
||||
while (node) {
|
||||
@@ -319,7 +373,12 @@ export class TernarySearchTree<K, V> {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return node ? node.value : undefined;
|
||||
return node;
|
||||
}
|
||||
|
||||
has(key: K): boolean {
|
||||
const node = this._getNode(key);
|
||||
return !(node?.value === undefined && node?.mid === undefined);
|
||||
}
|
||||
|
||||
delete(key: K): void {
|
||||
@@ -352,11 +411,18 @@ export class TernarySearchTree<K, V> {
|
||||
stack.push([0, node]);
|
||||
node = node.mid;
|
||||
} else {
|
||||
// remove element
|
||||
node.value = undefined;
|
||||
if (superStr) {
|
||||
// remove children
|
||||
node.left = undefined;
|
||||
node.mid = undefined;
|
||||
node.right = undefined;
|
||||
} else {
|
||||
// remove element
|
||||
node.value = undefined;
|
||||
}
|
||||
|
||||
// clean up empty nodes
|
||||
while (stack.length > 0 && (node.isEmpty() || superStr)) {
|
||||
while (stack.length > 0 && node.isEmpty()) {
|
||||
let [dir, parent] = stack.pop()!;
|
||||
switch (dir) {
|
||||
case 1: parent.left = undefined; break;
|
||||
@@ -394,7 +460,7 @@ export class TernarySearchTree<K, V> {
|
||||
return node && node.value || candidate;
|
||||
}
|
||||
|
||||
findSuperstr(key: K): Iterator<V> | undefined {
|
||||
findSuperstr(key: K): IterableIterator<[K, V]> | undefined {
|
||||
const iter = this._iter.reset(key);
|
||||
let node = this._root;
|
||||
while (node) {
|
||||
@@ -414,7 +480,7 @@ export class TernarySearchTree<K, V> {
|
||||
if (!node.mid) {
|
||||
return undefined;
|
||||
} else {
|
||||
return this._values(node.mid);
|
||||
return this._entries(node.mid);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -431,12 +497,6 @@ export class TernarySearchTree<K, V> {
|
||||
yield* this._entries(this._root);
|
||||
}
|
||||
|
||||
private *_values(node: TernarySearchTreeNode<K, V>): IterableIterator<V> {
|
||||
for (const [, value] of this._entries(node)) {
|
||||
yield value;
|
||||
}
|
||||
}
|
||||
|
||||
private *_entries(node: TernarySearchTreeNode<K, V> | undefined): IterableIterator<[K, V]> {
|
||||
if (node) {
|
||||
// left
|
||||
|
||||
@@ -6,11 +6,11 @@
|
||||
"git": {
|
||||
"name": "marked",
|
||||
"repositoryUrl": "https://github.com/markedjs/marked",
|
||||
"commitHash": "529a8d4e185a8aa561e4d8d2891f8556b5717cd4"
|
||||
"commitHash": "8cfa29ccd2a2759e8e60fe0d8d6df8c022beda4e"
|
||||
}
|
||||
},
|
||||
"license": "MIT",
|
||||
"version": "0.6.2"
|
||||
"version": "1.1.0"
|
||||
}
|
||||
],
|
||||
"version": 1
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
(function (global, factory) {
|
||||
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
|
||||
typeof define === 'function' && define.amd ? define(factory) :
|
||||
(global = global || self, global.marked = factory());
|
||||
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.marked = factory());
|
||||
}(this, (function () { 'use strict';
|
||||
|
||||
function _defineProperties(target, props) {
|
||||
@@ -368,11 +368,28 @@
|
||||
|
||||
function checkSanitizeDeprecation(opt) {
|
||||
if (opt && opt.sanitize && !opt.silent) {
|
||||
// VS CODE CHANGE
|
||||
// Disable logging about sanitize options. We already use insane after running the sanitizer
|
||||
|
||||
// console.warn('marked(): sanitize and sanitizer parameters are deprecated since version 0.7.0, should not be used and will be removed in the future. Read more here: https://marked.js.org/#/USING_ADVANCED.md#options');
|
||||
console.warn('marked(): sanitize and sanitizer parameters are deprecated since version 0.7.0, should not be used and will be removed in the future. Read more here: https://marked.js.org/#/USING_ADVANCED.md#options');
|
||||
}
|
||||
} // copied from https://stackoverflow.com/a/5450113/806777
|
||||
|
||||
|
||||
function repeatString(pattern, count) {
|
||||
if (count < 1) {
|
||||
return '';
|
||||
}
|
||||
|
||||
var result = '';
|
||||
|
||||
while (count > 1) {
|
||||
if (count & 1) {
|
||||
result += pattern;
|
||||
}
|
||||
|
||||
count >>= 1;
|
||||
pattern += pattern;
|
||||
}
|
||||
|
||||
return result + pattern;
|
||||
}
|
||||
|
||||
var helpers = {
|
||||
@@ -386,7 +403,8 @@
|
||||
splitCells: splitCells,
|
||||
rtrim: rtrim,
|
||||
findClosingBracket: findClosingBracket,
|
||||
checkSanitizeDeprecation: checkSanitizeDeprecation
|
||||
checkSanitizeDeprecation: checkSanitizeDeprecation,
|
||||
repeatString: repeatString
|
||||
};
|
||||
|
||||
var defaults$1 = defaults.defaults;
|
||||
@@ -620,7 +638,7 @@
|
||||
// so it is seen as the next token.
|
||||
|
||||
space = item.length;
|
||||
item = item.replace(/^ *([*+-]|\d+[.)]) */, ''); // Outdent whatever the
|
||||
item = item.replace(/^ *([*+-]|\d+[.)]) ?/, ''); // Outdent whatever the
|
||||
// list item contains. Hacky.
|
||||
|
||||
if (~item.indexOf('\n ')) {
|
||||
@@ -1138,11 +1156,11 @@
|
||||
|
||||
block.gfm = merge$1({}, block.normal, {
|
||||
nptable: '^ *([^|\\n ].*\\|.*)\\n' // Header
|
||||
+ ' *([-:]+ *\\|[-| :]*)' // Align
|
||||
+ ' {0,3}([-:]+ *\\|[-| :]*)' // Align
|
||||
+ '(?:\\n((?:(?!\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)',
|
||||
// Cells
|
||||
table: '^ *\\|(.+)\\n' // Header
|
||||
+ ' *\\|?( *[-:]+[-| :]*)' // Align
|
||||
+ ' {0,3}\\|?( *[-:]+[-| :]*)' // Align
|
||||
+ '(?:\\n *((?:(?!\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)' // Cells
|
||||
|
||||
});
|
||||
@@ -1187,24 +1205,24 @@
|
||||
start: /^(?:(\*\*(?=[*punctuation]))|\*\*)(?![\s])|__/,
|
||||
// (1) returns if starts w/ punctuation
|
||||
middle: /^\*\*(?:(?:(?!overlapSkip)(?:[^*]|\\\*)|overlapSkip)|\*(?:(?!overlapSkip)(?:[^*]|\\\*)|overlapSkip)*?\*)+?\*\*$|^__(?![\s])((?:(?:(?!overlapSkip)(?:[^_]|\\_)|overlapSkip)|_(?:(?!overlapSkip)(?:[^_]|\\_)|overlapSkip)*?_)+?)__$/,
|
||||
endAst: /[^punctuation\s]\*\*(?!\*)|[punctuation]\*\*(?!\*)(?:(?=[punctuation\s]|$))/,
|
||||
endAst: /[^punctuation\s]\*\*(?!\*)|[punctuation]\*\*(?!\*)(?:(?=[punctuation_\s]|$))/,
|
||||
// last char can't be punct, or final * must also be followed by punct (or endline)
|
||||
endUnd: /[^\s]__(?!_)(?:(?=[punctuation\s])|$)/ // last char can't be a space, and final _ must preceed punct or \s (or endline)
|
||||
endUnd: /[^\s]__(?!_)(?:(?=[punctuation*\s])|$)/ // last char can't be a space, and final _ must preceed punct or \s (or endline)
|
||||
|
||||
},
|
||||
em: {
|
||||
start: /^(?:(\*(?=[punctuation]))|\*)(?![*\s])|_/,
|
||||
// (1) returns if starts w/ punctuation
|
||||
middle: /^\*(?:(?:(?!overlapSkip)(?:[^*]|\\\*)|overlapSkip)|\*(?:(?!overlapSkip)(?:[^*]|\\\*)|overlapSkip)*?\*)+?\*$|^_(?![_\s])(?:(?:(?!overlapSkip)(?:[^_]|\\_)|overlapSkip)|_(?:(?!overlapSkip)(?:[^_]|\\_)|overlapSkip)*?_)+?_$/,
|
||||
endAst: /[^punctuation\s]\*(?!\*)|[punctuation]\*(?!\*)(?:(?=[punctuation\s]|$))/,
|
||||
endAst: /[^punctuation\s]\*(?!\*)|[punctuation]\*(?!\*)(?:(?=[punctuation_\s]|$))/,
|
||||
// last char can't be punct, or final * must also be followed by punct (or endline)
|
||||
endUnd: /[^\s]_(?!_)(?:(?=[punctuation\s])|$)/ // last char can't be a space, and final _ must preceed punct or \s (or endline)
|
||||
endUnd: /[^\s]_(?!_)(?:(?=[punctuation*\s])|$)/ // last char can't be a space, and final _ must preceed punct or \s (or endline)
|
||||
|
||||
},
|
||||
code: /^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,
|
||||
br: /^( {2,}|\\)\n(?!\s*$)/,
|
||||
del: noopTest$1,
|
||||
text: /^(`+|[^`])(?:[\s\S]*?(?:(?=[\\<!\[`*]|\b_|$)|[^ ](?= {2,}\n))|(?= {2,}\n))/,
|
||||
text: /^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*]|\b_|$)|[^ ](?= {2,}\n)))/,
|
||||
punctuation: /^([\s*punctuation])/
|
||||
}; // list of punctuation marks from common mark spec
|
||||
// without * and _ to workaround cases with double emphasis
|
||||
@@ -1220,7 +1238,7 @@
|
||||
inline.em.endAst = edit$1(inline.em.endAst, 'g').replace(/punctuation/g, inline._punctuation).getRegex();
|
||||
inline.em.endUnd = edit$1(inline.em.endUnd, 'g').replace(/punctuation/g, inline._punctuation).getRegex();
|
||||
inline.strong.start = edit$1(inline.strong.start).replace(/punctuation/g, inline._punctuation).getRegex();
|
||||
inline.strong.middle = edit$1(inline.strong.middle).replace(/punctuation/g, inline._punctuation).replace(/blockSkip/g, inline._blockSkip).getRegex();
|
||||
inline.strong.middle = edit$1(inline.strong.middle).replace(/punctuation/g, inline._punctuation).replace(/overlapSkip/g, inline._overlapSkip).getRegex();
|
||||
inline.strong.endAst = edit$1(inline.strong.endAst, 'g').replace(/punctuation/g, inline._punctuation).getRegex();
|
||||
inline.strong.endUnd = edit$1(inline.strong.endUnd, 'g').replace(/punctuation/g, inline._punctuation).getRegex();
|
||||
inline.blockSkip = edit$1(inline._blockSkip, 'g').getRegex();
|
||||
@@ -1272,7 +1290,7 @@
|
||||
url: /^((?:ftp|https?):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/,
|
||||
_backpedal: /(?:[^?!.,:;*_~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_~)]+(?!$))+/,
|
||||
del: /^~+(?=\S)([\s\S]*?\S)~+/,
|
||||
text: /^(`+|[^`])(?:[\s\S]*?(?:(?=[\\<!\[`*~]|\b_|https?:\/\/|ftp:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@))|(?= {2,}\n|[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@))/
|
||||
text: /^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*~]|\b_|https?:\/\/|ftp:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@))|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@))/
|
||||
});
|
||||
inline.gfm.url = edit$1(inline.gfm.url, 'i').replace('email', inline.gfm._extended_email).getRegex();
|
||||
/**
|
||||
@@ -1291,6 +1309,7 @@
|
||||
var defaults$2 = defaults.defaults;
|
||||
var block$1 = rules.block,
|
||||
inline$1 = rules.inline;
|
||||
var repeatString$1 = helpers.repeatString;
|
||||
/**
|
||||
* smartypants text replacement
|
||||
*/
|
||||
@@ -1373,6 +1392,15 @@
|
||||
var lexer = new Lexer(options);
|
||||
return lexer.lex(src);
|
||||
}
|
||||
/**
|
||||
* Static Lex Inline Method
|
||||
*/
|
||||
;
|
||||
|
||||
Lexer.lexInline = function lexInline(src, options) {
|
||||
var lexer = new Lexer(options);
|
||||
return lexer.inlineTokens(src);
|
||||
}
|
||||
/**
|
||||
* Preprocessing
|
||||
*/
|
||||
@@ -1652,7 +1680,7 @@
|
||||
if (links.length > 0) {
|
||||
while ((match = this.tokenizer.rules.inline.reflinkSearch.exec(maskedSrc)) != null) {
|
||||
if (links.includes(match[0].slice(match[0].lastIndexOf('[') + 1, -1))) {
|
||||
maskedSrc = maskedSrc.slice(0, match.index) + '[' + 'a'.repeat(match[0].length - 2) + ']' + maskedSrc.slice(this.tokenizer.rules.inline.reflinkSearch.lastIndex);
|
||||
maskedSrc = maskedSrc.slice(0, match.index) + '[' + repeatString$1('a', match[0].length - 2) + ']' + maskedSrc.slice(this.tokenizer.rules.inline.reflinkSearch.lastIndex);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1660,7 +1688,7 @@
|
||||
|
||||
|
||||
while ((match = this.tokenizer.rules.inline.blockSkip.exec(maskedSrc)) != null) {
|
||||
maskedSrc = maskedSrc.slice(0, match.index) + '[' + 'a'.repeat(match[0].length - 2) + ']' + maskedSrc.slice(this.tokenizer.rules.inline.blockSkip.lastIndex);
|
||||
maskedSrc = maskedSrc.slice(0, match.index) + '[' + repeatString$1('a', match[0].length - 2) + ']' + maskedSrc.slice(this.tokenizer.rules.inline.blockSkip.lastIndex);
|
||||
}
|
||||
|
||||
while (src) {
|
||||
@@ -2073,6 +2101,15 @@
|
||||
var parser = new Parser(options);
|
||||
return parser.parse(tokens);
|
||||
}
|
||||
/**
|
||||
* Static Parse Inline Method
|
||||
*/
|
||||
;
|
||||
|
||||
Parser.parseInline = function parseInline(tokens, options) {
|
||||
var parser = new Parser(options);
|
||||
return parser.parseInline(tokens);
|
||||
}
|
||||
/**
|
||||
* Parse Loop
|
||||
*/
|
||||
@@ -2606,6 +2643,42 @@
|
||||
}
|
||||
}
|
||||
};
|
||||
/**
|
||||
* Parse Inline
|
||||
*/
|
||||
|
||||
|
||||
marked.parseInline = function (src, opt) {
|
||||
// throw error in case of non string input
|
||||
if (typeof src === 'undefined' || src === null) {
|
||||
throw new Error('marked.parseInline(): input parameter is undefined or null');
|
||||
}
|
||||
|
||||
if (typeof src !== 'string') {
|
||||
throw new Error('marked.parseInline(): input parameter is of type ' + Object.prototype.toString.call(src) + ', string expected');
|
||||
}
|
||||
|
||||
opt = merge$2({}, marked.defaults, opt || {});
|
||||
checkSanitizeDeprecation$1(opt);
|
||||
|
||||
try {
|
||||
var tokens = Lexer_1.lexInline(src, opt);
|
||||
|
||||
if (opt.walkTokens) {
|
||||
marked.walkTokens(tokens, opt.walkTokens);
|
||||
}
|
||||
|
||||
return Parser_1.parseInline(tokens, opt);
|
||||
} catch (e) {
|
||||
e.message += '\nPlease report this to https://github.com/markedjs/marked.';
|
||||
|
||||
if (opt.silent) {
|
||||
return '<p>An error occurred:</p><pre>' + escape$2(e.message + '', true) + '</pre>';
|
||||
}
|
||||
|
||||
throw e;
|
||||
}
|
||||
};
|
||||
/**
|
||||
* Expose
|
||||
*/
|
||||
|
||||
@@ -78,6 +78,12 @@ export namespace Schemas {
|
||||
* Scheme used for extension pages
|
||||
*/
|
||||
export const extension = 'extension';
|
||||
|
||||
/**
|
||||
* Scheme used as a replacement of `file` scheme to load
|
||||
* files with our custom protocol handler (desktop only).
|
||||
*/
|
||||
export const vscodeFileResource = 'vscode-file';
|
||||
}
|
||||
|
||||
class RemoteAuthoritiesImpl {
|
||||
@@ -133,6 +139,8 @@ export const RemoteAuthorities = new RemoteAuthoritiesImpl();
|
||||
|
||||
class FileAccessImpl {
|
||||
|
||||
private readonly FALLBACK_AUTHORITY = 'vscode-app';
|
||||
|
||||
/**
|
||||
* Returns a URI to use in contexts where the browser is responsible
|
||||
* for loading (e.g. fetch()) or when used within the DOM.
|
||||
@@ -144,13 +152,43 @@ class FileAccessImpl {
|
||||
asBrowserUri(uriOrModule: URI | string, moduleIdToUrl?: { toUrl(moduleId: string): string }): URI {
|
||||
const uri = this.toUri(uriOrModule, moduleIdToUrl);
|
||||
|
||||
// Handle remote URIs via `RemoteAuthorities`
|
||||
if (uri.scheme === Schemas.vscodeRemote) {
|
||||
return RemoteAuthorities.rewrite(uri);
|
||||
}
|
||||
|
||||
// Only convert the URI if we are in a native context and it has `file:` scheme
|
||||
if (platform.isElectronSandboxed && platform.isNative && uri.scheme === Schemas.file) {
|
||||
return this.toCodeFileUri(uri);
|
||||
}
|
||||
|
||||
return uri;
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO@bpasero remove me eventually when vscode-file is adopted everywhere
|
||||
*/
|
||||
_asCodeFileUri(uri: URI): URI;
|
||||
_asCodeFileUri(moduleId: string, moduleIdToUrl: { toUrl(moduleId: string): string }): URI;
|
||||
_asCodeFileUri(uriOrModule: URI | string, moduleIdToUrl?: { toUrl(moduleId: string): string }): URI {
|
||||
const uri = this.toUri(uriOrModule, moduleIdToUrl);
|
||||
|
||||
return this.toCodeFileUri(uri);
|
||||
}
|
||||
|
||||
private toCodeFileUri(uri: URI): URI {
|
||||
return uri.with({
|
||||
scheme: Schemas.vscodeFileResource,
|
||||
// We need to provide an authority here so that it can serve
|
||||
// as origin for network and loading matters in chromium.
|
||||
// If the URI is not coming with an authority already, we
|
||||
// add our own
|
||||
authority: uri.authority || this.FALLBACK_AUTHORITY,
|
||||
query: null,
|
||||
fragment: null
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the `file` URI to use in contexts where node.js
|
||||
* is responsible for loading.
|
||||
@@ -160,6 +198,19 @@ class FileAccessImpl {
|
||||
asFileUri(uriOrModule: URI | string, moduleIdToUrl?: { toUrl(moduleId: string): string }): URI {
|
||||
const uri = this.toUri(uriOrModule, moduleIdToUrl);
|
||||
|
||||
// Only convert the URI if it is `vscode-file:` scheme
|
||||
if (uri.scheme === Schemas.vscodeFileResource) {
|
||||
return uri.with({
|
||||
scheme: Schemas.file,
|
||||
// Only preserve the `authority` if it is different from
|
||||
// our fallback authority. This ensures we properly preserve
|
||||
// Windows UNC paths that come with their own authority.
|
||||
authority: uri.authority !== this.FALLBACK_AUTHORITY ? uri.authority : null,
|
||||
query: null,
|
||||
fragment: null
|
||||
});
|
||||
}
|
||||
|
||||
return uri;
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ function _factory(sharedObj) {
|
||||
sharedObj.MonacoPerformanceMarks = sharedObj.MonacoPerformanceMarks || [];
|
||||
|
||||
const _dataLen = 2;
|
||||
const _timeStamp = typeof console.timeStamp === 'function' ? console.timeStamp.bind(console) : () => { };
|
||||
const _nativeMark = typeof performance === 'object' && typeof performance.mark === 'function' ? performance.mark.bind(performance) : () => { };
|
||||
|
||||
function importEntries(entries) {
|
||||
sharedObj.MonacoPerformanceMarks.splice(0, 0, ...entries);
|
||||
@@ -55,7 +55,7 @@ function _factory(sharedObj) {
|
||||
|
||||
function mark(name) {
|
||||
sharedObj.MonacoPerformanceMarks.push(name, Date.now());
|
||||
_timeStamp(name);
|
||||
_nativeMark(name);
|
||||
}
|
||||
|
||||
const exports = {
|
||||
|
||||
@@ -33,8 +33,8 @@ export interface INodeProcess {
|
||||
versions?: {
|
||||
electron?: string;
|
||||
};
|
||||
sandboxed?: boolean; // Electron
|
||||
type?: string;
|
||||
getuid(): number;
|
||||
cwd(): string;
|
||||
}
|
||||
declare const process: INodeProcess;
|
||||
@@ -55,11 +55,12 @@ if (typeof process !== 'undefined') {
|
||||
// Native environment (non-sandboxed)
|
||||
nodeProcess = process;
|
||||
} else if (typeof _globals.vscode !== 'undefined') {
|
||||
// Native envionment (sandboxed)
|
||||
// Native environment (sandboxed)
|
||||
nodeProcess = _globals.vscode.process;
|
||||
}
|
||||
|
||||
const isElectronRenderer = typeof nodeProcess?.versions?.electron === 'string' && nodeProcess.type === 'renderer';
|
||||
export const isElectronSandboxed = isElectronRenderer && nodeProcess?.sandboxed;
|
||||
|
||||
// Web environment
|
||||
if (typeof navigator === 'object' && !isElectronRenderer) {
|
||||
@@ -145,10 +146,6 @@ export const isIOS = _isIOS;
|
||||
export const platform = _platform;
|
||||
export const userAgent = _userAgent;
|
||||
|
||||
export function isRootUser(): boolean {
|
||||
return !!nodeProcess && !_isWindows && (nodeProcess.getuid() === 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* The language used for the user interface. The format of
|
||||
* the string is all lower case (e.g. zh-tw for Traditional
|
||||
|
||||
@@ -16,7 +16,16 @@ if (typeof process !== 'undefined') {
|
||||
|
||||
// Native sandbox environment
|
||||
else if (typeof globals.vscode !== 'undefined') {
|
||||
safeProcess = globals.vscode.process;
|
||||
safeProcess = {
|
||||
|
||||
// Supported
|
||||
get platform(): 'win32' | 'linux' | 'darwin' { return globals.vscode.process.platform; },
|
||||
get env() { return globals.vscode.process.env; },
|
||||
nextTick(callback: (...args: any[]) => void): void { return setImmediate(callback); },
|
||||
|
||||
// Unsupported
|
||||
cwd(): string { return globals.vscode.process.env['VSCODE_CWD'] || globals.vscode.process.execPath.substr(0, globals.vscode.process.execPath.lastIndexOf(globals.vscode.process.platform === 'win32' ? '\\' : '/')); }
|
||||
};
|
||||
}
|
||||
|
||||
// Web environment
|
||||
@@ -29,8 +38,7 @@ else {
|
||||
|
||||
// Unsupported
|
||||
get env() { return Object.create(null); },
|
||||
cwd(): string { return '/'; },
|
||||
getuid(): number { return -1; }
|
||||
cwd(): string { return '/'; }
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
import { memoize } from 'vs/base/common/decorators';
|
||||
import * as paths from 'vs/base/common/path';
|
||||
import { relativePath, joinPath } from 'vs/base/common/resources';
|
||||
import { IExtUri, extUri as defaultExtUri } from 'vs/base/common/resources';
|
||||
import { URI } from 'vs/base/common/uri';
|
||||
import { PathIterator } from 'vs/base/common/map';
|
||||
|
||||
@@ -95,12 +95,12 @@ export class ResourceTree<T extends NonNullable<any>, C> {
|
||||
return obj instanceof Node;
|
||||
}
|
||||
|
||||
constructor(context: C, rootURI: URI = URI.file('/')) {
|
||||
constructor(context: C, rootURI: URI = URI.file('/'), private extUri: IExtUri = defaultExtUri) {
|
||||
this.root = new Node(rootURI, '', context);
|
||||
}
|
||||
|
||||
add(uri: URI, element: T): void {
|
||||
const key = relativePath(this.root.uri, uri) || uri.fsPath;
|
||||
const key = this.extUri.relativePath(this.root.uri, uri) || uri.path;
|
||||
const iterator = new PathIterator(false).reset(key);
|
||||
let node = this.root;
|
||||
let path = '';
|
||||
@@ -113,7 +113,7 @@ export class ResourceTree<T extends NonNullable<any>, C> {
|
||||
|
||||
if (!child) {
|
||||
child = new Node(
|
||||
joinPath(this.root.uri, path),
|
||||
this.extUri.joinPath(this.root.uri, path),
|
||||
path,
|
||||
this.root.context,
|
||||
iterator.hasNext() ? undefined : element,
|
||||
@@ -136,7 +136,7 @@ export class ResourceTree<T extends NonNullable<any>, C> {
|
||||
}
|
||||
|
||||
delete(uri: URI): T | undefined {
|
||||
const key = relativePath(this.root.uri, uri) || uri.fsPath;
|
||||
const key = this.extUri.relativePath(this.root.uri, uri) || uri.path;
|
||||
const iterator = new PathIterator(false).reset(key);
|
||||
return this._delete(this.root, iterator);
|
||||
}
|
||||
@@ -168,7 +168,7 @@ export class ResourceTree<T extends NonNullable<any>, C> {
|
||||
}
|
||||
|
||||
getNode(uri: URI): IResourceNode<T, C> | undefined {
|
||||
const key = relativePath(this.root.uri, uri) || uri.fsPath;
|
||||
const key = this.extUri.relativePath(this.root.uri, uri) || uri.path;
|
||||
const iterator = new PathIterator(false).reset(key);
|
||||
let node = this.root;
|
||||
|
||||
|
||||
@@ -10,8 +10,6 @@ import { equalsIgnoreCase, compare as strCompare } from 'vs/base/common/strings'
|
||||
import { Schemas } from 'vs/base/common/network';
|
||||
import { isWindows, isLinux } from 'vs/base/common/platform';
|
||||
import { CharCode } from 'vs/base/common/charCode';
|
||||
import { ParsedExpression, IExpression, parse } from 'vs/base/common/glob';
|
||||
import { TernarySearchTree } from 'vs/base/common/map';
|
||||
|
||||
export function originalFSPath(uri: URI): string {
|
||||
return uriToFsPath(uri, true);
|
||||
@@ -58,6 +56,11 @@ export interface IExtUri {
|
||||
*/
|
||||
getComparisonKey(uri: URI, ignoreFragment?: boolean): string;
|
||||
|
||||
/**
|
||||
* Whether the casing of the path-component of the uri should be ignored.
|
||||
*/
|
||||
ignorePathCasing(uri: URI): boolean;
|
||||
|
||||
// --- path math
|
||||
|
||||
basenameOrAuthority(resource: URI): string;
|
||||
@@ -161,6 +164,10 @@ export class ExtUri implements IExtUri {
|
||||
}).toString();
|
||||
}
|
||||
|
||||
ignorePathCasing(uri: URI): boolean {
|
||||
return this._ignorePathCasing(uri);
|
||||
}
|
||||
|
||||
isEqualOrParent(base: URI, parentCandidate: URI, ignoreFragment: boolean = false): boolean {
|
||||
if (base.scheme === parentCandidate.scheme) {
|
||||
if (base.scheme === Schemas.file) {
|
||||
@@ -427,33 +434,6 @@ export namespace DataUri {
|
||||
}
|
||||
}
|
||||
|
||||
export class ResourceGlobMatcher {
|
||||
|
||||
private readonly globalExpression: ParsedExpression;
|
||||
private readonly expressionsByRoot: TernarySearchTree<URI, { root: URI, expression: ParsedExpression }> = TernarySearchTree.forUris<{ root: URI, expression: ParsedExpression }>();
|
||||
|
||||
constructor(
|
||||
globalExpression: IExpression,
|
||||
rootExpressions: { root: URI, expression: IExpression }[]
|
||||
) {
|
||||
this.globalExpression = parse(globalExpression);
|
||||
for (const expression of rootExpressions) {
|
||||
this.expressionsByRoot.set(expression.root, { root: expression.root, expression: parse(expression.expression) });
|
||||
}
|
||||
}
|
||||
|
||||
matches(resource: URI): boolean {
|
||||
const rootExpression = this.expressionsByRoot.findSubstr(resource);
|
||||
if (rootExpression) {
|
||||
const path = relativePath(rootExpression.root, resource);
|
||||
if (path && !!rootExpression.expression(path)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return !!this.globalExpression(resource.path);
|
||||
}
|
||||
}
|
||||
|
||||
export function toLocalResource(resource: URI, authority: string | undefined, localScheme: string): URI {
|
||||
if (authority) {
|
||||
let path = resource.path;
|
||||
|
||||
@@ -69,6 +69,14 @@ export function count(value: string, character: string): number {
|
||||
return result;
|
||||
}
|
||||
|
||||
export function truncate(value: string, maxLength: number, suffix = '…'): string {
|
||||
if (value.length <= maxLength) {
|
||||
return value;
|
||||
}
|
||||
|
||||
return `${value.substr(0, maxLength)}${suffix}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes all occurrences of needle from the beginning and end of haystack.
|
||||
* @param haystack string to trim
|
||||
@@ -208,6 +216,10 @@ export function regExpFlags(regexp: RegExp): string {
|
||||
+ ((regexp as any /* standalone editor compilation */).unicode ? 'u' : '');
|
||||
}
|
||||
|
||||
export function splitLines(str: string): string[] {
|
||||
return str.split(/\r\n|\r|\n/);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns first index of the string that is not whitespace.
|
||||
* If string is empty or contains only whitespaces, returns -1
|
||||
@@ -879,9 +891,15 @@ export function getNLines(str: string, n = 1): string {
|
||||
n--;
|
||||
} while (n > 0 && idx >= 0);
|
||||
|
||||
return idx >= 0 ?
|
||||
str.substr(0, idx) :
|
||||
str;
|
||||
if (idx === -1) {
|
||||
return str;
|
||||
}
|
||||
|
||||
if (str[idx - 1] === '\r') {
|
||||
idx--;
|
||||
}
|
||||
|
||||
return str.substr(0, idx);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -345,7 +345,7 @@ export class URI implements UriComponents {
|
||||
*/
|
||||
static joinPath(uri: URI, ...pathFragment: string[]): URI {
|
||||
if (!uri.path) {
|
||||
throw new Error(`[UriError]: cannot call joinPaths on URI without path`);
|
||||
throw new Error(`[UriError]: cannot call joinPath on URI without path`);
|
||||
}
|
||||
let newPath: string;
|
||||
if (isWindows && uri.scheme === 'file') {
|
||||
|
||||
@@ -17,8 +17,9 @@ for (let i = 0; i < 256; i++) {
|
||||
_hex.push(i.toString(16).padStart(2, '0'));
|
||||
}
|
||||
|
||||
// todo@joh node nodejs use `crypto#randomBytes`, see: https://nodejs.org/docs/latest/api/crypto.html#crypto_crypto_randombytes_size_callback
|
||||
// todo@joh use browser-crypto
|
||||
// todo@jrieken
|
||||
// 1. node nodejs use`crypto#randomBytes`, see: https://nodejs.org/docs/latest/api/crypto.html#crypto_crypto_randombytes_size_callback
|
||||
// 2. use browser-crypto
|
||||
const _fillRandomValues = function (bucket: Uint8Array): Uint8Array {
|
||||
for (let i = 0; i < bucket.length; i++) {
|
||||
bucket[i] = Math.floor(Math.random() * 256);
|
||||
|
||||
@@ -358,6 +358,10 @@ export class SimpleWorkerServer<H extends object> {
|
||||
delete loaderConfig.paths['vs'];
|
||||
}
|
||||
}
|
||||
if (typeof loaderConfig.trustedTypesPolicy !== undefined) {
|
||||
// don't use, it has been destroyed during serialize
|
||||
delete loaderConfig['trustedTypesPolicy'];
|
||||
}
|
||||
|
||||
// Since this is in a web worker, enable catching errors
|
||||
loaderConfig.catchError = true;
|
||||
|
||||
Reference in New Issue
Block a user