mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-05 01:25:38 -05:00
Merge from vscode a348d103d1256a06a2c9b3f9b406298a9fef6898 (#15681)
* Merge from vscode a348d103d1256a06a2c9b3f9b406298a9fef6898 * Fixes and cleanup * Distro * Fix hygiene yarn * delete no yarn lock changes file * Fix hygiene * Fix layer check * Fix CI * Skip lib checks * Remove tests deleted in vs code * Fix tests * Distro * Fix tests and add removed extension point * Skip failing notebook tests for now * Disable broken tests and cleanup build folder * Update yarn.lock and fix smoke tests * Bump sqlite * fix contributed actions and file spacing * Fix user data path * Update yarn.locks Co-authored-by: ADS Merger <karlb@microsoft.com>
This commit is contained in:
@@ -1,218 +0,0 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { VSBufferReadableStream } from 'vs/base/common/buffer';
|
||||
import { CancellationToken } from 'vs/base/common/cancellation';
|
||||
import { isUNC } from 'vs/base/common/extpath';
|
||||
import { Schemas } from 'vs/base/common/network';
|
||||
import { sep } from 'vs/base/common/path';
|
||||
import { URI } from 'vs/base/common/uri';
|
||||
import { IHeaders } from 'vs/base/parts/request/common/request';
|
||||
import { FileOperationError, FileOperationResult, IFileService } from 'vs/platform/files/common/files';
|
||||
import { ILogService } from 'vs/platform/log/common/log';
|
||||
import { IRemoteConnectionData } from 'vs/platform/remote/common/remoteAuthorityResolver';
|
||||
import { IRequestService } from 'vs/platform/request/common/request';
|
||||
import { getWebviewContentMimeType } from 'vs/platform/webview/common/mimeTypes';
|
||||
|
||||
|
||||
export const webviewPartitionId = 'webview';
|
||||
|
||||
export namespace WebviewResourceResponse {
|
||||
export enum Type { Success, Failed, AccessDenied, NotModified }
|
||||
|
||||
export class StreamSuccess {
|
||||
readonly type = Type.Success;
|
||||
|
||||
constructor(
|
||||
public readonly stream: VSBufferReadableStream,
|
||||
public readonly etag: string | undefined,
|
||||
public readonly mimeType: string,
|
||||
) { }
|
||||
}
|
||||
|
||||
export const Failed = { type: Type.Failed } as const;
|
||||
export const AccessDenied = { type: Type.AccessDenied } as const;
|
||||
|
||||
export class NotModified {
|
||||
readonly type = Type.NotModified;
|
||||
|
||||
constructor(
|
||||
public readonly mimeType: string,
|
||||
) { }
|
||||
}
|
||||
|
||||
export type StreamResponse = StreamSuccess | typeof Failed | typeof AccessDenied | NotModified;
|
||||
}
|
||||
|
||||
export namespace WebviewFileReadResponse {
|
||||
export enum Type { Success, NotModified }
|
||||
|
||||
export class StreamSuccess {
|
||||
readonly type = Type.Success;
|
||||
|
||||
constructor(
|
||||
public readonly stream: VSBufferReadableStream,
|
||||
public readonly etag: string | undefined
|
||||
) { }
|
||||
}
|
||||
|
||||
export const NotModified = { type: Type.NotModified } as const;
|
||||
|
||||
export type Response = StreamSuccess | typeof NotModified;
|
||||
}
|
||||
|
||||
/**
|
||||
* Wraps a call to `IFileService.readFileStream` and converts the result to a `WebviewFileReadResponse.Response`
|
||||
*/
|
||||
export async function readFileStream(
|
||||
fileService: IFileService,
|
||||
resource: URI,
|
||||
etag: string | undefined,
|
||||
): Promise<WebviewFileReadResponse.Response> {
|
||||
try {
|
||||
const result = await fileService.readFileStream(resource, { etag });
|
||||
return new WebviewFileReadResponse.StreamSuccess(result.value, result.etag);
|
||||
} catch (e) {
|
||||
if (e instanceof FileOperationError) {
|
||||
const result = e.fileOperationResult;
|
||||
|
||||
// NotModified status is expected and can be handled gracefully
|
||||
if (result === FileOperationResult.FILE_NOT_MODIFIED_SINCE) {
|
||||
return WebviewFileReadResponse.NotModified;
|
||||
}
|
||||
}
|
||||
|
||||
// Otherwise the error is unexpected. Re-throw and let caller handle it
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
export interface WebviewResourceFileReader {
|
||||
readFileStream(resource: URI, etag: string | undefined): Promise<WebviewFileReadResponse.Response>;
|
||||
}
|
||||
|
||||
export async function loadLocalResource(
|
||||
requestUri: URI,
|
||||
ifNoneMatch: string | undefined,
|
||||
options: {
|
||||
extensionLocation: URI | undefined;
|
||||
roots: ReadonlyArray<URI>;
|
||||
remoteConnectionData?: IRemoteConnectionData | null;
|
||||
rewriteUri?: (uri: URI) => URI,
|
||||
},
|
||||
fileReader: WebviewResourceFileReader,
|
||||
requestService: IRequestService,
|
||||
logService: ILogService,
|
||||
token: CancellationToken,
|
||||
): Promise<WebviewResourceResponse.StreamResponse> {
|
||||
logService.debug(`loadLocalResource - being. requestUri=${requestUri}`);
|
||||
|
||||
let resourceToLoad = getResourceToLoad(requestUri, options.roots);
|
||||
|
||||
logService.debug(`loadLocalResource - found resource to load. requestUri=${requestUri}, resourceToLoad=${resourceToLoad}`);
|
||||
|
||||
if (!resourceToLoad) {
|
||||
return WebviewResourceResponse.AccessDenied;
|
||||
}
|
||||
|
||||
const mime = getWebviewContentMimeType(requestUri); // Use the original path for the mime
|
||||
|
||||
// Perform extra normalization if needed
|
||||
if (options.rewriteUri) {
|
||||
resourceToLoad = options.rewriteUri(resourceToLoad);
|
||||
}
|
||||
|
||||
if (resourceToLoad.scheme === Schemas.http || resourceToLoad.scheme === Schemas.https) {
|
||||
const headers: IHeaders = {};
|
||||
if (ifNoneMatch) {
|
||||
headers['If-None-Match'] = ifNoneMatch;
|
||||
}
|
||||
|
||||
const response = await requestService.request({
|
||||
url: resourceToLoad.toString(true),
|
||||
headers: headers
|
||||
}, token);
|
||||
|
||||
logService.debug(`loadLocalResource - Loaded over http(s). requestUri=${requestUri}, response=${response.res.statusCode}`);
|
||||
|
||||
if (response.res.statusCode === 200) {
|
||||
return new WebviewResourceResponse.StreamSuccess(response.stream, response.res.headers['etag'], mime);
|
||||
}
|
||||
return WebviewResourceResponse.Failed;
|
||||
}
|
||||
|
||||
try {
|
||||
const contents = await fileReader.readFileStream(resourceToLoad, ifNoneMatch);
|
||||
logService.debug(`loadLocalResource - Loaded using fileReader. requestUri=${requestUri}`);
|
||||
|
||||
switch (contents.type) {
|
||||
case WebviewFileReadResponse.Type.Success:
|
||||
return new WebviewResourceResponse.StreamSuccess(contents.stream, contents.etag, mime);
|
||||
|
||||
case WebviewFileReadResponse.Type.NotModified:
|
||||
return new WebviewResourceResponse.NotModified(mime);
|
||||
|
||||
default:
|
||||
logService.error(`loadLocalResource - Unknown file read response`);
|
||||
return WebviewResourceResponse.Failed;
|
||||
}
|
||||
} catch (err) {
|
||||
logService.debug(`loadLocalResource - Error using fileReader. requestUri=${requestUri}`);
|
||||
console.log(err);
|
||||
|
||||
return WebviewResourceResponse.Failed;
|
||||
}
|
||||
}
|
||||
|
||||
function getResourceToLoad(
|
||||
requestUri: URI,
|
||||
roots: ReadonlyArray<URI>
|
||||
): URI | undefined {
|
||||
const normalizedPath = normalizeRequestPath(requestUri);
|
||||
|
||||
for (const root of roots) {
|
||||
if (containsResource(root, normalizedPath)) {
|
||||
return normalizedPath;
|
||||
}
|
||||
}
|
||||
|
||||
return undefined;
|
||||
}
|
||||
|
||||
function normalizeRequestPath(requestUri: URI) {
|
||||
if (requestUri.scheme === Schemas.vscodeWebviewResource) {
|
||||
// The `vscode-webview-resource` scheme has the following format:
|
||||
//
|
||||
// vscode-webview-resource://id/scheme//authority?/path
|
||||
//
|
||||
|
||||
// Encode requestUri.path so that URI.parse can properly parse special characters like '#', '?', etc.
|
||||
const resourceUri = URI.parse(encodeURIComponent(requestUri.path).replace(/%2F/gi, '/').replace(/^\/([a-z0-9\-]+)(\/{1,2})/i, (_: string, scheme: string, sep: string) => {
|
||||
if (sep.length === 1) {
|
||||
return `${scheme}:///`; // Add empty authority.
|
||||
} else {
|
||||
return `${scheme}://`; // Url has own authority.
|
||||
}
|
||||
}));
|
||||
return resourceUri.with({
|
||||
query: requestUri.query,
|
||||
fragment: requestUri.fragment
|
||||
});
|
||||
} else {
|
||||
return requestUri;
|
||||
}
|
||||
}
|
||||
|
||||
function containsResource(root: URI, resource: URI): boolean {
|
||||
let rootPath = root.fsPath + (root.fsPath.endsWith(sep) ? '' : sep);
|
||||
let resourceFsPath = resource.fsPath;
|
||||
|
||||
if (isUNC(root.fsPath) && isUNC(resource.fsPath)) {
|
||||
rootPath = rootPath.toLowerCase();
|
||||
resourceFsPath = resourceFsPath.toLowerCase();
|
||||
}
|
||||
|
||||
return resourceFsPath.startsWith(rootPath);
|
||||
}
|
||||
@@ -3,14 +3,12 @@
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { VSBuffer } from 'vs/base/common/buffer';
|
||||
import { UriComponents } from 'vs/base/common/uri';
|
||||
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
|
||||
import { IRemoteConnectionData } from 'vs/platform/remote/common/remoteAuthorityResolver';
|
||||
import { IWebviewPortMapping } from 'vs/platform/webview/common/webviewPortMapping';
|
||||
|
||||
export const IWebviewManagerService = createDecorator<IWebviewManagerService>('webviewManagerService');
|
||||
|
||||
export const webviewPartitionId = 'webview';
|
||||
|
||||
export interface WebviewWebContentsId {
|
||||
readonly webContentsId: number;
|
||||
}
|
||||
@@ -19,27 +17,8 @@ export interface WebviewWindowId {
|
||||
readonly windowId: number;
|
||||
}
|
||||
|
||||
export type WebviewManagerDidLoadResourceResponse =
|
||||
{ buffer: VSBuffer, etag: string | undefined }
|
||||
| 'not-modified'
|
||||
| 'access-denied'
|
||||
| 'not-found';
|
||||
|
||||
export interface IWebviewManagerService {
|
||||
_serviceBrand: unknown;
|
||||
|
||||
registerWebview(id: string, windowId: number, metadata: RegisterWebviewMetadata): Promise<void>;
|
||||
unregisterWebview(id: string): Promise<void>;
|
||||
updateWebviewMetadata(id: string, metadataDelta: Partial<RegisterWebviewMetadata>): Promise<void>;
|
||||
|
||||
didLoadResource(requestId: number, response: WebviewManagerDidLoadResourceResponse): void;
|
||||
|
||||
setIgnoreMenuShortcuts(id: WebviewWebContentsId | WebviewWindowId, enabled: boolean): Promise<void>;
|
||||
}
|
||||
|
||||
export interface RegisterWebviewMetadata {
|
||||
readonly extensionLocation: UriComponents | undefined;
|
||||
readonly localResourceRoots: readonly UriComponents[];
|
||||
readonly remoteConnectionData: IRemoteConnectionData | null;
|
||||
readonly portMappings: readonly IWebviewPortMapping[];
|
||||
}
|
||||
|
||||
@@ -10,8 +10,8 @@ import { IAddress } from 'vs/platform/remote/common/remoteAgentConnection';
|
||||
import { extractLocalHostUriMetaDataForPortMapping, ITunnelService, RemoteTunnel } from 'vs/platform/remote/common/tunnel';
|
||||
|
||||
export interface IWebviewPortMapping {
|
||||
webviewPort: number;
|
||||
extensionHostPort: number;
|
||||
readonly webviewPort: number;
|
||||
readonly extensionHostPort: number;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user