@volar/language-service 2.4.30 → 2.4.31

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.
@@ -45,10 +45,19 @@ function register(context) {
45
45
  }
46
46
  }
47
47
  }
48
+ // The formatted copy is generated by the plugin of the document itself, not routed like a new script.
49
+ // Its ID differs only in the fragment, so a plugin that routes or names files by path sees the same file,
50
+ // while one that caches virtual codes by ID does not overwrite the document's own.
51
+ const { languagePlugin } = sourceScript.generated;
52
+ const tempId = sourceScript.id.with({ fragment: 'volar-formatting' });
53
+ const codegenCtx = {
54
+ getAssociatedScript: id => context.language.scripts.get(id),
55
+ };
56
+ let tempVirtualFile;
48
57
  try {
49
58
  const originalDocument = document;
50
59
  let tempSourceSnapshot = sourceScript.snapshot;
51
- let tempVirtualFile = context.language.scripts.set(vscode_uri_1.URI.parse(sourceScript.id.toString() + '.tmp'), sourceScript.snapshot, sourceScript.languageId, [sourceScript.generated.languagePlugin])?.generated?.root;
60
+ tempVirtualFile = languagePlugin.createVirtualCode?.(tempId, sourceScript.languageId, tempSourceSnapshot, codegenCtx);
52
61
  if (!tempVirtualFile) {
53
62
  return;
54
63
  }
@@ -108,8 +117,12 @@ function register(context) {
108
117
  const newText = vscode_languageserver_textdocument_1.TextDocument.applyEdits(document, edits);
109
118
  document = vscode_languageserver_textdocument_1.TextDocument.create(document.uri, document.languageId, document.version + 1, newText);
110
119
  tempSourceSnapshot = (0, common_1.stringToSnapshot)(newText);
111
- tempVirtualFile = context.language.scripts.set(vscode_uri_1.URI.parse(sourceScript.id.toString() + '.tmp'), tempSourceSnapshot, sourceScript.languageId, [sourceScript.generated.languagePlugin])?.generated?.root;
120
+ const previousVirtualFile = tempVirtualFile;
121
+ tempVirtualFile = languagePlugin.updateVirtualCode
122
+ ? languagePlugin.updateVirtualCode(tempId, previousVirtualFile, tempSourceSnapshot, codegenCtx)
123
+ : languagePlugin.createVirtualCode?.(tempId, sourceScript.languageId, tempSourceSnapshot, codegenCtx);
112
124
  if (!tempVirtualFile) {
125
+ languagePlugin.disposeVirtualCode?.(tempId, previousVirtualFile);
113
126
  break;
114
127
  }
115
128
  }
@@ -128,7 +141,9 @@ function register(context) {
128
141
  return [textEdit];
129
142
  }
130
143
  finally {
131
- context.language.scripts.delete(vscode_uri_1.URI.parse(sourceScript.id.toString() + '.tmp'));
144
+ if (tempVirtualFile) {
145
+ languagePlugin.disposeVirtualCode?.(tempId, tempVirtualFile);
146
+ }
132
147
  }
133
148
  async function tryFormat(sourceDocument, document, sourceScript, virtualCode, embeddedLevel, rangeOrPosition, ch) {
134
149
  if (context.disabledEmbeddedDocumentUris.get(vscode_uri_1.URI.parse(document.uri))) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@volar/language-service",
3
- "version": "2.4.30",
3
+ "version": "2.4.31",
4
4
  "license": "MIT",
5
5
  "files": [
6
6
  "**/*.js",
@@ -12,7 +12,7 @@
12
12
  "directory": "packages/language-service"
13
13
  },
14
14
  "dependencies": {
15
- "@volar/language-core": "2.4.30",
15
+ "@volar/language-core": "2.4.31",
16
16
  "vscode-languageserver-protocol": "^3.17.5",
17
17
  "vscode-languageserver-textdocument": "^1.0.11",
18
18
  "vscode-uri": "^3.0.8"