mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 18:46:40 -05:00
Refresh master with initial release/0.24 snapshot (#332)
* Initial port of release/0.24 source code * Fix additional headers * Fix a typo in launch.json
This commit is contained in:
@@ -16,6 +16,11 @@ export interface IExpression {
|
||||
[pattern: string]: boolean | SiblingClause | any;
|
||||
}
|
||||
|
||||
export interface IRelativePattern {
|
||||
base: string;
|
||||
pattern: string;
|
||||
}
|
||||
|
||||
export function getEmptyExpression(): IExpression {
|
||||
return Object.create(null);
|
||||
}
|
||||
@@ -28,6 +33,8 @@ export interface SiblingClause {
|
||||
when: string;
|
||||
}
|
||||
|
||||
const GLOBSTAR = '**';
|
||||
const GLOB_SPLIT = '/';
|
||||
const PATH_REGEX = '[/\\\\]'; // any slash or backslash
|
||||
const NO_PATH_REGEX = '[^/\\\\]'; // any non-slash and non-backslash
|
||||
const ALL_FORWARD_SLASHES = /\//g;
|
||||
@@ -103,10 +110,10 @@ function parseRegExp(pattern: string): string {
|
||||
let regEx = '';
|
||||
|
||||
// Split up into segments for each slash found
|
||||
let segments = splitGlobAware(pattern, '/');
|
||||
let segments = splitGlobAware(pattern, GLOB_SPLIT);
|
||||
|
||||
// Special case where we only have globstars
|
||||
if (segments.every(s => s === '**')) {
|
||||
if (segments.every(s => s === GLOBSTAR)) {
|
||||
regEx = '.*';
|
||||
}
|
||||
|
||||
@@ -116,7 +123,7 @@ function parseRegExp(pattern: string): string {
|
||||
segments.forEach((segment, index) => {
|
||||
|
||||
// Globstar is special
|
||||
if (segment === '**') {
|
||||
if (segment === GLOBSTAR) {
|
||||
|
||||
// if we have more than one globstar after another, just ignore it
|
||||
if (!previousSegmentWasGlobStar) {
|
||||
@@ -207,7 +214,7 @@ function parseRegExp(pattern: string): string {
|
||||
}
|
||||
|
||||
// Tail: Add the slash we had split on if there is more to come and the next one is not a globstar
|
||||
if (index < segments.length - 1 && segments[index + 1] !== '**') {
|
||||
if (index < segments.length - 1 && segments[index + 1] !== GLOBSTAR) {
|
||||
regEx += PATH_REGEX;
|
||||
}
|
||||
|
||||
@@ -264,11 +271,19 @@ const NULL = function (): string {
|
||||
return null;
|
||||
};
|
||||
|
||||
function parsePattern(pattern: string, options: IGlobOptions): ParsedStringPattern {
|
||||
if (!pattern) {
|
||||
function parsePattern(arg1: string | IRelativePattern, options: IGlobOptions): ParsedStringPattern {
|
||||
if (!arg1) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Handle IRelativePattern
|
||||
let pattern: string;
|
||||
if (typeof arg1 !== 'string') {
|
||||
pattern = arg1.pattern;
|
||||
} else {
|
||||
pattern = arg1;
|
||||
}
|
||||
|
||||
// Whitespace trimming
|
||||
pattern = pattern.trim();
|
||||
|
||||
@@ -276,7 +291,7 @@ function parsePattern(pattern: string, options: IGlobOptions): ParsedStringPatte
|
||||
const patternKey = `${pattern}_${!!options.trimForExclusions}`;
|
||||
let parsedPattern = CACHE.get(patternKey);
|
||||
if (parsedPattern) {
|
||||
return parsedPattern;
|
||||
return wrapRelativePattern(parsedPattern, arg1);
|
||||
}
|
||||
|
||||
// Check for Trivias
|
||||
@@ -304,7 +319,21 @@ function parsePattern(pattern: string, options: IGlobOptions): ParsedStringPatte
|
||||
// Cache
|
||||
CACHE.set(patternKey, parsedPattern);
|
||||
|
||||
return parsedPattern;
|
||||
return wrapRelativePattern(parsedPattern, arg1);
|
||||
}
|
||||
|
||||
function wrapRelativePattern(parsedPattern: ParsedStringPattern, arg2: string | IRelativePattern): ParsedStringPattern {
|
||||
if (typeof arg2 === 'string') {
|
||||
return parsedPattern;
|
||||
}
|
||||
|
||||
return function (path, basename) {
|
||||
if (!paths.isEqualOrParent(path, arg2.base)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return parsedPattern(paths.relative(arg2.base, path), basename);
|
||||
};
|
||||
}
|
||||
|
||||
function trimForExclusions(pattern: string, options: IGlobOptions): string {
|
||||
@@ -395,9 +424,9 @@ function toRegExp(pattern: string): ParsedStringPattern {
|
||||
* - simple brace expansion ({js,ts} => js or ts)
|
||||
* - character ranges (using [...])
|
||||
*/
|
||||
export function match(pattern: string, path: string): boolean;
|
||||
export function match(pattern: string | IRelativePattern, path: string): boolean;
|
||||
export function match(expression: IExpression, path: string, siblingsFn?: () => string[]): string /* the matching pattern */;
|
||||
export function match(arg1: string | IExpression, path: string, siblingsFn?: () => string[]): any {
|
||||
export function match(arg1: string | IExpression | IRelativePattern, path: string, siblingsFn?: () => string[]): any {
|
||||
if (!arg1 || !path) {
|
||||
return false;
|
||||
}
|
||||
@@ -413,16 +442,16 @@ export function match(arg1: string | IExpression, path: string, siblingsFn?: ()
|
||||
* - simple brace expansion ({js,ts} => js or ts)
|
||||
* - character ranges (using [...])
|
||||
*/
|
||||
export function parse(pattern: string, options?: IGlobOptions): ParsedPattern;
|
||||
export function parse(pattern: string | IRelativePattern, options?: IGlobOptions): ParsedPattern;
|
||||
export function parse(expression: IExpression, options?: IGlobOptions): ParsedExpression;
|
||||
export function parse(arg1: string | IExpression, options: IGlobOptions = {}): any {
|
||||
export function parse(arg1: string | IExpression | IRelativePattern, options: IGlobOptions = {}): any {
|
||||
if (!arg1) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// Glob with String
|
||||
if (typeof arg1 === 'string') {
|
||||
const parsedPattern = parsePattern(arg1, options);
|
||||
if (typeof arg1 === 'string' || isRelativePattern(arg1)) {
|
||||
const parsedPattern = parsePattern(arg1 as string | IRelativePattern, options);
|
||||
if (parsedPattern === NULL) {
|
||||
return FALSE;
|
||||
}
|
||||
@@ -442,6 +471,12 @@ export function parse(arg1: string | IExpression, options: IGlobOptions = {}): a
|
||||
return parsedExpression(<IExpression>arg1, options);
|
||||
}
|
||||
|
||||
function isRelativePattern(obj: any): obj is IRelativePattern {
|
||||
const rp = obj as IRelativePattern;
|
||||
|
||||
return typeof rp.base === 'string' && typeof rp.pattern === 'string';
|
||||
}
|
||||
|
||||
/**
|
||||
* Same as `parse`, but the ParsedExpression is guaranteed to return a Promise
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user