mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-09 09:42:34 -05: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:
@@ -6,7 +6,7 @@
|
||||
import { globals } from 'vs/base/common/platform';
|
||||
import { IWorker, IWorkerCallback, IWorkerFactory, logOnceWebWorkerWarning } from 'vs/base/common/worker/simpleWorker';
|
||||
|
||||
function getWorker(workerId: string, label: string): Worker {
|
||||
function getWorker(workerId: string, label: string): Worker | Promise<Worker> {
|
||||
// Option for hosts to overwrite the worker script (used in the standalone editor)
|
||||
if (globals.MonacoEnvironment) {
|
||||
if (typeof globals.MonacoEnvironment.getWorker === 'function') {
|
||||
@@ -18,12 +18,34 @@ function getWorker(workerId: string, label: string): Worker {
|
||||
}
|
||||
// ESM-comment-begin
|
||||
if (typeof require === 'function') {
|
||||
return new Worker(require.toUrl('./' + workerId) + '#' + label);
|
||||
// check if the JS lives on a different origin
|
||||
|
||||
const workerMain = require.toUrl('./' + workerId);
|
||||
if (/^(http:)|(https:)|(file:)/.test(workerMain)) {
|
||||
const currentUrl = String(window.location);
|
||||
const currentOrigin = currentUrl.substr(0, currentUrl.length - window.location.hash.length - window.location.search.length - window.location.pathname.length);
|
||||
if (workerMain.substring(0, currentOrigin.length) !== currentOrigin) {
|
||||
// this is the cross-origin case
|
||||
// i.e. the webpage is running at a different origin than where the scripts are loaded from
|
||||
const workerBaseUrl = workerMain.substr(0, workerMain.length - 'vs/base/worker/workerMain.js'.length);
|
||||
const js = `/*${label}*/self.MonacoEnvironment={baseUrl: '${workerBaseUrl}'};importScripts('${workerMain}');/*${label}*/`;
|
||||
const url = `data:text/javascript;charset=utf-8,${encodeURIComponent(js)}`;
|
||||
return new Worker(url);
|
||||
}
|
||||
}
|
||||
return new Worker(workerMain + '#' + label);
|
||||
}
|
||||
// ESM-comment-end
|
||||
throw new Error(`You must define a function MonacoEnvironment.getWorkerUrl or MonacoEnvironment.getWorker`);
|
||||
}
|
||||
|
||||
function isPromiseLike<T>(obj: any): obj is PromiseLike<T> {
|
||||
if (typeof obj.then === 'function') {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* A worker that uses HTML5 web workers so that is has
|
||||
* its own global scope and its own thread.
|
||||
@@ -31,18 +53,26 @@ function getWorker(workerId: string, label: string): Worker {
|
||||
class WebWorker implements IWorker {
|
||||
|
||||
private id: number;
|
||||
private worker: Worker | null;
|
||||
private worker: Promise<Worker> | null;
|
||||
|
||||
constructor(moduleId: string, id: number, label: string, onMessageCallback: IWorkerCallback, onErrorCallback: (err: any) => void) {
|
||||
this.id = id;
|
||||
this.worker = getWorker('workerMain.js', label);
|
||||
this.postMessage(moduleId);
|
||||
this.worker.onmessage = function (ev: any) {
|
||||
onMessageCallback(ev.data);
|
||||
};
|
||||
if (typeof this.worker.addEventListener === 'function') {
|
||||
this.worker.addEventListener('error', onErrorCallback);
|
||||
const workerOrPromise = getWorker('workerMain.js', label);
|
||||
if (isPromiseLike(workerOrPromise)) {
|
||||
this.worker = workerOrPromise;
|
||||
} else {
|
||||
this.worker = Promise.resolve(workerOrPromise);
|
||||
}
|
||||
this.postMessage(moduleId);
|
||||
this.worker.then((w) => {
|
||||
w.onmessage = function (ev: any) {
|
||||
onMessageCallback(ev.data);
|
||||
};
|
||||
(<any>w).onmessageerror = onErrorCallback;
|
||||
if (typeof w.addEventListener === 'function') {
|
||||
w.addEventListener('error', onErrorCallback);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public getId(): number {
|
||||
@@ -51,13 +81,13 @@ class WebWorker implements IWorker {
|
||||
|
||||
public postMessage(msg: string): void {
|
||||
if (this.worker) {
|
||||
this.worker.postMessage(msg);
|
||||
this.worker.then(w => w.postMessage(msg));
|
||||
}
|
||||
}
|
||||
|
||||
public dispose(): void {
|
||||
if (this.worker) {
|
||||
this.worker.terminate();
|
||||
this.worker.then(w => w.terminate());
|
||||
}
|
||||
this.worker = null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user