Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@volar/language-service

Package Overview
Dependencies
Maintainers
1
Versions
233
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@volar/language-service - npm Package Compare versions

Comparing version 2.3.0-alpha.5 to 2.3.0-alpha.6

4

lib/documents.d.ts

@@ -8,4 +8,4 @@ import { CodeInformation, CodeRangeKey, LinkedCodeMap, Mapping, SourceMap, VirtualCode } from '@volar/language-core';

map: SourceMap<CodeInformation>;
virtuaoCode?: VirtualCode | undefined;
constructor(sourceDocument: TextDocument, embeddedDocument: TextDocument, map: SourceMap<CodeInformation>, virtuaoCode?: VirtualCode | undefined);
virtuaoCode?: VirtualCode<unknown> | undefined;
constructor(sourceDocument: TextDocument, embeddedDocument: TextDocument, map: SourceMap<CodeInformation>, virtuaoCode?: VirtualCode<unknown> | undefined);
getSourceRange(range: vscode.Range, filter?: (data: CodeInformation) => boolean): vscode.Range | undefined;

@@ -12,0 +12,0 @@ getGeneratedRange(range: vscode.Range, filter?: (data: CodeInformation) => boolean): vscode.Range | undefined;

@@ -128,13 +128,15 @@ "use strict";

}
const map = context.documents.getSourceMap(virtualCode);
let range = map.getSourceRange(tsItem.range);
if (!range) {
// TODO: <script> range
range = {
start: map.sourceDocument.positionAt(0),
end: map.sourceDocument.positionAt(map.sourceDocument.getText().length),
};
}
const selectionRange = map.getSourceRange(tsItem.selectionRange);
if (selectionRange) {
for (const map of context.documents.getMaps(virtualCode)) {
let range = map.getSourceRange(tsItem.range);
if (!range) {
// TODO: <script> range
range = {
start: map.sourceDocument.positionAt(0),
end: map.sourceDocument.positionAt(map.sourceDocument.getText().length),
};
}
const selectionRange = map.getSourceRange(tsItem.selectionRange);
if (!selectionRange) {
continue;
}
const vueRanges = tsRanges.map(tsRange => map.getSourceRange(tsRange)).filter(common_1.notEmpty);

@@ -141,0 +143,0 @@ const vueItem = {

@@ -33,24 +33,25 @@ "use strict";

}
const map = context.documents.getSourceMap(virtualCode);
for (const mapped of map.getGeneratedPositions(position, data => (0, language_core_1.isCompletionEnabled)(data))) {
if (!cacheData.plugin.provideCompletionItems) {
continue;
for (const map of context.documents.getMaps(virtualCode)) {
for (const mapped of map.getGeneratedPositions(position, data => (0, language_core_1.isCompletionEnabled)(data))) {
if (!cacheData.plugin.provideCompletionItems) {
continue;
}
cacheData.list = await cacheData.plugin.provideCompletionItems(map.embeddedDocument, mapped, completionContext, token);
if (!cacheData.list) {
continue;
}
for (const item of cacheData.list.items) {
item.data = {
uri: uri.toString(),
original: {
additionalTextEdits: item.additionalTextEdits,
textEdit: item.textEdit,
data: item.data,
},
pluginIndex: pluginIndex,
embeddedDocumentUri: map.embeddedDocument.uri,
};
}
cacheData.list = (0, transform_1.transformCompletionList)(cacheData.list, range => map.getSourceRange(range), map.embeddedDocument, context);
}
cacheData.list = await cacheData.plugin.provideCompletionItems(map.embeddedDocument, mapped, completionContext, token);
if (!cacheData.list) {
continue;
}
for (const item of cacheData.list.items) {
item.data = {
uri: uri.toString(),
original: {
additionalTextEdits: item.additionalTextEdits,
textEdit: item.textEdit,
data: item.data,
},
pluginIndex: pluginIndex,
embeddedDocumentUri: map.embeddedDocument.uri,
};
}
cacheData.list = (0, transform_1.transformCompletionList)(cacheData.list, range => map.getSourceRange(range), map.embeddedDocument, context);
}

@@ -57,0 +58,0 @@ }

@@ -68,2 +68,3 @@ "use strict";

}
let foundTargetSelectionRange = false;
const decoded = context.decodeEmbeddedDocumentUri(vscode_uri_1.URI.parse(link.targetUri));

@@ -73,5 +74,8 @@ const sourceScript = decoded && context.language.scripts.get(decoded[0]);

if (targetVirtualFile) {
const targetSourceMap = context.documents.getSourceMap(targetVirtualFile);
const targetSelectionRange = targetSourceMap.getSourceRange(link.targetSelectionRange);
if (targetSelectionRange) {
for (const targetSourceMap of context.documents.getMaps(targetVirtualFile)) {
const targetSelectionRange = targetSourceMap.getSourceRange(link.targetSelectionRange);
if (!targetSelectionRange) {
continue;
}
foundTargetSelectionRange = true;
let targetRange = targetSourceMap.getSourceRange(link.targetRange);

@@ -83,22 +87,20 @@ link.targetUri = targetSourceMap.sourceDocument.uri;

}
else if (apiName === 'provideDefinition') {
const targetMap = context.documents.getSourceMap(targetVirtualFile);
// cross file definition
if (targetMap.sourceDocument.uri !== uri.toString()) {
return {
...link,
targetUri: targetMap.sourceDocument.uri,
targetRange: {
start: { line: 0, character: 0 },
end: { line: 0, character: 0 },
},
targetSelectionRange: {
start: { line: 0, character: 0 },
end: { line: 0, character: 0 },
},
};
if (apiName === 'provideDefinition' && !foundTargetSelectionRange) {
for (const targetMap of context.documents.getMaps(targetVirtualFile)) {
if (targetMap && targetMap.sourceDocument.uri !== uri.toString()) {
return {
...link,
targetUri: targetMap.sourceDocument.uri,
targetRange: {
start: { line: 0, character: 0 },
end: { line: 0, character: 0 },
},
targetSelectionRange: {
start: { line: 0, character: 0 },
end: { line: 0, character: 0 },
},
};
}
}
else {
return;
}
return;
}

@@ -105,0 +107,0 @@ }

@@ -140,3 +140,3 @@ "use strict";

}
async function collectErrors() {
function collectErrors() {
return Object.values(lastResponse).flatMap(({ errors }) => errors);

@@ -208,12 +208,13 @@ }

if (virtualCode) {
const map = context.documents.getSourceMap(virtualCode);
const range = map.getSourceRange(info.location.range, filter);
if (range) {
relatedInfos.push({
location: {
uri: map.sourceDocument.uri,
range,
},
message: info.message,
});
for (const map of context.documents.getMaps(virtualCode)) {
const range = map.getSourceRange(info.location.range, filter);
if (range) {
relatedInfos.push({
location: {
uri: map.sourceDocument.uri,
range,
},
message: info.message,
});
}
}

@@ -220,0 +221,0 @@ }

@@ -11,3 +11,3 @@ "use strict";

return (uri, token = cancellation_1.NoneCancellationToken) => {
return (0, featureWorkers_1.documentFeatureWorker)(context, uri, map => map.map.mappings.some(mapping => (0, language_core_1.isSymbolsEnabled)(mapping.data)), async (plugin, document) => {
return (0, featureWorkers_1.documentFeatureWorker)(context, uri, map => map.map.mappings.some(mapping => (0, language_core_1.isSymbolsEnabled)(mapping.data)), (plugin, document) => {
if (token.isCancellationRequested) {

@@ -14,0 +14,0 @@ return;

@@ -25,8 +25,9 @@ "use strict";

}
const map = context.documents.getSourceMap(virtualCode);
const range = map.getSourceRange(reference.range, language_core_1.isReferencesEnabled);
if (range) {
reference.uri = map.sourceDocument.uri;
reference.range = range;
return reference;
for (const map of context.documents.getMaps(virtualCode)) {
const range = map.getSourceRange(reference.range, language_core_1.isReferencesEnabled);
if (range) {
reference.uri = map.sourceDocument.uri;
reference.range = range;
return reference;
}
}

@@ -33,0 +34,0 @@ })

@@ -58,9 +58,10 @@ "use strict";

if (virtualCode) {
const map = context.documents.getSourceMap(virtualCode);
const range = map.getSourceRange(reference.range, language_core_1.isReferencesEnabled);
if (range) {
results.push({
uri: map.sourceDocument.uri,
range,
});
for (const map of context.documents.getMaps(virtualCode)) {
const range = map.getSourceRange(reference.range, language_core_1.isReferencesEnabled);
if (range) {
results.push({
uri: map.sourceDocument.uri,
range,
});
}
}

@@ -67,0 +68,0 @@ }

@@ -30,6 +30,7 @@ "use strict";

if (virtualCode) {
const map = context.documents.getSourceMap(virtualCode);
const range = map.getSourceRange(loc.range);
if (range) {
return { uri: map.sourceDocument.uri, range };
for (const map of context.documents.getMaps(virtualCode)) {
const range = map.getSourceRange(loc.range);
if (range) {
return { uri: map.sourceDocument.uri, range };
}
}

@@ -36,0 +37,0 @@ }

@@ -21,5 +21,6 @@ "use strict";

if (virtualCode) {
const map = context.documents.getSourceMap(virtualCode);
item = await plugin[1].resolveCompletionItem(item, token);
item = plugin[1].transformCompletionItem?.(item) ?? (0, transform_1.transformCompletionItem)(item, embeddedRange => map.getSourceRange(embeddedRange), map.embeddedDocument, context);
for (const map of context.documents.getMaps(virtualCode)) {
item = await plugin[1].resolveCompletionItem(item, token);
item = plugin[1].transformCompletionItem?.(item) ?? (0, transform_1.transformCompletionItem)(item, embeddedRange => map.getSourceRange(embeddedRange), map.embeddedDocument, context);
}
}

@@ -26,0 +27,0 @@ }

@@ -62,11 +62,10 @@ "use strict";

},
getSourceMap(virtualCode) {
const map = context.language.maps.get(virtualCode);
let result = map2DocMap.get(map);
if (!result) {
const sourceScript = context.language.scripts.fromVirtualCode(virtualCode);
const embeddedUri = context.encodeEmbeddedDocumentUri(sourceScript.id, virtualCode.id);
map2DocMap.set(map, result = new documents_1.SourceMapWithDocuments(this.get(sourceScript.id, sourceScript.languageId, sourceScript.snapshot), this.get(embeddedUri, virtualCode.languageId, virtualCode.snapshot), map, virtualCode));
*getMaps(virtualCode) {
for (const [uri, snapshot, map] of context.language.maps.forEach(virtualCode)) {
if (!map2DocMap.has(map)) {
const embeddedUri = context.encodeEmbeddedDocumentUri(uri, virtualCode.id);
map2DocMap.set(map, new documents_1.SourceMapWithDocuments(this.get(uri, context.language.scripts.get(uri).languageId, snapshot), this.get(embeddedUri, virtualCode.languageId, virtualCode.snapshot), map, virtualCode));
}
yield map2DocMap.get(map);
}
return result;
},

@@ -73,0 +72,0 @@ getLinkedCodeMap(virtualCode, documentUri) {

@@ -52,4 +52,4 @@ import type { Language, SourceScript, VirtualCode } from '@volar/language-core';

get(uri: URI, languageId: string, snapshot: ts.IScriptSnapshot): TextDocument;
getSourceMap(virtualCode: VirtualCode): SourceMapWithDocuments;
getLinkedCodeMap(virtualCode: VirtualCode, documentUri: URI): LinkedCodeMapWithDocument | undefined;
getMaps(virtualCode: VirtualCode<URI>): Generator<SourceMapWithDocuments>;
getLinkedCodeMap(virtualCode: VirtualCode<URI>, documentUri: URI): LinkedCodeMapWithDocument | undefined;
};

@@ -56,0 +56,0 @@ plugins: [LanguageServicePlugin, LanguageServicePluginInstance][];

@@ -9,3 +9,3 @@ import type { VirtualCode } from '@volar/language-core';

export declare function safeCall<T>(cb: () => Thenable<T> | T, errorMsg?: string): Promise<T | undefined>;
export declare function forEachEmbeddedDocument(context: LanguageServiceContext, sourceScriptId: URI, current: VirtualCode): Generator<SourceMapWithDocuments>;
export declare function getEmbeddedFilesByLevel(context: LanguageServiceContext, sourceFileUri: URI, rootFile: VirtualCode, level: number): VirtualCode[];
export declare function forEachEmbeddedDocument(context: LanguageServiceContext, sourceScriptId: URI, current: VirtualCode<URI>): Generator<SourceMapWithDocuments>;
export declare function getEmbeddedFilesByLevel(context: LanguageServiceContext, sourceFileUri: URI, rootFile: VirtualCode, level: number): VirtualCode<unknown>[];
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getEmbeddedFilesByLevel = exports.forEachEmbeddedDocument = exports.safeCall = exports.languageFeatureWorker = exports.documentFeatureWorker = void 0;
async function documentFeatureWorker(context, uri, valid, worker, transformResult, combineResult) {
function documentFeatureWorker(context, uri, valid, worker, transformResult, combineResult) {
return languageFeatureWorker(context, uri, () => void 0, function* (map) {

@@ -92,5 +92,7 @@ if (valid(map)) {

}
const map = context.documents.getSourceMap(current);
if (!context.disabledEmbeddedDocumentUris.get(context.encodeEmbeddedDocumentUri(sourceScriptId, current.id))) {
yield map;
for (const map of context.documents.getMaps(current)) {
if (sourceScriptId.toString() === map.sourceDocument.uri
&& !context.disabledEmbeddedDocumentUris.get(context.encodeEmbeddedDocumentUri(sourceScriptId, current.id))) {
yield map;
}
}

@@ -97,0 +99,0 @@ }

@@ -18,4 +18,6 @@ "use strict";

if (embeddedRange && virtualCode) {
const map = context.documents.getSourceMap(virtualCode);
if (map.map.mappings.some(mapping => (0, language_core_1.isDocumentLinkEnabled)(mapping.data))) {
for (const map of context.documents.getMaps(virtualCode)) {
if (!map.map.mappings.some(mapping => (0, language_core_1.isDocumentLinkEnabled)(mapping.data))) {
continue;
}
const startLine = Number(embeddedRange[1]) - 1;

@@ -35,2 +37,3 @@ const startCharacter = Number(embeddedRange[3] ?? 1) - 1;

});
break;
}

@@ -44,2 +47,3 @@ }

});
break;
}

@@ -278,6 +282,7 @@ }

if (virtualCode) {
const map = context.documents.getSourceMap(virtualCode);
// TODO: check capability?
const uri = map.sourceDocument.uri;
sourceResult.changeAnnotations[uri] = tsAnno;
for (const map of context.documents.getMaps(virtualCode)) {
// TODO: check capability?
const uri = map.sourceDocument.uri;
sourceResult.changeAnnotations[uri] = tsAnno;
}
}

@@ -294,26 +299,27 @@ else {

if (virtualCode) {
const map = context.documents.getSourceMap(virtualCode);
const tsEdits = edit.changes[tsUri];
for (const tsEdit of tsEdits) {
if (mode === 'rename' || mode === 'fileName' || mode === 'codeAction') {
let _data;
const range = map.getSourceRange(tsEdit.range, data => {
_data = data;
return (0, language_core_1.isRenameEnabled)(data);
});
if (range) {
sourceResult.changes[map.sourceDocument.uri] ??= [];
sourceResult.changes[map.sourceDocument.uri].push({
newText: (0, language_core_1.resolveRenameEditText)(tsEdit.newText, _data),
range,
for (const map of context.documents.getMaps(virtualCode)) {
const tsEdits = edit.changes[tsUri];
for (const tsEdit of tsEdits) {
if (mode === 'rename' || mode === 'fileName' || mode === 'codeAction') {
let _data;
const range = map.getSourceRange(tsEdit.range, data => {
_data = data;
return (0, language_core_1.isRenameEnabled)(data);
});
hasResult = true;
if (range) {
sourceResult.changes[map.sourceDocument.uri] ??= [];
sourceResult.changes[map.sourceDocument.uri].push({
newText: (0, language_core_1.resolveRenameEditText)(tsEdit.newText, _data),
range,
});
hasResult = true;
}
}
}
else {
const range = map.getSourceRange(tsEdit.range);
if (range) {
sourceResult.changes[map.sourceDocument.uri] ??= [];
sourceResult.changes[map.sourceDocument.uri].push({ newText: tsEdit.newText, range });
hasResult = true;
else {
const range = map.getSourceRange(tsEdit.range);
if (range) {
sourceResult.changes[map.sourceDocument.uri] ??= [];
sourceResult.changes[map.sourceDocument.uri].push({ newText: tsEdit.newText, range });
hasResult = true;
}
}

@@ -337,40 +343,41 @@ }

if (virtualCode) {
const map = context.documents.getSourceMap(virtualCode);
sourceEdit = {
textDocument: {
uri: map.sourceDocument.uri,
version: versions[map.sourceDocument.uri] ?? null,
},
edits: [],
};
for (const tsEdit of tsDocEdit.edits) {
if (mode === 'rename' || mode === 'fileName' || mode === 'codeAction') {
let _data;
const range = map.getSourceRange(tsEdit.range, data => {
_data = data;
// fix https://github.com/johnsoncodehk/volar/issues/1091
return (0, language_core_1.isRenameEnabled)(data);
});
if (range) {
sourceEdit.edits.push({
annotationId: 'annotationId' in tsEdit ? tsEdit.annotationId : undefined,
newText: (0, language_core_1.resolveRenameEditText)(tsEdit.newText, _data),
range,
for (const map of context.documents.getMaps(virtualCode)) {
sourceEdit = {
textDocument: {
uri: map.sourceDocument.uri,
version: versions[map.sourceDocument.uri] ?? null,
},
edits: [],
};
for (const tsEdit of tsDocEdit.edits) {
if (mode === 'rename' || mode === 'fileName' || mode === 'codeAction') {
let _data;
const range = map.getSourceRange(tsEdit.range, data => {
_data = data;
// fix https://github.com/johnsoncodehk/volar/issues/1091
return (0, language_core_1.isRenameEnabled)(data);
});
if (range) {
sourceEdit.edits.push({
annotationId: 'annotationId' in tsEdit ? tsEdit.annotationId : undefined,
newText: (0, language_core_1.resolveRenameEditText)(tsEdit.newText, _data),
range,
});
}
}
}
else {
const range = map.getSourceRange(tsEdit.range);
if (range) {
sourceEdit.edits.push({
annotationId: 'annotationId' in tsEdit ? tsEdit.annotationId : undefined,
newText: tsEdit.newText,
range,
});
else {
const range = map.getSourceRange(tsEdit.range);
if (range) {
sourceEdit.edits.push({
annotationId: 'annotationId' in tsEdit ? tsEdit.annotationId : undefined,
newText: tsEdit.newText,
range,
});
}
}
}
if (!sourceEdit.edits.length) {
sourceEdit = undefined;
}
}
if (!sourceEdit.edits.length) {
sourceEdit = undefined;
}
}

@@ -389,11 +396,12 @@ else {

if (virtualCode) {
const map = context.documents.getSourceMap(virtualCode);
// TODO: check capability?
sourceEdit = {
kind: 'rename',
oldUri: map.sourceDocument.uri,
newUri: tsDocEdit.newUri /* TODO: remove .ts? */,
options: tsDocEdit.options,
annotationId: tsDocEdit.annotationId,
};
for (const map of context.documents.getMaps(virtualCode)) {
// TODO: check capability?
sourceEdit = {
kind: 'rename',
oldUri: map.sourceDocument.uri,
newUri: tsDocEdit.newUri /* TODO: remove .ts? */,
options: tsDocEdit.options,
annotationId: tsDocEdit.annotationId,
};
}
}

@@ -409,10 +417,11 @@ else {

if (virtualCode) {
const map = context.documents.getSourceMap(virtualCode);
// TODO: check capability?
sourceEdit = {
kind: 'delete',
uri: map.sourceDocument.uri,
options: tsDocEdit.options,
annotationId: tsDocEdit.annotationId,
};
for (const map of context.documents.getMaps(virtualCode)) {
// TODO: check capability?
sourceEdit = {
kind: 'delete',
uri: map.sourceDocument.uri,
options: tsDocEdit.options,
annotationId: tsDocEdit.annotationId,
};
}
}

@@ -419,0 +428,0 @@ else {

{
"name": "@volar/language-service",
"version": "2.3.0-alpha.5",
"version": "2.3.0-alpha.6",
"license": "MIT",

@@ -15,3 +15,3 @@ "files": [

"dependencies": {
"@volar/language-core": "2.3.0-alpha.5",
"@volar/language-core": "2.3.0-alpha.6",
"vscode-languageserver-protocol": "^3.17.5",

@@ -21,3 +21,3 @@ "vscode-languageserver-textdocument": "^1.0.11",

},
"gitHead": "c3f6867de39095913ceaa2256ad35a9ca1a90487"
"gitHead": "f3103e86be8d80cb36f66be4c054ef9a255c29b1"
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc