mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-03-18 11:03:18 -04:00
Vscode merge (#4582)
* Merge from vscode 37cb23d3dd4f9433d56d4ba5ea3203580719a0bd * fix issues with merges * bump node version in azpipe * replace license headers * remove duplicate launch task * fix build errors * fix build errors * fix tslint issues * working through package and linux build issues * more work * wip * fix packaged builds * working through linux build errors * wip * wip * wip * fix mac and linux file limits * iterate linux pipeline * disable editor typing * revert series to parallel * remove optimize vscode from linux * fix linting issues * revert testing change * add work round for new node * readd packaging for extensions * fix issue with angular not resolving decorator dependencies
This commit is contained in:
@@ -3,12 +3,15 @@
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import * as paths from 'vs/base/common/paths';
|
||||
import * as extpath from 'vs/base/common/extpath';
|
||||
import * as paths from 'vs/base/common/path';
|
||||
import { URI } from 'vs/base/common/uri';
|
||||
import { equalsIgnoreCase } from 'vs/base/common/strings';
|
||||
import { Schemas } from 'vs/base/common/network';
|
||||
import { isLinux, isWindows } 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 getComparisonKey(resource: URI): string {
|
||||
return hasToIgnoreCase(resource) ? resource.toString().toLowerCase() : resource.toString();
|
||||
@@ -32,22 +35,24 @@ export function basenameOrAuthority(resource: URI): string {
|
||||
export function isEqualOrParent(base: URI, parentCandidate: URI, ignoreCase = hasToIgnoreCase(base)): boolean {
|
||||
if (base.scheme === parentCandidate.scheme) {
|
||||
if (base.scheme === Schemas.file) {
|
||||
return paths.isEqualOrParent(fsPath(base), fsPath(parentCandidate), ignoreCase);
|
||||
return extpath.isEqualOrParent(originalFSPath(base), originalFSPath(parentCandidate), ignoreCase);
|
||||
}
|
||||
if (isEqualAuthority(base.authority, parentCandidate.authority, ignoreCase)) {
|
||||
return paths.isEqualOrParent(base.path, parentCandidate.path, ignoreCase, '/');
|
||||
if (isEqualAuthority(base.authority, parentCandidate.authority)) {
|
||||
return extpath.isEqualOrParent(base.path, parentCandidate.path, ignoreCase, '/');
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function isEqualAuthority(a1: string, a2: string, ignoreCase?: boolean) {
|
||||
return a1 === a2 || ignoreCase && a1 && a2 && equalsIgnoreCase(a1, a2);
|
||||
/**
|
||||
* Tests wheter the two authorities are the same
|
||||
*/
|
||||
export function isEqualAuthority(a1: string, a2: string) {
|
||||
return a1 === a2 || equalsIgnoreCase(a1, a2);
|
||||
}
|
||||
|
||||
export function isEqual(first: URI | undefined, second: URI | undefined, ignoreCase = hasToIgnoreCase(first)): boolean {
|
||||
const identityEquals = (first === second);
|
||||
if (identityEquals) {
|
||||
if (first === second) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -55,15 +60,20 @@ export function isEqual(first: URI | undefined, second: URI | undefined, ignoreC
|
||||
return false;
|
||||
}
|
||||
|
||||
if (ignoreCase) {
|
||||
return equalsIgnoreCase(first.toString(), second.toString());
|
||||
if (first.scheme !== second.scheme || !isEqualAuthority(first.authority, second.authority)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return first.toString() === second.toString();
|
||||
const p1 = first.path || '/', p2 = second.path || '/';
|
||||
return p1 === p2 || ignoreCase && equalsIgnoreCase(p1 || '/', p2 || '/');
|
||||
}
|
||||
|
||||
export function basename(resource: URI): string {
|
||||
return paths.basename(resource.path);
|
||||
return paths.posix.basename(resource.path);
|
||||
}
|
||||
|
||||
export function extname(resource: URI): string {
|
||||
return paths.posix.extname(resource.path);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -72,16 +82,17 @@ export function basename(resource: URI): string {
|
||||
* @param resource The input URI.
|
||||
* @returns The URI representing the directory of the input URI.
|
||||
*/
|
||||
export function dirname(resource: URI): URI | null {
|
||||
export function dirname(resource: URI): URI {
|
||||
if (resource.path.length === 0) {
|
||||
return resource;
|
||||
}
|
||||
if (resource.scheme === Schemas.file) {
|
||||
return URI.file(paths.dirname(fsPath(resource)));
|
||||
return URI.file(paths.dirname(originalFSPath(resource)));
|
||||
}
|
||||
let dirname = paths.dirname(resource.path, '/');
|
||||
let dirname = paths.posix.dirname(resource.path);
|
||||
if (resource.authority && dirname.length && dirname.charCodeAt(0) !== CharCode.Slash) {
|
||||
return null; // If a URI contains an authority component, then the path component must either be empty or begin with a CharCode.Slash ("/") character
|
||||
console.error(`dirname("${resource.toString})) resulted in a relative path`);
|
||||
dirname = '/'; // If a URI contains an authority component, then the path component must either be empty or begin with a CharCode.Slash ("/") character
|
||||
}
|
||||
return resource.with({
|
||||
path: dirname
|
||||
@@ -89,18 +100,18 @@ export function dirname(resource: URI): URI | null {
|
||||
}
|
||||
|
||||
/**
|
||||
* Join a URI path with a path fragment and normalizes the resulting path.
|
||||
* Join a URI path with path fragments and normalizes the resulting path.
|
||||
*
|
||||
* @param resource The input URI.
|
||||
* @param pathFragment The path fragment to add to the URI path.
|
||||
* @returns The resulting URI.
|
||||
*/
|
||||
export function joinPath(resource: URI, pathFragment: string): URI {
|
||||
export function joinPath(resource: URI, ...pathFragment: string[]): URI {
|
||||
let joinedPath: string;
|
||||
if (resource.scheme === Schemas.file) {
|
||||
joinedPath = URI.file(paths.join(fsPath(resource), pathFragment)).path;
|
||||
joinedPath = URI.file(paths.join(originalFSPath(resource), ...pathFragment)).path;
|
||||
} else {
|
||||
joinedPath = paths.join(resource.path, pathFragment);
|
||||
joinedPath = paths.posix.join(resource.path || '/', ...pathFragment);
|
||||
}
|
||||
return resource.with({
|
||||
path: joinedPath
|
||||
@@ -119,9 +130,9 @@ export function normalizePath(resource: URI): URI {
|
||||
}
|
||||
let normalizedPath: string;
|
||||
if (resource.scheme === Schemas.file) {
|
||||
normalizedPath = URI.file(paths.normalize(fsPath(resource))).path;
|
||||
normalizedPath = URI.file(paths.normalize(originalFSPath(resource))).path;
|
||||
} else {
|
||||
normalizedPath = paths.normalize(resource.path);
|
||||
normalizedPath = paths.posix.normalize(resource.path);
|
||||
}
|
||||
return resource.with({
|
||||
path: normalizedPath
|
||||
@@ -132,7 +143,7 @@ export function normalizePath(resource: URI): URI {
|
||||
* Returns the fsPath of an URI where the drive letter is not normalized.
|
||||
* See #56403.
|
||||
*/
|
||||
export function fsPath(uri: URI): string {
|
||||
export function originalFSPath(uri: URI): string {
|
||||
let value: string;
|
||||
const uriPath = uri.path;
|
||||
if (uri.authority && uriPath.length > 1 && uri.scheme === 'file') {
|
||||
@@ -141,7 +152,7 @@ export function fsPath(uri: URI): string {
|
||||
} else if (
|
||||
isWindows
|
||||
&& uriPath.charCodeAt(0) === CharCode.Slash
|
||||
&& paths.isWindowsDriveLetter(uriPath.charCodeAt(1))
|
||||
&& extpath.isWindowsDriveLetter(uriPath.charCodeAt(1))
|
||||
&& uriPath.charCodeAt(2) === CharCode.Colon
|
||||
) {
|
||||
value = uriPath.substr(1);
|
||||
@@ -159,7 +170,64 @@ export function fsPath(uri: URI): string {
|
||||
* Returns true if the URI path is absolute.
|
||||
*/
|
||||
export function isAbsolutePath(resource: URI): boolean {
|
||||
return paths.isAbsolute(resource.path);
|
||||
return !!resource.path && resource.path[0] === '/';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the URI path has a trailing path separator
|
||||
*/
|
||||
export function hasTrailingPathSeparator(resource: URI): boolean {
|
||||
if (resource.scheme === Schemas.file) {
|
||||
const fsp = originalFSPath(resource);
|
||||
return fsp.length > extpath.getRoot(fsp).length && fsp[fsp.length - 1] === paths.sep;
|
||||
} else {
|
||||
const p = resource.path;
|
||||
return p.length > 1 && p.charCodeAt(p.length - 1) === CharCode.Slash; // ignore the slash at offset 0
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Removes a trailing path seperator, if theres one.
|
||||
* Important: Doesn't remove the first slash, it would make the URI invalid
|
||||
*/
|
||||
export function removeTrailingPathSeparator(resource: URI): URI {
|
||||
if (hasTrailingPathSeparator(resource)) {
|
||||
return resource.with({ path: resource.path.substr(0, resource.path.length - 1) });
|
||||
}
|
||||
return resource;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns a relative path between two URIs. If the URIs don't have the same schema or authority, `undefined` is returned.
|
||||
* The returned relative path always uses forward slashes.
|
||||
*/
|
||||
export function relativePath(from: URI, to: URI): string | undefined {
|
||||
if (from.scheme !== to.scheme || !isEqualAuthority(from.authority, to.authority)) {
|
||||
return undefined;
|
||||
}
|
||||
if (from.scheme === Schemas.file) {
|
||||
const relativePath = paths.relative(from.path, to.path);
|
||||
return isWindows ? extpath.toSlashes(relativePath) : relativePath;
|
||||
}
|
||||
return paths.posix.relative(from.path || '/', to.path || '/');
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolves a absolute or relative path against a base URI.
|
||||
*/
|
||||
export function resolvePath(base: URI, path: string): URI {
|
||||
if (base.scheme === Schemas.file) {
|
||||
const newURI = URI.file(paths.resolve(originalFSPath(base), path));
|
||||
return base.with({
|
||||
authority: newURI.authority,
|
||||
path: newURI.path
|
||||
});
|
||||
}
|
||||
return base.with({
|
||||
path: paths.posix.resolve(base.path, path)
|
||||
});
|
||||
}
|
||||
|
||||
export function distinctParents<T>(items: T[], resourceAccessor: (item: T) => URI): T[] {
|
||||
@@ -182,21 +250,6 @@ export function distinctParents<T>(items: T[], resourceAccessor: (item: T) => UR
|
||||
return distinctParents;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests whether the given URL is a file URI created by `URI.parse` instead of `URI.file`.
|
||||
* Such URI have no scheme or scheme that consist of a single letter (windows drive letter)
|
||||
* @param candidate The URI to test
|
||||
* @returns A corrected, real file URI if the input seems to be malformed.
|
||||
* Undefined is returned if the input URI looks fine.
|
||||
*/
|
||||
export function isMalformedFileUri(candidate: URI): URI | undefined {
|
||||
if (!candidate.scheme || isWindows && candidate.scheme.match(/^[a-zA-Z]$/)) {
|
||||
return URI.file((candidate.scheme ? candidate.scheme + ':' : '') + candidate.path);
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Data URI related helpers.
|
||||
*/
|
||||
@@ -230,3 +283,31 @@ export namespace DataUri {
|
||||
return metadata;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export class ResourceGlobMatcher {
|
||||
|
||||
private readonly globalExpression: ParsedExpression;
|
||||
private readonly expressionsByRoot: TernarySearchTree<{ root: URI, expression: ParsedExpression }> = TernarySearchTree.forPaths<{ 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.toString(), { root: expression.root, expression: parse(expression.expression) });
|
||||
}
|
||||
}
|
||||
|
||||
matches(resource: URI): boolean {
|
||||
const rootExpression = this.expressionsByRoot.findSubstr(resource.toString());
|
||||
if (rootExpression) {
|
||||
const path = relativePath(rootExpression.root, resource);
|
||||
if (path && !!rootExpression.expression(path)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return !!this.globalExpression(resource.path);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user