@volar/language-service 1.5.1 → 1.5.3
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.
|
@@ -72,7 +72,7 @@ function register(context) {
|
|
|
72
72
|
if (edits.length > 0) {
|
|
73
73
|
const newText = vscode_languageserver_textdocument_1.TextDocument.applyEdits(document, edits);
|
|
74
74
|
document = vscode_languageserver_textdocument_1.TextDocument.create(document.uri, document.languageId, document.version + 1, newText);
|
|
75
|
-
context.core.virtualFiles.updateSource(context.env.uriToFileName(document.uri), (0, common_1.stringToSnapshot)(document.getText()),
|
|
75
|
+
context.core.virtualFiles.updateSource(context.env.uriToFileName(document.uri), (0, common_1.stringToSnapshot)(document.getText()), document.languageId);
|
|
76
76
|
edited = true;
|
|
77
77
|
}
|
|
78
78
|
if (level > 1) {
|
|
@@ -121,7 +121,7 @@ function register(context) {
|
|
|
121
121
|
if (indentEdits.length > 0) {
|
|
122
122
|
const newText = vscode_languageserver_textdocument_1.TextDocument.applyEdits(document, indentEdits);
|
|
123
123
|
document = vscode_languageserver_textdocument_1.TextDocument.create(document.uri, document.languageId, document.version + 1, newText);
|
|
124
|
-
context.core.virtualFiles.updateSource(context.env.uriToFileName(document.uri), (0, common_1.stringToSnapshot)(document.getText()),
|
|
124
|
+
context.core.virtualFiles.updateSource(context.env.uriToFileName(document.uri), (0, common_1.stringToSnapshot)(document.getText()), document.languageId);
|
|
125
125
|
edited = true;
|
|
126
126
|
}
|
|
127
127
|
}
|
|
@@ -130,7 +130,7 @@ function register(context) {
|
|
|
130
130
|
}
|
|
131
131
|
if (edited) {
|
|
132
132
|
// recover
|
|
133
|
-
context.core.virtualFiles.updateSource(context.env.uriToFileName(document.uri), originalSnapshot,
|
|
133
|
+
context.core.virtualFiles.updateSource(context.env.uriToFileName(document.uri), originalSnapshot, document.languageId);
|
|
134
134
|
}
|
|
135
135
|
if (document.getText() === originalDocument.getText())
|
|
136
136
|
return;
|
|
@@ -116,7 +116,7 @@ function mergeWorkspaceEdits(original, ...others) {
|
|
|
116
116
|
original.documentChanges = [];
|
|
117
117
|
}
|
|
118
118
|
for (const docChange of other.documentChanges) {
|
|
119
|
-
original.documentChanges
|
|
119
|
+
pushEditToDocumentChanges(original.documentChanges, docChange);
|
|
120
120
|
}
|
|
121
121
|
}
|
|
122
122
|
}
|
|
@@ -149,7 +149,7 @@ function embeddedEditToSourceEdit(tsResult, documents, mode, versions = {}) {
|
|
|
149
149
|
for (const [_, map] of documents.getMapsByVirtualFileUri(tsUri)) {
|
|
150
150
|
const tsEdits = tsResult.changes[tsUri];
|
|
151
151
|
for (const tsEdit of tsEdits) {
|
|
152
|
-
if (mode === 'rename' || mode === 'fileName') {
|
|
152
|
+
if (mode === 'rename' || mode === 'fileName' || mode === 'codeAction') {
|
|
153
153
|
let _data;
|
|
154
154
|
const range = map.toSourceRange(tsEdit.range, data => {
|
|
155
155
|
_data = data;
|
|
@@ -188,7 +188,7 @@ function embeddedEditToSourceEdit(tsResult, documents, mode, versions = {}) {
|
|
|
188
188
|
version: versions[map.sourceFileDocument.uri] ?? null,
|
|
189
189
|
}, []);
|
|
190
190
|
for (const tsEdit of tsDocEdit.edits) {
|
|
191
|
-
if (mode === 'rename' || mode === 'fileName') {
|
|
191
|
+
if (mode === 'rename' || mode === 'fileName' || mode === 'codeAction') {
|
|
192
192
|
let _data;
|
|
193
193
|
const range = map.toSourceRange(tsEdit.range, data => {
|
|
194
194
|
_data = data;
|
|
@@ -253,7 +253,7 @@ function embeddedEditToSourceEdit(tsResult, documents, mode, versions = {}) {
|
|
|
253
253
|
}
|
|
254
254
|
}
|
|
255
255
|
if (sourceEdit) {
|
|
256
|
-
sourceResult.documentChanges
|
|
256
|
+
pushEditToDocumentChanges(sourceResult.documentChanges, sourceEdit);
|
|
257
257
|
hasResult = true;
|
|
258
258
|
}
|
|
259
259
|
}
|
|
@@ -263,4 +263,15 @@ function embeddedEditToSourceEdit(tsResult, documents, mode, versions = {}) {
|
|
|
263
263
|
}
|
|
264
264
|
}
|
|
265
265
|
exports.embeddedEditToSourceEdit = embeddedEditToSourceEdit;
|
|
266
|
+
function pushEditToDocumentChanges(arr, item) {
|
|
267
|
+
const current = arr.find(edit => vscode.TextDocumentEdit.is(edit)
|
|
268
|
+
&& vscode.TextDocumentEdit.is(item)
|
|
269
|
+
&& edit.textDocument.uri === item.textDocument.uri);
|
|
270
|
+
if (current) {
|
|
271
|
+
current.edits.push(...item.edits);
|
|
272
|
+
}
|
|
273
|
+
else {
|
|
274
|
+
arr.push(item);
|
|
275
|
+
}
|
|
276
|
+
}
|
|
266
277
|
//# sourceMappingURL=rename.js.map
|
package/out/types.d.ts
CHANGED
|
@@ -112,7 +112,7 @@ export interface Service {
|
|
|
112
112
|
resolveReferencesCodeLensLocations?(document: TextDocument, range: vscode.Range, references: vscode.Location[], token: vscode.CancellationToken): Result<vscode.Location[]>;
|
|
113
113
|
resolveEmbeddedRange?(range: vscode.Range): vscode.Range | undefined;
|
|
114
114
|
rules?: {
|
|
115
|
-
provide?: Record<any, (document: TextDocument, ruleType: RuleType) =>
|
|
115
|
+
provide?: Record<any, (document: TextDocument, ruleType: RuleType) => any | undefined>;
|
|
116
116
|
resolveDiagnostic?(diagnostic: vscode.Diagnostic): vscode.Diagnostic;
|
|
117
117
|
};
|
|
118
118
|
};
|
|
@@ -66,37 +66,16 @@ exports.languageFeatureWorker = languageFeatureWorker;
|
|
|
66
66
|
async function ruleWorker(context, ruleType, uri, isValidSourceMap, worker, transform, combineResult, reportProgress) {
|
|
67
67
|
const document = context.getTextDocument(uri);
|
|
68
68
|
const virtualFile = context.documents.getSourceByUri(uri)?.root;
|
|
69
|
-
|
|
69
|
+
let provided = {};
|
|
70
70
|
let results = [];
|
|
71
|
-
let ruleCtx
|
|
72
|
-
env: context.env,
|
|
73
|
-
ruleId: '',
|
|
74
|
-
document: document,
|
|
75
|
-
report: () => { },
|
|
76
|
-
inject: key => {
|
|
77
|
-
if (!provided.has(key)) {
|
|
78
|
-
for (const service of Object.values(context.services)) {
|
|
79
|
-
const provide = service.rules?.provide?.[key];
|
|
80
|
-
if (provide) {
|
|
81
|
-
try {
|
|
82
|
-
provided.set(key, provide(ruleCtx.document, ruleType));
|
|
83
|
-
}
|
|
84
|
-
catch (err) {
|
|
85
|
-
console.warn('service rule context setup crashed on ' + ruleCtx.document.uri + ': ' + err);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
return provided.get(key);
|
|
91
|
-
},
|
|
92
|
-
};
|
|
71
|
+
let ruleCtx;
|
|
93
72
|
if (virtualFile) {
|
|
94
73
|
await (0, definePlugin_1.visitEmbedded)(context.documents, virtualFile, async (file, map) => {
|
|
95
74
|
if (!isValidSourceMap(file)) {
|
|
96
75
|
return true;
|
|
97
76
|
}
|
|
98
|
-
ruleCtx
|
|
99
|
-
provided
|
|
77
|
+
ruleCtx = createCtx(map.virtualFileDocument);
|
|
78
|
+
provided = {};
|
|
100
79
|
for (const ruleId in context.config.rules) {
|
|
101
80
|
const rule = context.config.rules[ruleId];
|
|
102
81
|
if ((rule.type ?? types_1.RuleType.Syntax) !== ruleType) {
|
|
@@ -121,8 +100,8 @@ async function ruleWorker(context, ruleType, uri, isValidSourceMap, worker, tran
|
|
|
121
100
|
});
|
|
122
101
|
}
|
|
123
102
|
else if (document) {
|
|
124
|
-
ruleCtx
|
|
125
|
-
provided
|
|
103
|
+
ruleCtx = createCtx(document);
|
|
104
|
+
provided = {};
|
|
126
105
|
for (const ruleId in context.config.rules) {
|
|
127
106
|
const rule = context.config.rules[ruleId];
|
|
128
107
|
if ((rule.type ?? types_1.RuleType.Syntax) !== ruleType) {
|
|
@@ -150,6 +129,32 @@ async function ruleWorker(context, ruleType, uri, isValidSourceMap, worker, tran
|
|
|
150
129
|
else if (results.length > 0) {
|
|
151
130
|
return results[0];
|
|
152
131
|
}
|
|
132
|
+
function createCtx(document) {
|
|
133
|
+
return {
|
|
134
|
+
env: context.env,
|
|
135
|
+
ruleId: '',
|
|
136
|
+
document: document,
|
|
137
|
+
report: () => { },
|
|
138
|
+
inject: key => {
|
|
139
|
+
provided[key] ??= new Map();
|
|
140
|
+
const map = provided[key];
|
|
141
|
+
if (!map.has(ruleCtx.document)) {
|
|
142
|
+
for (const service of Object.values(context.services)) {
|
|
143
|
+
const provide = service.rules?.provide?.[key];
|
|
144
|
+
if (provide) {
|
|
145
|
+
try {
|
|
146
|
+
map.set(ruleCtx.document, provide(ruleCtx.document, ruleType));
|
|
147
|
+
}
|
|
148
|
+
catch (err) {
|
|
149
|
+
console.warn('service rule context setup crashed on ' + ruleCtx.document.uri + ': ' + err);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
return map.get(ruleCtx.document);
|
|
155
|
+
},
|
|
156
|
+
};
|
|
157
|
+
}
|
|
153
158
|
}
|
|
154
159
|
exports.ruleWorker = ruleWorker;
|
|
155
160
|
async function safeCall(cb, errorMsg) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@volar/language-service",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.3",
|
|
4
4
|
"main": "out/index.js",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"files": [
|
|
@@ -13,8 +13,8 @@
|
|
|
13
13
|
"directory": "packages/language-service"
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@volar/language-core": "1.5.
|
|
17
|
-
"@volar/source-map": "1.5.
|
|
16
|
+
"@volar/language-core": "1.5.3",
|
|
17
|
+
"@volar/source-map": "1.5.3",
|
|
18
18
|
"typescript-auto-import-cache": "^0.2.1",
|
|
19
19
|
"vscode-html-languageservice": "^5.0.4",
|
|
20
20
|
"vscode-json-languageservice": "^5.2.0",
|
|
@@ -22,5 +22,5 @@
|
|
|
22
22
|
"vscode-languageserver-textdocument": "^1.0.8",
|
|
23
23
|
"vscode-uri": "^3.0.7"
|
|
24
24
|
},
|
|
25
|
-
"gitHead": "
|
|
25
|
+
"gitHead": "4d4849277f76523ad1f2719cc94e09abb8c7c77c"
|
|
26
26
|
}
|