@volar/language-service 1.11.1 → 2.0.0-alpha.1
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/index.d.ts +3 -4
- package/index.js +5 -5
- package/lib/documents.d.ts +26 -40
- package/lib/documents.js +66 -113
- package/lib/features/provideAutoInsertionEdit.d.ts +6 -0
- package/lib/features/provideAutoInsertionEdit.js +40 -0
- package/lib/{languageFeatures/callHierarchy.d.ts → features/provideCallHierarchyItems.d.ts} +1 -2
- package/lib/{languageFeatures/callHierarchy.js → features/provideCallHierarchyItems.js} +33 -23
- package/lib/{languageFeatures/codeActions.d.ts → features/provideCodeActions.d.ts} +1 -13
- package/lib/features/provideCodeActions.js +111 -0
- package/lib/{languageFeatures/codeLens.d.ts → features/provideCodeLenses.d.ts} +6 -6
- package/lib/features/provideCodeLenses.js +61 -0
- package/lib/{documentFeatures/colorPresentations.d.ts → features/provideColorPresentations.d.ts} +0 -1
- package/lib/features/provideColorPresentations.js +46 -0
- package/lib/{languageFeatures/complete.d.ts → features/provideCompletionItems.d.ts} +1 -2
- package/lib/{languageFeatures/complete.js → features/provideCompletionItems.js} +45 -37
- package/lib/features/provideDefinition.d.ts +4 -0
- package/lib/{languageFeatures/definition.js → features/provideDefinition.js} +48 -45
- package/lib/{languageFeatures/validation.d.ts → features/provideDiagnostics.d.ts} +2 -5
- package/lib/{languageFeatures/validation.js → features/provideDiagnostics.js} +30 -125
- package/lib/{documentFeatures/documentColors.d.ts → features/provideDocumentColors.d.ts} +1 -2
- package/lib/features/provideDocumentColors.js +34 -0
- package/lib/features/provideDocumentDropEdits.d.ts +3 -0
- package/lib/features/provideDocumentDropEdits.js +27 -0
- package/lib/{documentFeatures/format.d.ts → features/provideDocumentFormattingEdits.d.ts} +0 -1
- package/lib/{documentFeatures/format.js → features/provideDocumentFormattingEdits.js} +76 -71
- package/lib/{languageFeatures/documentHighlights.d.ts → features/provideDocumentHighlights.d.ts} +0 -1
- package/lib/{languageFeatures/documentHighlights.js → features/provideDocumentHighlights.js} +17 -16
- package/lib/{languageFeatures/documentLinks.d.ts → features/provideDocumentLinks.d.ts} +1 -2
- package/lib/features/provideDocumentLinks.js +50 -0
- package/lib/{languageFeatures/documentSemanticTokens.d.ts → features/provideDocumentSemanticTokens.d.ts} +1 -2
- package/lib/features/provideDocumentSemanticTokens.js +84 -0
- package/lib/{documentFeatures/documentSymbols.d.ts → features/provideDocumentSymbols.d.ts} +0 -1
- package/lib/{documentFeatures/documentSymbols.js → features/provideDocumentSymbols.js} +15 -10
- package/lib/{languageFeatures/fileReferences.d.ts → features/provideFileReferences.d.ts} +0 -1
- package/lib/features/provideFileReferences.js +35 -0
- package/lib/{languageFeatures/fileRename.d.ts → features/provideFileRenameEdits.d.ts} +0 -1
- package/lib/{languageFeatures/fileRename.js → features/provideFileRenameEdits.js} +12 -12
- package/lib/{documentFeatures/foldingRanges.d.ts → features/provideFoldingRanges.d.ts} +0 -1
- package/lib/features/provideFoldingRanges.js +24 -0
- package/lib/{languageFeatures/hover.d.ts → features/provideHover.d.ts} +0 -1
- package/lib/{languageFeatures/hover.js → features/provideHover.js} +11 -11
- package/lib/{languageFeatures/inlayHints.d.ts → features/provideInlayHints.d.ts} +1 -2
- package/lib/features/provideInlayHints.js +84 -0
- package/lib/{documentFeatures/linkedEditingRanges.d.ts → features/provideLinkedEditingRanges.d.ts} +0 -1
- package/lib/features/provideLinkedEditingRanges.js +32 -0
- package/lib/{languageFeatures/references.d.ts → features/provideReferences.d.ts} +0 -1
- package/lib/{languageFeatures/references.js → features/provideReferences.js} +14 -13
- package/lib/{languageFeatures/rename.d.ts → features/provideRenameEdits.d.ts} +0 -3
- package/lib/features/provideRenameEdits.js +126 -0
- package/lib/{languageFeatures/renamePrepare.d.ts → features/provideRenameRange.d.ts} +2 -3
- package/lib/{languageFeatures/renamePrepare.js → features/provideRenameRange.js} +7 -5
- package/lib/{documentFeatures/selectionRanges.d.ts → features/provideSelectionRanges.d.ts} +1 -2
- package/lib/{documentFeatures/selectionRanges.js → features/provideSelectionRanges.js} +18 -15
- package/lib/{languageFeatures/signatureHelp.d.ts → features/provideSignatureHelp.d.ts} +0 -1
- package/lib/{languageFeatures/signatureHelp.js → features/provideSignatureHelp.js} +8 -6
- package/lib/{languageFeatures/workspaceSymbols.d.ts → features/provideWorkspaceSymbols.d.ts} +0 -1
- package/lib/{languageFeatures/workspaceSymbols.js → features/provideWorkspaceSymbols.js} +15 -11
- package/lib/{languageFeatures/codeActionResolve.d.ts → features/resolveCodeAction.d.ts} +0 -1
- package/lib/features/resolveCodeAction.js +27 -0
- package/lib/{languageFeatures/codeLensResolve.d.ts → features/resolveCodeLens.d.ts} +0 -1
- package/lib/features/resolveCodeLens.js +39 -0
- package/lib/{languageFeatures/completeResolve.d.ts → features/resolveCompletionItem.d.ts} +0 -1
- package/lib/features/resolveCompletionItem.js +35 -0
- package/lib/{languageFeatures/documentLinkResolve.d.ts → features/resolveDocumentLink.d.ts} +0 -1
- package/lib/{languageFeatures/documentLinkResolve.js → features/resolveDocumentLink.js} +12 -10
- package/lib/{languageFeatures/inlayHintResolve.d.ts → features/resolveInlayHint.d.ts} +0 -1
- package/lib/{languageFeatures/inlayHintResolve.js → features/resolveInlayHint.js} +4 -4
- package/lib/languageService.d.ts +61 -0
- package/lib/languageService.js +158 -0
- package/lib/types.d.ts +88 -137
- package/lib/types.js +1 -8
- package/lib/utils/SemanticTokensBuilder.d.ts +0 -1
- package/lib/utils/cancellation.d.ts +0 -1
- package/lib/utils/common.d.ts +0 -2
- package/lib/utils/common.js +1 -18
- package/lib/utils/dedupe.d.ts +0 -1
- package/lib/utils/featureWorkers.d.ts +7 -8
- package/lib/utils/featureWorkers.js +37 -93
- package/lib/utils/transform.d.ts +19 -0
- package/lib/utils/transform.js +375 -0
- package/package.json +3 -4
- package/lib/baseLanguageService.d.ts +0 -112
- package/lib/baseLanguageService.js +0 -231
- package/lib/documentFeatures/colorPresentations.js +0 -37
- package/lib/documentFeatures/documentColors.js +0 -26
- package/lib/documentFeatures/foldingRanges.js +0 -17
- package/lib/documentFeatures/linkedEditingRanges.js +0 -20
- package/lib/languageFeatures/autoInsert.d.ts +0 -4
- package/lib/languageFeatures/autoInsert.js +0 -42
- package/lib/languageFeatures/codeActionResolve.js +0 -51
- package/lib/languageFeatures/codeActions.js +0 -177
- package/lib/languageFeatures/codeLens.js +0 -53
- package/lib/languageFeatures/codeLensResolve.js +0 -31
- package/lib/languageFeatures/completeResolve.js +0 -32
- package/lib/languageFeatures/definition.d.ts +0 -5
- package/lib/languageFeatures/documentLinks.js +0 -66
- package/lib/languageFeatures/documentSemanticTokens.js +0 -70
- package/lib/languageFeatures/fileReferences.js +0 -32
- package/lib/languageFeatures/inlayHints.js +0 -75
- package/lib/languageFeatures/rename.js +0 -291
- package/lib/transformer/completionItem.d.ts +0 -3
- package/lib/transformer/completionItem.js +0 -18
- package/lib/transformer/completionList.d.ts +0 -3
- package/lib/transformer/completionList.js +0 -27
- package/lib/transformer/documentSymbol.d.ts +0 -3
- package/lib/transformer/documentSymbol.js +0 -24
- package/lib/transformer/foldingRanges.d.ts +0 -3
- package/lib/transformer/foldingRanges.js +0 -24
- package/lib/transformer/hover.d.ts +0 -3
- package/lib/transformer/hover.js +0 -17
- package/lib/transformer/index.d.ts +0 -12
- package/lib/transformer/index.js +0 -26
- package/lib/transformer/locationLike.d.ts +0 -5
- package/lib/transformer/locationLike.js +0 -14
- package/lib/transformer/locationsLike.d.ts +0 -5
- package/lib/transformer/locationsLike.js +0 -12
- package/lib/transformer/selectionRange.d.ts +0 -3
- package/lib/transformer/selectionRange.js +0 -15
- package/lib/transformer/selectionRanges.d.ts +0 -3
- package/lib/transformer/selectionRanges.js +0 -12
- package/lib/transformer/textEdit.d.ts +0 -3
- package/lib/transformer/textEdit.js +0 -72
- package/lib/transformer/workspaceSymbol.d.ts +0 -3
- package/lib/transformer/workspaceSymbol.js +0 -18
- package/lib/utils/definePlugin.d.ts +0 -4
- package/lib/utils/definePlugin.js +0 -20
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.register = exports.errorMarkups = exports.updateRange = void 0;
|
|
4
|
-
const
|
|
4
|
+
const language_core_1 = require("@volar/language-core");
|
|
5
|
+
const cancellation_1 = require("../utils/cancellation");
|
|
5
6
|
const common_1 = require("../utils/common");
|
|
6
7
|
const dedupe = require("../utils/dedupe");
|
|
7
8
|
const featureWorkers_1 = require("../utils/featureWorkers");
|
|
8
|
-
const cancellation_1 = require("../utils/cancellation");
|
|
9
9
|
function updateRange(range, change) {
|
|
10
10
|
if (!updatePosition(range.start, change, false)) {
|
|
11
11
|
return;
|
|
@@ -89,10 +89,10 @@ function register(context) {
|
|
|
89
89
|
format_rules: new Map(),
|
|
90
90
|
};
|
|
91
91
|
return async (uri, mode, token = cancellation_1.NoneCancellationToken, response) => {
|
|
92
|
-
const
|
|
93
|
-
if (!
|
|
92
|
+
const sourceFile = context.language.files.getSourceFile(uri);
|
|
93
|
+
if (!sourceFile)
|
|
94
94
|
return [];
|
|
95
|
-
|
|
95
|
+
const document = context.documents.get(uri, sourceFile.languageId, sourceFile.snapshot);
|
|
96
96
|
const lastResponse = lastResponses.get(uri) ?? lastResponses.set(uri, {
|
|
97
97
|
semantic: { errors: [] },
|
|
98
98
|
syntactic: { errors: [] },
|
|
@@ -100,23 +100,22 @@ function register(context) {
|
|
|
100
100
|
syntax_rules: { errors: [] },
|
|
101
101
|
format_rules: { errors: [] },
|
|
102
102
|
}).get(uri);
|
|
103
|
-
const newSnapshot = context.host.getScriptSnapshot(context.env.uriToFileName(uri));
|
|
104
103
|
let updateCacheRangeFailed = false;
|
|
105
104
|
let errorsUpdated = false;
|
|
106
105
|
let lastCheckCancelAt = 0;
|
|
107
106
|
for (const cache of Object.values(lastResponse)) {
|
|
108
107
|
const oldSnapshot = cache.snapshot;
|
|
109
108
|
const oldDocument = cache.document;
|
|
110
|
-
const change = oldSnapshot ?
|
|
111
|
-
cache.snapshot =
|
|
112
|
-
cache.document =
|
|
113
|
-
if (!updateCacheRangeFailed &&
|
|
109
|
+
const change = oldSnapshot ? sourceFile.snapshot.getChangeRange(oldSnapshot) : undefined;
|
|
110
|
+
cache.snapshot = sourceFile.snapshot;
|
|
111
|
+
cache.document = document;
|
|
112
|
+
if (!updateCacheRangeFailed && oldDocument && change) {
|
|
114
113
|
const changeRange = {
|
|
115
114
|
range: {
|
|
116
115
|
start: oldDocument.positionAt(change.span.start),
|
|
117
116
|
end: oldDocument.positionAt(change.span.start + change.span.length),
|
|
118
117
|
},
|
|
119
|
-
newEnd:
|
|
118
|
+
newEnd: document.positionAt(change.span.start + change.newLength),
|
|
120
119
|
};
|
|
121
120
|
for (const error of cache.errors) {
|
|
122
121
|
if (!updateRange(error.range, changeRange)) {
|
|
@@ -127,15 +126,9 @@ function register(context) {
|
|
|
127
126
|
}
|
|
128
127
|
}
|
|
129
128
|
if (mode === 'all' || mode === 'syntactic') {
|
|
130
|
-
await lintWorker(types_1.RuleType.Format, cacheMaps.format_rules, lastResponse.format_rules);
|
|
131
|
-
await doResponse();
|
|
132
|
-
await lintWorker(types_1.RuleType.Syntax, cacheMaps.syntax_rules, lastResponse.syntax_rules);
|
|
133
|
-
await doResponse();
|
|
134
129
|
await worker('provideDiagnostics', cacheMaps.syntactic, lastResponse.syntactic);
|
|
135
|
-
await doResponse();
|
|
136
130
|
}
|
|
137
131
|
if (mode === 'all' || mode === 'semantic') {
|
|
138
|
-
await lintWorker(types_1.RuleType.Semantic, cacheMaps.semantic_rules, lastResponse.semantic_rules);
|
|
139
132
|
await doResponse();
|
|
140
133
|
await worker('provideSemanticDiagnostics', cacheMaps.semantic, lastResponse.semantic);
|
|
141
134
|
}
|
|
@@ -150,8 +143,8 @@ function register(context) {
|
|
|
150
143
|
const errors = Object.values(lastResponse).flatMap(({ errors }) => errors);
|
|
151
144
|
exports.errorMarkups[uri] = [];
|
|
152
145
|
for (const error of errors) {
|
|
153
|
-
for (const service of
|
|
154
|
-
const markup = await service.provideDiagnosticMarkupContent?.(error, token);
|
|
146
|
+
for (const service of context.services) {
|
|
147
|
+
const markup = await service[1].provideDiagnosticMarkupContent?.(error, token);
|
|
155
148
|
if (markup) {
|
|
156
149
|
exports.errorMarkups[uri].push({ error, markup });
|
|
157
150
|
}
|
|
@@ -159,82 +152,8 @@ function register(context) {
|
|
|
159
152
|
}
|
|
160
153
|
return errors;
|
|
161
154
|
}
|
|
162
|
-
async function lintWorker(ruleType, cacheMap, cache) {
|
|
163
|
-
const result = await (0, featureWorkers_1.ruleWorker)(context, ruleType, uri, file => ruleType === types_1.RuleType.Format ? !!file.capabilities.documentFormatting : !!file.capabilities.diagnostic, async (ruleId, rule, lintDocument, ruleCtx) => {
|
|
164
|
-
if (token) {
|
|
165
|
-
if (Date.now() - lastCheckCancelAt >= 5) {
|
|
166
|
-
await (0, common_1.sleep)(5); // wait for LSP event polling
|
|
167
|
-
lastCheckCancelAt = Date.now();
|
|
168
|
-
}
|
|
169
|
-
if (token.isCancellationRequested) {
|
|
170
|
-
return;
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
const pluginCache = cacheMap.get(ruleId) ?? cacheMap.set(ruleId, new Map()).get(ruleId);
|
|
174
|
-
const cache = pluginCache.get(lintDocument.uri);
|
|
175
|
-
const projectVersion = (ruleType === types_1.RuleType.Semantic) ? context.host.getProjectVersion?.() : undefined;
|
|
176
|
-
if (ruleType === types_1.RuleType.Semantic) {
|
|
177
|
-
if (cache && cache.documentVersion === lintDocument.version && cache.projectVersion === projectVersion) {
|
|
178
|
-
return cache.errors;
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
else {
|
|
182
|
-
if (cache && cache.documentVersion === lintDocument.version) {
|
|
183
|
-
return cache.errors;
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
const reportResults = [];
|
|
187
|
-
ruleCtx.report = (error, ...fixes) => {
|
|
188
|
-
error.message ||= 'No message.';
|
|
189
|
-
error.source ||= 'rule';
|
|
190
|
-
error.code ||= ruleId;
|
|
191
|
-
reportResults.push([error, ...fixes]);
|
|
192
|
-
};
|
|
193
|
-
try {
|
|
194
|
-
await rule.run(lintDocument, ruleCtx);
|
|
195
|
-
}
|
|
196
|
-
catch (err) {
|
|
197
|
-
console.warn(`[volar/rules-api] ${ruleId} ${ruleType} error.`);
|
|
198
|
-
console.warn(err);
|
|
199
|
-
}
|
|
200
|
-
context.ruleFixes ??= {};
|
|
201
|
-
context.ruleFixes[lintDocument.uri] ??= {};
|
|
202
|
-
context.ruleFixes[lintDocument.uri][ruleId] ??= {};
|
|
203
|
-
reportResults?.forEach(([error, ...fixes], index) => {
|
|
204
|
-
context.ruleFixes[lintDocument.uri][ruleId][index] = [error, fixes];
|
|
205
|
-
error.data = {
|
|
206
|
-
uri,
|
|
207
|
-
version: newDocument.version,
|
|
208
|
-
type: 'rule',
|
|
209
|
-
isFormat: ruleType === types_1.RuleType.Format,
|
|
210
|
-
serviceOrRuleId: ruleId,
|
|
211
|
-
original: {
|
|
212
|
-
data: error.data,
|
|
213
|
-
},
|
|
214
|
-
ruleFixIndex: index,
|
|
215
|
-
documentUri: lintDocument.uri,
|
|
216
|
-
};
|
|
217
|
-
});
|
|
218
|
-
errorsUpdated = true;
|
|
219
|
-
const errors = reportResults.map(reportResult => reportResult[0]);
|
|
220
|
-
pluginCache.set(lintDocument.uri, {
|
|
221
|
-
documentVersion: lintDocument.version,
|
|
222
|
-
errors,
|
|
223
|
-
projectVersion,
|
|
224
|
-
});
|
|
225
|
-
return errors;
|
|
226
|
-
}, ruleType === types_1.RuleType.Format ? transformFormatErrorRange : transformErrorRange, arr => arr.flat());
|
|
227
|
-
if (result) {
|
|
228
|
-
cache.errors = result;
|
|
229
|
-
cache.snapshot = newSnapshot;
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
155
|
async function worker(api, cacheMap, cache) {
|
|
233
|
-
const result = await (0, featureWorkers_1.
|
|
234
|
-
if (file.capabilities.diagnostic) {
|
|
235
|
-
yield arg;
|
|
236
|
-
}
|
|
237
|
-
}, async (service, document) => {
|
|
156
|
+
const result = await (0, featureWorkers_1.documentFeatureWorker)(context, uri, map => map.map.mappings.some(mapping => (0, language_core_1.isDiagnosticsEnabled)(mapping.data)), async (service, document) => {
|
|
238
157
|
if (token) {
|
|
239
158
|
if (Date.now() - lastCheckCancelAt >= 5) {
|
|
240
159
|
await (0, common_1.sleep)(5); // waiting LSP event polling
|
|
@@ -244,32 +163,22 @@ function register(context) {
|
|
|
244
163
|
return;
|
|
245
164
|
}
|
|
246
165
|
}
|
|
247
|
-
const
|
|
248
|
-
const serviceCache = cacheMap.get(
|
|
166
|
+
const serviceIndex = context.services.indexOf(service);
|
|
167
|
+
const serviceCache = cacheMap.get(serviceIndex) ?? cacheMap.set(serviceIndex, new Map()).get(serviceIndex);
|
|
249
168
|
const cache = serviceCache.get(document.uri);
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
if (cache && cache.documentVersion === document.version && cache.projectVersion === projectVersion) {
|
|
253
|
-
return cache.errors;
|
|
254
|
-
}
|
|
169
|
+
if (api !== 'provideSemanticDiagnostics' && cache && cache.documentVersion === document.version) {
|
|
170
|
+
return cache.errors;
|
|
255
171
|
}
|
|
256
|
-
|
|
257
|
-
if (cache && cache.documentVersion === document.version) {
|
|
258
|
-
return cache.errors;
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
const errors = await service[api]?.(document, token);
|
|
172
|
+
const errors = await service[1][api]?.(document, token);
|
|
262
173
|
errors?.forEach(error => {
|
|
263
174
|
error.data = {
|
|
264
175
|
uri,
|
|
265
|
-
version:
|
|
266
|
-
|
|
267
|
-
serviceOrRuleId: serviceId,
|
|
176
|
+
version: document.version,
|
|
177
|
+
serviceIndex,
|
|
268
178
|
isFormat: false,
|
|
269
179
|
original: {
|
|
270
180
|
data: error.data,
|
|
271
181
|
},
|
|
272
|
-
ruleFixIndex: 0,
|
|
273
182
|
documentUri: document.uri,
|
|
274
183
|
};
|
|
275
184
|
});
|
|
@@ -277,29 +186,24 @@ function register(context) {
|
|
|
277
186
|
serviceCache.set(document.uri, {
|
|
278
187
|
documentVersion: document.version,
|
|
279
188
|
errors,
|
|
280
|
-
projectVersion,
|
|
281
189
|
});
|
|
282
190
|
return errors;
|
|
283
|
-
},
|
|
191
|
+
}, (errors, map) => {
|
|
192
|
+
return transformErrorRangeBase(errors, map, language_core_1.shouldReportDiagnostics);
|
|
193
|
+
}, arr => dedupe.withDiagnostics(arr.flat()));
|
|
284
194
|
if (result) {
|
|
285
195
|
cache.errors = result;
|
|
286
|
-
cache.snapshot =
|
|
196
|
+
cache.snapshot = sourceFile?.snapshot;
|
|
287
197
|
}
|
|
288
198
|
}
|
|
289
199
|
};
|
|
290
|
-
function transformFormatErrorRange(errors, map) {
|
|
291
|
-
return transformErrorRangeBase(errors, map, () => true);
|
|
292
|
-
}
|
|
293
|
-
function transformErrorRange(errors, map) {
|
|
294
|
-
return transformErrorRangeBase(errors, map, data => typeof data.diagnostic === 'object' ? data.diagnostic.shouldReport() : !!data.diagnostic);
|
|
295
|
-
}
|
|
296
200
|
function transformErrorRangeBase(errors, map, filter) {
|
|
297
201
|
const result = [];
|
|
298
202
|
for (const error of errors) {
|
|
299
203
|
// clone it to avoid modify cache
|
|
300
204
|
let _error = { ...error };
|
|
301
205
|
if (map) {
|
|
302
|
-
const range = map.
|
|
206
|
+
const range = map.getSourceRange(error.range, filter);
|
|
303
207
|
if (!range) {
|
|
304
208
|
continue;
|
|
305
209
|
}
|
|
@@ -308,9 +212,10 @@ function register(context) {
|
|
|
308
212
|
if (_error.relatedInformation) {
|
|
309
213
|
const relatedInfos = [];
|
|
310
214
|
for (const info of _error.relatedInformation) {
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
215
|
+
const [virtualFile] = context.language.files.getVirtualFile(info.location.uri);
|
|
216
|
+
if (virtualFile) {
|
|
217
|
+
for (const map of context.documents.getMaps(virtualFile)) {
|
|
218
|
+
const range = map.getSourceRange(info.location.range, filter);
|
|
314
219
|
if (range) {
|
|
315
220
|
relatedInfos.push({
|
|
316
221
|
location: {
|
|
@@ -334,4 +239,4 @@ function register(context) {
|
|
|
334
239
|
}
|
|
335
240
|
}
|
|
336
241
|
exports.register = register;
|
|
337
|
-
//# sourceMappingURL=
|
|
242
|
+
//# sourceMappingURL=provideDiagnostics.js.map
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { ServiceContext } from '../types';
|
|
2
1
|
import type * as vscode from 'vscode-languageserver-protocol';
|
|
2
|
+
import type { ServiceContext } from '../types';
|
|
3
3
|
export declare function register(context: ServiceContext): (uri: string, token?: vscode.CancellationToken) => Promise<vscode.ColorInformation[] | undefined>;
|
|
4
|
-
//# sourceMappingURL=documentColors.d.ts.map
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.register = void 0;
|
|
4
|
+
const language_core_1 = require("@volar/language-core");
|
|
5
|
+
const cancellation_1 = require("../utils/cancellation");
|
|
6
|
+
const common_1 = require("../utils/common");
|
|
7
|
+
const featureWorkers_1 = require("../utils/featureWorkers");
|
|
8
|
+
function register(context) {
|
|
9
|
+
return (uri, token = cancellation_1.NoneCancellationToken) => {
|
|
10
|
+
return (0, featureWorkers_1.documentFeatureWorker)(context, uri, map => map.map.mappings.some(mapping => (0, language_core_1.isColorEnabled)(mapping.data)), (service, document) => {
|
|
11
|
+
if (token.isCancellationRequested) {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
return service[1].provideDocumentColors?.(document, token);
|
|
15
|
+
}, (data, map) => {
|
|
16
|
+
if (!map) {
|
|
17
|
+
return data;
|
|
18
|
+
}
|
|
19
|
+
return data
|
|
20
|
+
.map(color => {
|
|
21
|
+
const range = map.getSourceRange(color.range, language_core_1.isColorEnabled);
|
|
22
|
+
if (range) {
|
|
23
|
+
return {
|
|
24
|
+
range,
|
|
25
|
+
color: color.color,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
})
|
|
29
|
+
.filter(common_1.notEmpty);
|
|
30
|
+
}, arr => arr.flat());
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
exports.register = register;
|
|
34
|
+
//# sourceMappingURL=provideDocumentColors.js.map
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type * as vscode from 'vscode-languageserver-protocol';
|
|
2
|
+
import type { ServiceContext, DataTransferItem } from '../types';
|
|
3
|
+
export declare function register(context: ServiceContext): (uri: string, position: vscode.Position, dataTransfer: Map<string, DataTransferItem>, token?: vscode.CancellationToken) => Promise<import("../types").DocumentDropEdit | undefined>;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.register = void 0;
|
|
4
|
+
const featureWorkers_1 = require("../utils/featureWorkers");
|
|
5
|
+
const cancellation_1 = require("../utils/cancellation");
|
|
6
|
+
const transform_1 = require("../utils/transform");
|
|
7
|
+
function register(context) {
|
|
8
|
+
return (uri, position, dataTransfer, token = cancellation_1.NoneCancellationToken) => {
|
|
9
|
+
return (0, featureWorkers_1.languageFeatureWorker)(context, uri, () => position, function* (map) {
|
|
10
|
+
for (const mappedPosition of map.getGeneratedPositions(position)) {
|
|
11
|
+
yield mappedPosition;
|
|
12
|
+
}
|
|
13
|
+
}, (service, document, arg) => {
|
|
14
|
+
if (token.isCancellationRequested) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
return service[1].provideDocumentDropEdits?.(document, arg, dataTransfer, token);
|
|
18
|
+
}, (edit) => {
|
|
19
|
+
if (edit.additionalEdit) {
|
|
20
|
+
edit.additionalEdit = (0, transform_1.transformWorkspaceEdit)(edit.additionalEdit, context, undefined);
|
|
21
|
+
}
|
|
22
|
+
return edit;
|
|
23
|
+
});
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
exports.register = register;
|
|
27
|
+
//# sourceMappingURL=provideDocumentDropEdits.js.map
|
|
@@ -9,43 +9,45 @@ const documents_1 = require("../documents");
|
|
|
9
9
|
function register(context) {
|
|
10
10
|
let fakeVersion = 0;
|
|
11
11
|
return async (uri, options, range, onTypeParams, token = cancellation_1.NoneCancellationToken) => {
|
|
12
|
-
|
|
13
|
-
if (!
|
|
12
|
+
const sourceFile = context.language.files.getSourceFile(uri);
|
|
13
|
+
if (!sourceFile)
|
|
14
14
|
return;
|
|
15
|
+
let document = context.documents.get(uri, sourceFile.languageId, sourceFile.snapshot);
|
|
15
16
|
range ??= {
|
|
16
17
|
start: document.positionAt(0),
|
|
17
18
|
end: document.positionAt(document.getText().length),
|
|
18
19
|
};
|
|
19
|
-
|
|
20
|
-
if (!source) {
|
|
20
|
+
if (!sourceFile.virtualFile) {
|
|
21
21
|
return onTypeParams
|
|
22
22
|
? (await tryFormat(document, onTypeParams.position, onTypeParams.ch))?.edits
|
|
23
23
|
: (await tryFormat(document, range, undefined))?.edits;
|
|
24
24
|
}
|
|
25
25
|
const initialIndentLanguageId = await context.env.getConfiguration?.('volar.format.initialIndent') ?? { html: true };
|
|
26
|
-
let tempSourceSnapshot =
|
|
27
|
-
const tempVirtualFile =
|
|
26
|
+
let tempSourceSnapshot = sourceFile.snapshot;
|
|
27
|
+
const tempVirtualFile = sourceFile.virtualFile[1].createVirtualFile(sourceFile.id, sourceFile.languageId, sourceFile.snapshot);
|
|
28
28
|
const originalDocument = document;
|
|
29
29
|
let level = 0;
|
|
30
30
|
while (true) {
|
|
31
31
|
const embeddedFiles = getEmbeddedFilesByLevel(tempVirtualFile, level++);
|
|
32
32
|
if (embeddedFiles.length === 0)
|
|
33
33
|
break;
|
|
34
|
-
// if (level===2) continue;
|
|
35
34
|
let edits = [];
|
|
36
35
|
const toPatchIndent = [];
|
|
37
36
|
for (const file of embeddedFiles) {
|
|
38
|
-
if (!file.
|
|
37
|
+
if (!file.mappings.some(mapping => (0, language_core_1.isFormattingEnabled)(mapping.data)))
|
|
39
38
|
continue;
|
|
40
|
-
const isCodeBlock = file.mappings.length === 1
|
|
39
|
+
const isCodeBlock = file.mappings.length === 1
|
|
40
|
+
&& file.mappings[0].sourceOffsets.length === 1
|
|
41
|
+
&& file.mappings[0].generatedOffsets[0] === 0
|
|
42
|
+
&& file.mappings[0].lengths[0] === file.snapshot.getLength();
|
|
41
43
|
if (onTypeParams && !isCodeBlock)
|
|
42
44
|
continue;
|
|
43
|
-
const docMap = createDocMap(file,
|
|
45
|
+
const docMap = createDocMap(file, sourceFile.id, sourceFile.languageId, tempSourceSnapshot);
|
|
44
46
|
if (!docMap)
|
|
45
47
|
continue;
|
|
46
48
|
let embeddedCodeResult;
|
|
47
49
|
if (onTypeParams) {
|
|
48
|
-
const embeddedPosition = docMap.
|
|
50
|
+
const embeddedPosition = docMap.getGeneratedPosition(onTypeParams.position);
|
|
49
51
|
if (embeddedPosition) {
|
|
50
52
|
embeddedCodeResult = await tryFormat(docMap.virtualFileDocument, embeddedPosition, onTypeParams.ch);
|
|
51
53
|
}
|
|
@@ -59,12 +61,12 @@ function register(context) {
|
|
|
59
61
|
if (!embeddedCodeResult)
|
|
60
62
|
continue;
|
|
61
63
|
toPatchIndent.push({
|
|
62
|
-
|
|
64
|
+
virtualFileUri: file.id,
|
|
63
65
|
isCodeBlock,
|
|
64
|
-
service: embeddedCodeResult.service,
|
|
66
|
+
service: embeddedCodeResult.service[1],
|
|
65
67
|
});
|
|
66
68
|
for (const textEdit of embeddedCodeResult.edits) {
|
|
67
|
-
const range = docMap.
|
|
69
|
+
const range = docMap.getSourceRange(textEdit.range);
|
|
68
70
|
if (range) {
|
|
69
71
|
edits.push({
|
|
70
72
|
newText: textEdit.newText,
|
|
@@ -78,7 +80,7 @@ function register(context) {
|
|
|
78
80
|
const newText = vscode_languageserver_textdocument_1.TextDocument.applyEdits(document, edits);
|
|
79
81
|
document = vscode_languageserver_textdocument_1.TextDocument.create(document.uri, document.languageId, document.version + 1, newText);
|
|
80
82
|
tempSourceSnapshot = (0, common_1.stringToSnapshot)(newText);
|
|
81
|
-
|
|
83
|
+
sourceFile.virtualFile[1].updateVirtualFile(tempVirtualFile, tempSourceSnapshot);
|
|
82
84
|
}
|
|
83
85
|
if (level > 1) {
|
|
84
86
|
const baseIndent = options.insertSpaces ? ' '.repeat(options.tabSize) : '\t';
|
|
@@ -92,23 +94,24 @@ function register(context) {
|
|
|
92
94
|
}
|
|
93
95
|
for (const item of toPatchIndent) {
|
|
94
96
|
let virtualFile;
|
|
95
|
-
(0, language_core_1.forEachEmbeddedFile)(tempVirtualFile
|
|
96
|
-
if (file.
|
|
97
|
+
for (const file of (0, language_core_1.forEachEmbeddedFile)(tempVirtualFile)) {
|
|
98
|
+
if (file.id === item.virtualFileUri) {
|
|
97
99
|
virtualFile = file;
|
|
100
|
+
break;
|
|
98
101
|
}
|
|
99
|
-
}
|
|
100
|
-
const docMap = createDocMap(virtualFile,
|
|
102
|
+
}
|
|
103
|
+
const docMap = createDocMap(virtualFile, sourceFile.id, sourceFile.languageId, tempSourceSnapshot);
|
|
101
104
|
if (!docMap)
|
|
102
105
|
continue;
|
|
103
106
|
const indentSensitiveLines = new Set();
|
|
104
|
-
for (const service of item.service.provideFormattingIndentSensitiveLines ? [item.service] :
|
|
107
|
+
for (const service of item.service.provideFormattingIndentSensitiveLines ? [item.service] : context.services.map(service => service[1])) {
|
|
105
108
|
if (token.isCancellationRequested)
|
|
106
109
|
break;
|
|
107
110
|
if (service.provideFormattingIndentSensitiveLines) {
|
|
108
111
|
const lines = await service.provideFormattingIndentSensitiveLines(docMap.virtualFileDocument, token);
|
|
109
112
|
if (lines) {
|
|
110
113
|
for (const line of lines) {
|
|
111
|
-
const sourceLine = docMap.
|
|
114
|
+
const sourceLine = docMap.getSourcePosition({ line: line, character: 0 })?.line;
|
|
112
115
|
if (sourceLine !== undefined) {
|
|
113
116
|
indentSensitiveLines.add(sourceLine);
|
|
114
117
|
}
|
|
@@ -135,7 +138,7 @@ function register(context) {
|
|
|
135
138
|
const newText = vscode_languageserver_textdocument_1.TextDocument.applyEdits(document, indentEdits);
|
|
136
139
|
document = vscode_languageserver_textdocument_1.TextDocument.create(document.uri, document.languageId, document.version + 1, newText);
|
|
137
140
|
tempSourceSnapshot = (0, common_1.stringToSnapshot)(newText);
|
|
138
|
-
|
|
141
|
+
sourceFile.virtualFile[1].updateVirtualFile(tempVirtualFile, tempSourceSnapshot);
|
|
139
142
|
}
|
|
140
143
|
}
|
|
141
144
|
}
|
|
@@ -165,18 +168,18 @@ function register(context) {
|
|
|
165
168
|
}
|
|
166
169
|
async function tryFormat(document, range, ch) {
|
|
167
170
|
let formatRange = range;
|
|
168
|
-
for (const service of
|
|
171
|
+
for (const service of context.services) {
|
|
169
172
|
if (token.isCancellationRequested)
|
|
170
173
|
break;
|
|
171
174
|
let edits;
|
|
172
175
|
try {
|
|
173
176
|
if (ch !== undefined && 'line' in formatRange && 'character' in formatRange) {
|
|
174
|
-
if (service.autoFormatTriggerCharacters?.includes(ch)) {
|
|
175
|
-
edits = await service.provideOnTypeFormattingEdits?.(document, formatRange, ch, options, token);
|
|
177
|
+
if (service[0].autoFormatTriggerCharacters?.includes(ch)) {
|
|
178
|
+
edits = await service[1].provideOnTypeFormattingEdits?.(document, formatRange, ch, options, token);
|
|
176
179
|
}
|
|
177
180
|
}
|
|
178
181
|
else if (ch === undefined && 'start' in formatRange && 'end' in formatRange) {
|
|
179
|
-
edits = await service.provideDocumentFormattingEdits?.(document, formatRange, options, token);
|
|
182
|
+
edits = await service[1].provideDocumentFormattingEdits?.(document, formatRange, options, token);
|
|
180
183
|
}
|
|
181
184
|
}
|
|
182
185
|
catch (err) {
|
|
@@ -191,16 +194,16 @@ function register(context) {
|
|
|
191
194
|
}
|
|
192
195
|
}
|
|
193
196
|
};
|
|
194
|
-
function createDocMap(file,
|
|
197
|
+
function createDocMap(file, sourceFileUri, sourceLanguageId, _sourceSnapshot) {
|
|
195
198
|
const maps = (0, language_core_1.updateVirtualFileMaps)(file, (sourceFileName) => {
|
|
196
199
|
if (!sourceFileName) {
|
|
197
|
-
return [
|
|
200
|
+
return [sourceFileUri, _sourceSnapshot];
|
|
198
201
|
}
|
|
199
202
|
});
|
|
200
|
-
if (maps.has(
|
|
201
|
-
const
|
|
203
|
+
if (maps.has(sourceFileUri) && maps.get(sourceFileUri)[0] === _sourceSnapshot) {
|
|
204
|
+
const map = maps.get(sourceFileUri);
|
|
202
205
|
const version = fakeVersion++;
|
|
203
|
-
return new documents_1.SourceMapWithDocuments(vscode_languageserver_textdocument_1.TextDocument.create(
|
|
206
|
+
return new documents_1.SourceMapWithDocuments(vscode_languageserver_textdocument_1.TextDocument.create(sourceFileUri, sourceLanguageId ?? (0, language_core_1.resolveCommonLanguageId)(sourceFileUri), version, _sourceSnapshot.getText(0, _sourceSnapshot.getLength())), vscode_languageserver_textdocument_1.TextDocument.create(file.id, file.languageId, version, file.snapshot.getText(0, file.snapshot.getLength())), map[1]);
|
|
204
207
|
}
|
|
205
208
|
}
|
|
206
209
|
}
|
|
@@ -212,46 +215,48 @@ function patchIndents(document, isCodeBlock, map, initialIndent) {
|
|
|
212
215
|
}
|
|
213
216
|
for (let i = 0; i < map.mappings.length; i++) {
|
|
214
217
|
const mapping = map.mappings[i];
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
218
|
+
for (let j = 0; j < mapping.sourceOffsets.length; j++) {
|
|
219
|
+
const firstLineIndent = getBaseIndent(mapping.sourceOffsets[j]);
|
|
220
|
+
const text = document.getText().substring(mapping.sourceOffsets[j], mapping.sourceOffsets[j] + mapping.lengths[j]);
|
|
221
|
+
const lines = text.split('\n');
|
|
222
|
+
const baseIndent = firstLineIndent + initialIndent;
|
|
223
|
+
let lineOffset = lines[0].length + 1;
|
|
224
|
+
let insertedFinalNewLine = false;
|
|
225
|
+
if (!text.trim())
|
|
226
|
+
continue;
|
|
227
|
+
if (isCodeBlock && text.trimStart().length === text.length) {
|
|
228
|
+
indentTextEdits.push({
|
|
229
|
+
newText: '\n' + baseIndent,
|
|
230
|
+
range: {
|
|
231
|
+
start: document.positionAt(mapping.sourceOffsets[j]),
|
|
232
|
+
end: document.positionAt(mapping.sourceOffsets[j]),
|
|
233
|
+
},
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
if (isCodeBlock && text.trimEnd().length === text.length) {
|
|
237
|
+
indentTextEdits.push({
|
|
238
|
+
newText: '\n',
|
|
239
|
+
range: {
|
|
240
|
+
start: document.positionAt(mapping.sourceOffsets[j] + mapping.lengths[j]),
|
|
241
|
+
end: document.positionAt(mapping.sourceOffsets[j] + mapping.lengths[j]),
|
|
242
|
+
},
|
|
243
|
+
});
|
|
244
|
+
insertedFinalNewLine = true;
|
|
245
|
+
}
|
|
246
|
+
if (baseIndent && lines.length > 1) {
|
|
247
|
+
for (let i = 1; i < lines.length; i++) {
|
|
248
|
+
if (lines[i].trim() || i === lines.length - 1) {
|
|
249
|
+
const isLastLine = i === lines.length - 1 && !insertedFinalNewLine;
|
|
250
|
+
indentTextEdits.push({
|
|
251
|
+
newText: isLastLine ? firstLineIndent : baseIndent,
|
|
252
|
+
range: {
|
|
253
|
+
start: document.positionAt(mapping.sourceOffsets[j] + lineOffset),
|
|
254
|
+
end: document.positionAt(mapping.sourceOffsets[j] + lineOffset),
|
|
255
|
+
},
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
lineOffset += lines[i].length + 1;
|
|
253
259
|
}
|
|
254
|
-
lineOffset += lines[i].length + 1;
|
|
255
260
|
}
|
|
256
261
|
}
|
|
257
262
|
}
|
|
@@ -262,4 +267,4 @@ function patchIndents(document, isCodeBlock, map, initialIndent) {
|
|
|
262
267
|
return startLineText.substring(0, startLineText.length - startLineText.trimStart().length);
|
|
263
268
|
}
|
|
264
269
|
}
|
|
265
|
-
//# sourceMappingURL=
|
|
270
|
+
//# sourceMappingURL=provideDocumentFormattingEdits.js.map
|
package/lib/{languageFeatures/documentHighlights.d.ts → features/provideDocumentHighlights.d.ts}
RENAMED
|
@@ -1,4 +1,3 @@
|
|
|
1
1
|
import type * as vscode from 'vscode-languageserver-protocol';
|
|
2
2
|
import type { ServiceContext } from '../types';
|
|
3
3
|
export declare function register(context: ServiceContext): (uri: string, position: vscode.Position, token?: vscode.CancellationToken) => Promise<vscode.DocumentHighlight[] | undefined>;
|
|
4
|
-
//# sourceMappingURL=documentHighlights.d.ts.map
|