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.4 to 2.3.0-alpha.5

24

lib/features/provideCallHierarchyItems.js

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

}
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 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) {
const vueRanges = tsRanges.map(tsRange => map.getSourceRange(tsRange)).filter(common_1.notEmpty);

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

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

}
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);
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;
}
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);
}

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

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

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

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

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

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

}
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 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 },
},
};
}
return;
else {
return;
}
}

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

@@ -207,13 +207,12 @@ "use strict";

if (virtualCode) {
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,
});
}
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,
});
}

@@ -220,0 +219,0 @@ }

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

const featureWorkers_1 = require("../utils/featureWorkers");
const uriMap_1 = require("../utils/uriMap");
function register(context) {

@@ -183,13 +182,5 @@ let fakeVersion = 0;

function createDocMap(virtualCode, documentUri, sourceLanguageId, _sourceSnapshot) {
const mapOfMap = (0, uriMap_1.createUriMap)();
(0, language_core_1.updateVirtualCodeMapOfMap)(virtualCode, mapOfMap, sourceFileUri2 => {
if (!sourceFileUri2) {
return [documentUri, _sourceSnapshot];
}
});
if (mapOfMap.has(documentUri) && mapOfMap.get(documentUri)[0] === _sourceSnapshot) {
const map = mapOfMap.get(documentUri);
const version = fakeVersion++;
return new documents_1.SourceMapWithDocuments(vscode_languageserver_textdocument_1.TextDocument.create(documentUri.toString(), sourceLanguageId, version, _sourceSnapshot.getText(0, _sourceSnapshot.getLength())), vscode_languageserver_textdocument_1.TextDocument.create(context.encodeEmbeddedDocumentUri(documentUri, virtualCode.id).toString(), virtualCode.languageId, version, virtualCode.snapshot.getText(0, virtualCode.snapshot.getLength())), map[1], virtualCode);
}
const map = new language_core_1.SourceMap(virtualCode.mappings);
const version = fakeVersion++;
return new documents_1.SourceMapWithDocuments(vscode_languageserver_textdocument_1.TextDocument.create(documentUri.toString(), sourceLanguageId, version, _sourceSnapshot.getText(0, _sourceSnapshot.getLength())), vscode_languageserver_textdocument_1.TextDocument.create(context.encodeEmbeddedDocumentUri(documentUri, virtualCode.id).toString(), virtualCode.languageId, version, virtualCode.snapshot.getText(0, virtualCode.snapshot.getLength())), map, virtualCode);
}

@@ -196,0 +187,0 @@ }

@@ -10,3 +10,4 @@ "use strict";

function register(context) {
return async (uri, range, legend, token = cancellation_1.NoneCancellationToken, _reportProgress) => {
return async (uri, range, legend, token = cancellation_1.NoneCancellationToken, _reportProgress // TODO
) => {
const sourceScript = context.language.scripts.get(uri);

@@ -51,3 +52,5 @@ if (!sourceScript) {

.filter(common_1.notEmpty);
}, tokens => tokens.flat());
}, tokens => tokens.flat()
// tokens => reportProgress?.(buildTokens(tokens)), // TODO: this has no effect with LSP
);
if (tokens) {

@@ -54,0 +57,0 @@ return buildTokens(tokens);

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

}
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;
}
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;
}

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

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

if (virtualCode) {
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,
});
}
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,
});
}

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

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

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

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

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

if (virtualCode) {
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);
}
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);
}

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

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

},
*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);
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));
}
return result;
},

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

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

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

@@ -55,0 +55,0 @@ };

@@ -8,3 +8,3 @@ import type * as vscode from 'vscode-languageserver-protocol';

export declare function withTextEdits<T extends vscode.TextEdit>(items: T[]): T[];
export declare function withDocumentChanges(items: NonNullable<vscode.WorkspaceEdit['documentChanges']>): (vscode.TextDocumentEdit | vscode.CreateFile | vscode.RenameFile | vscode.DeleteFile)[];
export declare function withDocumentChanges(items: NonNullable<vscode.WorkspaceEdit['documentChanges']>): (vscode.CreateFile | vscode.TextDocumentEdit | vscode.RenameFile | vscode.DeleteFile)[];
export declare function withDiagnostics<T extends vscode.Diagnostic>(items: T[]): T[];

@@ -11,0 +11,0 @@ export declare function withLocations<T extends vscode.Location>(items: T[]): T[];

@@ -92,7 +92,5 @@ "use strict";

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

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

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

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

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

});
break;
}

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

});
break;
}

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

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

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

if (virtualCode) {
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);
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,
});
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;
}
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;
}

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

if (virtualCode) {
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);
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,
});
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;
}
}

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

if (virtualCode) {
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,
};
}
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,
};
}

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

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

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

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

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

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

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

},
"gitHead": "8ab3ce02b06a410e9321eea3e9f23d36f97fedda"
"gitHead": "c3f6867de39095913ceaa2256ad35a9ca1a90487"
}
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