@lvce-editor/extension-management-worker 4.83.2 → 4.84.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.
@@ -3943,14 +3943,20 @@ const executeExtensionDiagnosticProvider = async (rpc, extension, textDocument,
3943
3943
  const executeMatchingDiagnosticProvider = async (extension, textDocument, args, assetDir, platform, resultPort, providerIndex) => {
3944
3944
  const providerId = extension.id ?? extension.uri ?? extension.path ?? String(providerIndex);
3945
3945
  let diagnostics = [];
3946
+ let providerError;
3946
3947
  try {
3947
3948
  const rpc = await getRpc$1(extension, assetDir, platform, `onDiagnostic:${textDocument.languageId}`);
3948
3949
  diagnostics = await executeExtensionDiagnosticProvider(rpc, extension, textDocument, args);
3949
- } catch {
3950
- // A failing provider should not prevent results from other providers from being delivered.
3950
+ } catch (error) {
3951
+ // Preserve failure information for callers waiting for a successful diagnostics pass.
3952
+ // Other providers still deliver their results.
3953
+ providerError = error instanceof Error ? error.message : String(error);
3951
3954
  }
3952
3955
  resultPort?.postMessage({
3953
3956
  diagnostics,
3957
+ ...(providerError !== undefined && {
3958
+ error: providerError
3959
+ }),
3954
3960
  providerId,
3955
3961
  providerIndex,
3956
3962
  type: 'result'
@@ -4898,11 +4904,12 @@ const hasView = (extension, viewId) => {
4898
4904
  const hasOnlyViewAndCommandActivations = extension => {
4899
4905
  return Array.isArray(extension.activation) && extension.activation.length > 0 && extension.activation.every(event => event.startsWith('onView:') || event.startsWith('onCommand:'));
4900
4906
  };
4907
+ const pendingViewCreations = new WeakMap();
4901
4908
  const hasOtherViewInstances = rpc => {
4902
4909
  return getEntries().some(entry => entry.instance.status === 'ready' && entry.instance.rpc === rpc);
4903
4910
  };
4904
4911
  const disposeViewOnlyExtensionWorker = async (extensionId, rpc) => {
4905
- if (hasOtherViewInstances(rpc)) {
4912
+ if (pendingViewCreations.has(rpc) || hasOtherViewInstances(rpc)) {
4906
4913
  return;
4907
4914
  }
4908
4915
  if (get$2(extensionId) !== rpc) {
@@ -4918,7 +4925,7 @@ const getExtensionForView = async (viewId, assetDir, platform, applicationId) =>
4918
4925
  }
4919
4926
  return extension;
4920
4927
  };
4921
- const getRpcForView = async (viewId, assetDir, platform, applicationId) => {
4928
+ const getRpcForView = async (viewId, assetDir, platform, applicationId, retain) => {
4922
4929
  const {
4923
4930
  assetDir: resolvedAssetDir,
4924
4931
  platform: resolvedPlatform
@@ -4928,22 +4935,26 @@ const getRpcForView = async (viewId, assetDir, platform, applicationId) => {
4928
4935
  const existingRpc = get$2(extensionId, applicationId);
4929
4936
  // Application teardown and reload own application workers; global view-only disposal does not.
4930
4937
  if (existingRpc) {
4931
- return {
4938
+ const worker = {
4932
4939
  disposeWorkerWhenLastViewCloses: applicationId === undefined && hasOnlyViewAndCommandActivations(extension),
4933
4940
  extensionId,
4934
4941
  rpc: existingRpc
4935
4942
  };
4943
+ retain?.(worker);
4944
+ return worker;
4936
4945
  }
4937
4946
  const activationResult = await activateByEvent(`onView:${viewId}`, resolvedAssetDir, resolvedPlatform, get$7(applicationId));
4938
4947
  if (activationResult.error) {
4939
4948
  throw activationResult.error;
4940
4949
  }
4941
4950
  const rpc = await getRpc$1(extension, resolvedAssetDir, resolvedPlatform);
4942
- return {
4951
+ const worker = {
4943
4952
  disposeWorkerWhenLastViewCloses: applicationId === undefined && hasOnlyViewAndCommandActivations(extension),
4944
4953
  extensionId,
4945
4954
  rpc
4946
4955
  };
4956
+ retain?.(worker);
4957
+ return worker;
4947
4958
  };
4948
4959
  const getRpcForInstance = async (viewId, uid, assetDir, platform) => {
4949
4960
  const instance = get$1(uid);
@@ -4972,12 +4983,18 @@ const getViewMetadata = async (rpc, viewId) => {
4972
4983
  };
4973
4984
  };
4974
4985
  const createViewInstance = async (viewId, uid, context, assetDir, platform, applicationId) => {
4986
+ let retainedWorker;
4987
+ const retain = worker => {
4988
+ retainedWorker = worker;
4989
+ pendingViewCreations.set(worker.rpc, (pendingViewCreations.get(worker.rpc) || 0) + 1);
4990
+ };
4975
4991
  try {
4992
+ // Retain at selection time, before yielding the RPC to the caller.
4976
4993
  const {
4977
4994
  disposeWorkerWhenLastViewCloses,
4978
4995
  extensionId,
4979
4996
  rpc
4980
- } = await getRpcForView(viewId, assetDir, platform, applicationId);
4997
+ } = await getRpcForView(viewId, assetDir, platform, applicationId, retain);
4981
4998
  const {
4982
4999
  eventListeners,
4983
5000
  stateful
@@ -5015,6 +5032,24 @@ const createViewInstance = async (viewId, uid, context, assetDir, platform, appl
5015
5032
  error: serializedError,
5016
5033
  ok: false
5017
5034
  };
5035
+ } finally {
5036
+ if (retainedWorker) {
5037
+ const {
5038
+ disposeWorkerWhenLastViewCloses,
5039
+ extensionId,
5040
+ rpc
5041
+ } = retainedWorker;
5042
+ const remaining = (pendingViewCreations.get(rpc) || 1) - 1;
5043
+ if (remaining) {
5044
+ pendingViewCreations.set(rpc, remaining);
5045
+ } else {
5046
+ pendingViewCreations.delete(rpc);
5047
+ }
5048
+ // Failed creations must also release a worker kept alive by an overlapping close.
5049
+ if (disposeWorkerWhenLastViewCloses) {
5050
+ await disposeViewOnlyExtensionWorker(extensionId, rpc);
5051
+ }
5052
+ }
5018
5053
  }
5019
5054
  };
5020
5055
  const dispatchViewEvent = async (viewId, uid, event, assetDir, platform) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/extension-management-worker",
3
- "version": "4.83.2",
3
+ "version": "4.84.0",
4
4
  "description": "Webworker for the Extension Management functionality in Lvce Editor.",
5
5
  "keywords": [
6
6
  "web-worker"