@lvce-editor/extension-host-worker 1.4.1 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/extensionHostWorkerMain.js +113 -109
- package/package.json +1 -1
|
@@ -1451,88 +1451,6 @@ const getPathSeparator = protocol => {
|
|
|
1451
1451
|
}
|
|
1452
1452
|
};
|
|
1453
1453
|
|
|
1454
|
-
const webViews = Object.create(null);
|
|
1455
|
-
const webViewProviders = Object.create(null);
|
|
1456
|
-
const getProvider = providerId => {
|
|
1457
|
-
return webViewProviders[providerId];
|
|
1458
|
-
};
|
|
1459
|
-
const setProvider = (providerId, provider) => {
|
|
1460
|
-
webViewProviders[providerId] = provider;
|
|
1461
|
-
};
|
|
1462
|
-
const getWebView = id => {
|
|
1463
|
-
return webViews[id];
|
|
1464
|
-
};
|
|
1465
|
-
const setWebView = (id, webView) => {
|
|
1466
|
-
webViews[id] = webView;
|
|
1467
|
-
};
|
|
1468
|
-
|
|
1469
|
-
// TODO pass uuid to allow having multiple webviews open at the same time
|
|
1470
|
-
const createWebView = async (providerId, port, uri, uid, origin) => {
|
|
1471
|
-
const provider = getProvider(providerId);
|
|
1472
|
-
if (!provider) {
|
|
1473
|
-
throw new Error(`webview provider ${providerId} not found`);
|
|
1474
|
-
}
|
|
1475
|
-
|
|
1476
|
-
// TODO cancel promise when webview is disposed before sending message
|
|
1477
|
-
// TODO handle case when webview doesn't send ready message
|
|
1478
|
-
// TODO handle error
|
|
1479
|
-
await new Promise(resolve => {
|
|
1480
|
-
port.onmessage = resolve;
|
|
1481
|
-
});
|
|
1482
|
-
|
|
1483
|
-
// TODO use ipc module
|
|
1484
|
-
const handlePortMessage = async event => {
|
|
1485
|
-
const {
|
|
1486
|
-
data,
|
|
1487
|
-
target
|
|
1488
|
-
} = event;
|
|
1489
|
-
const {
|
|
1490
|
-
method,
|
|
1491
|
-
params,
|
|
1492
|
-
id
|
|
1493
|
-
} = data;
|
|
1494
|
-
if (provider && provider.commands && provider.commands[method]) {
|
|
1495
|
-
const fn = provider.commands[method];
|
|
1496
|
-
const result = await fn(...params);
|
|
1497
|
-
if (id) {
|
|
1498
|
-
target.postMessage({
|
|
1499
|
-
jsonrpc: '2.0',
|
|
1500
|
-
id,
|
|
1501
|
-
result
|
|
1502
|
-
});
|
|
1503
|
-
}
|
|
1504
|
-
}
|
|
1505
|
-
};
|
|
1506
|
-
port.onmessage = handlePortMessage;
|
|
1507
|
-
const rpc = {
|
|
1508
|
-
uri,
|
|
1509
|
-
provider,
|
|
1510
|
-
uid,
|
|
1511
|
-
origin,
|
|
1512
|
-
invoke(method, ...params) {
|
|
1513
|
-
// TODO return promise with result
|
|
1514
|
-
port.postMessage({
|
|
1515
|
-
jsonrpc: '2.0',
|
|
1516
|
-
method,
|
|
1517
|
-
params
|
|
1518
|
-
});
|
|
1519
|
-
}
|
|
1520
|
-
};
|
|
1521
|
-
// TODO allow creating multiple webviews per provider
|
|
1522
|
-
setWebView(providerId, rpc);
|
|
1523
|
-
};
|
|
1524
|
-
const load = async providerId => {
|
|
1525
|
-
const rpc = getWebView(providerId);
|
|
1526
|
-
await rpc.provider.create(rpc, rpc.uri);
|
|
1527
|
-
};
|
|
1528
|
-
const disposeWebView = id => {
|
|
1529
|
-
// TODO race condition
|
|
1530
|
-
// const webView=webViews[id]
|
|
1531
|
-
};
|
|
1532
|
-
const registerWebViewProvider = provider => {
|
|
1533
|
-
setProvider(provider.id, provider);
|
|
1534
|
-
};
|
|
1535
|
-
|
|
1536
1454
|
const {
|
|
1537
1455
|
registerFormattingProvider,
|
|
1538
1456
|
executeFormattingProvider,
|
|
@@ -2080,32 +1998,6 @@ const {
|
|
|
2080
1998
|
}
|
|
2081
1999
|
});
|
|
2082
2000
|
|
|
2083
|
-
const createWorker = async ({
|
|
2084
|
-
method,
|
|
2085
|
-
url,
|
|
2086
|
-
name
|
|
2087
|
-
}) => {
|
|
2088
|
-
string(method);
|
|
2089
|
-
string(url);
|
|
2090
|
-
string(name);
|
|
2091
|
-
const ipc = create$7({
|
|
2092
|
-
method: ModuleWorkerAndWorkaroundForChromeDevtoolsBug$1,
|
|
2093
|
-
url,
|
|
2094
|
-
name
|
|
2095
|
-
});
|
|
2096
|
-
return ipc;
|
|
2097
|
-
};
|
|
2098
|
-
|
|
2099
|
-
const state$1 = {
|
|
2100
|
-
workspacePath: ''
|
|
2101
|
-
};
|
|
2102
|
-
const setWorkspacePath = path => {
|
|
2103
|
-
state$1.workspacePath = path;
|
|
2104
|
-
};
|
|
2105
|
-
const getWorkspaceFolder = path => {
|
|
2106
|
-
return state$1.workspacePath;
|
|
2107
|
-
};
|
|
2108
|
-
|
|
2109
2001
|
const RE_PROTOCOL = /^([a-z\-]+):\/\//;
|
|
2110
2002
|
const getProtocol = uri => {
|
|
2111
2003
|
const protocolMatch = uri.match(RE_PROTOCOL);
|
|
@@ -2168,6 +2060,21 @@ const createWebViewIpc = async webView => {
|
|
|
2168
2060
|
return ipc;
|
|
2169
2061
|
};
|
|
2170
2062
|
|
|
2063
|
+
const webViews = Object.create(null);
|
|
2064
|
+
const webViewProviders = Object.create(null);
|
|
2065
|
+
const getProvider = providerId => {
|
|
2066
|
+
return webViewProviders[providerId];
|
|
2067
|
+
};
|
|
2068
|
+
const setProvider = (providerId, provider) => {
|
|
2069
|
+
webViewProviders[providerId] = provider;
|
|
2070
|
+
};
|
|
2071
|
+
const getWebView = id => {
|
|
2072
|
+
return webViews[id];
|
|
2073
|
+
};
|
|
2074
|
+
const setWebView = (id, webView) => {
|
|
2075
|
+
webViews[id] = webView;
|
|
2076
|
+
};
|
|
2077
|
+
|
|
2171
2078
|
// TODO if webViewId is provided,
|
|
2172
2079
|
// 1. read file as blob
|
|
2173
2080
|
// 2. send blob to webview
|
|
@@ -2228,6 +2135,99 @@ const getRemoteUrl = async (uri, options = {}) => {
|
|
|
2228
2135
|
throw new Error(`unsupported platform for remote url`);
|
|
2229
2136
|
};
|
|
2230
2137
|
|
|
2138
|
+
// TODO pass uuid to allow having multiple webviews open at the same time
|
|
2139
|
+
const createWebView = async (providerId, port, uri, uid, origin) => {
|
|
2140
|
+
const provider = getProvider(providerId);
|
|
2141
|
+
if (!provider) {
|
|
2142
|
+
throw new Error(`webview provider ${providerId} not found`);
|
|
2143
|
+
}
|
|
2144
|
+
|
|
2145
|
+
// TODO cancel promise when webview is disposed before sending message
|
|
2146
|
+
// TODO handle case when webview doesn't send ready message
|
|
2147
|
+
// TODO handle error
|
|
2148
|
+
await new Promise(resolve => {
|
|
2149
|
+
port.onmessage = resolve;
|
|
2150
|
+
});
|
|
2151
|
+
|
|
2152
|
+
// TODO use ipc module
|
|
2153
|
+
const handlePortMessage = async event => {
|
|
2154
|
+
const {
|
|
2155
|
+
data,
|
|
2156
|
+
target
|
|
2157
|
+
} = event;
|
|
2158
|
+
const {
|
|
2159
|
+
method,
|
|
2160
|
+
params,
|
|
2161
|
+
id
|
|
2162
|
+
} = data;
|
|
2163
|
+
if (provider && provider.commands && provider.commands[method]) {
|
|
2164
|
+
const fn = provider.commands[method];
|
|
2165
|
+
const result = await fn(...params);
|
|
2166
|
+
if (id) {
|
|
2167
|
+
target.postMessage({
|
|
2168
|
+
jsonrpc: '2.0',
|
|
2169
|
+
id,
|
|
2170
|
+
result
|
|
2171
|
+
});
|
|
2172
|
+
}
|
|
2173
|
+
}
|
|
2174
|
+
};
|
|
2175
|
+
port.onmessage = handlePortMessage;
|
|
2176
|
+
const rpc = {
|
|
2177
|
+
uri,
|
|
2178
|
+
provider,
|
|
2179
|
+
uid,
|
|
2180
|
+
origin,
|
|
2181
|
+
invoke(method, ...params) {
|
|
2182
|
+
// TODO return promise with result
|
|
2183
|
+
port.postMessage({
|
|
2184
|
+
jsonrpc: '2.0',
|
|
2185
|
+
method,
|
|
2186
|
+
params
|
|
2187
|
+
});
|
|
2188
|
+
}
|
|
2189
|
+
};
|
|
2190
|
+
// TODO allow creating multiple webviews per provider
|
|
2191
|
+
setWebView(providerId, rpc);
|
|
2192
|
+
};
|
|
2193
|
+
const load = async providerId => {
|
|
2194
|
+
const rpc = getWebView(providerId);
|
|
2195
|
+
await rpc.provider.create(rpc, rpc.uri);
|
|
2196
|
+
};
|
|
2197
|
+
const disposeWebView = id => {
|
|
2198
|
+
// TODO race condition
|
|
2199
|
+
// const webView=webViews[id]
|
|
2200
|
+
};
|
|
2201
|
+
const registerWebViewProvider = provider => {
|
|
2202
|
+
setProvider(provider.id, provider);
|
|
2203
|
+
};
|
|
2204
|
+
|
|
2205
|
+
const createWorker = async ({
|
|
2206
|
+
method,
|
|
2207
|
+
url,
|
|
2208
|
+
name
|
|
2209
|
+
}) => {
|
|
2210
|
+
string(method);
|
|
2211
|
+
string(url);
|
|
2212
|
+
string(name);
|
|
2213
|
+
const ipc = create$7({
|
|
2214
|
+
method: ModuleWorkerAndWorkaroundForChromeDevtoolsBug$1,
|
|
2215
|
+
url,
|
|
2216
|
+
name
|
|
2217
|
+
});
|
|
2218
|
+
return ipc;
|
|
2219
|
+
};
|
|
2220
|
+
|
|
2221
|
+
const state$1 = {
|
|
2222
|
+
workspacePath: ''
|
|
2223
|
+
};
|
|
2224
|
+
const setWorkspacePath = path => {
|
|
2225
|
+
state$1.workspacePath = path;
|
|
2226
|
+
};
|
|
2227
|
+
const getWorkspaceFolder = path => {
|
|
2228
|
+
return state$1.workspacePath;
|
|
2229
|
+
};
|
|
2230
|
+
|
|
2231
2231
|
class FormattingError extends Error {
|
|
2232
2232
|
constructor(message, codeFrame) {
|
|
2233
2233
|
super(message);
|
|
@@ -2286,6 +2286,7 @@ const api = {
|
|
|
2286
2286
|
// File System
|
|
2287
2287
|
registerFileSystemProvider: registerFileSystemProvider,
|
|
2288
2288
|
readFile: readFileExternal,
|
|
2289
|
+
readDirWithFileType: readDirWithFileTypes,
|
|
2289
2290
|
// Formatting
|
|
2290
2291
|
registerFormattingProvider: registerFormattingProvider,
|
|
2291
2292
|
executeFormattingProvider: executeFormattingProvider,
|
|
@@ -2412,7 +2413,10 @@ const getUrlPrefix = extensionPath => {
|
|
|
2412
2413
|
if (platform === Web) {
|
|
2413
2414
|
return extensionPath;
|
|
2414
2415
|
}
|
|
2415
|
-
|
|
2416
|
+
if (extensionPath.startsWith('/')) {
|
|
2417
|
+
return `/remote${extensionPath}`;
|
|
2418
|
+
}
|
|
2419
|
+
return `/remote/${extensionPath}`;
|
|
2416
2420
|
};
|
|
2417
2421
|
|
|
2418
2422
|
const handleRpcInfos = extension => {
|
package/package.json
CHANGED