@volar/language-service
Advanced tools
Comparing version 1.4.0-alpha.0 to 1.4.0-alpha.1
@@ -20,3 +20,3 @@ import { LanguageServicePluginContext, LanguageServiceOptions } from './types'; | ||
getColorPresentations: (uri: string, color: _.Color, range: _.Range, token: _.CancellationToken) => Promise<_.ColorPresentation[] | undefined>; | ||
doValidation: (uri: string, token: _.CancellationToken, mode: "all" | "semantic" | "syntactic", response?: ((result: _.Diagnostic[]) => void) | undefined) => Promise<_.Diagnostic[]>; | ||
doValidation: (uri: string, token: _.CancellationToken, mode: "semantic" | "all" | "syntactic", response?: ((result: _.Diagnostic[]) => void) | undefined) => Promise<_.Diagnostic[]>; | ||
findReferences: (uri: string, position: _.Position, token: _.CancellationToken) => Promise<_.Location[] | undefined>; | ||
@@ -23,0 +23,0 @@ findFileReferences: (uri: string, token: _.CancellationToken) => import("./types").NullableResult<_.Location[]>; |
@@ -38,4 +38,3 @@ Object.defineProperty(exports, "__esModule", { value: true }); | ||
function createLanguageService(ctx, documentRegistry) { | ||
var _a; | ||
const languageContext = (0, language_core_1.createLanguageContext)(ctx.host, Object.values((_a = ctx.config.languages) !== null && _a !== void 0 ? _a : {}).filter(common_1.notEmpty)); | ||
const languageContext = (0, language_core_1.createLanguageContext)(ctx.host, Object.values(ctx.config.languages ?? {}).filter(common_1.notEmpty)); | ||
const context = createLanguageServiceContext(ctx, languageContext, documentRegistry); | ||
@@ -46,5 +45,4 @@ return createLanguageServiceBase(context); | ||
function createLanguageServiceContext(ctx, languageContext, documentRegistry) { | ||
var _a, _b, _c, _d; | ||
const ts = (_b = (_a = ctx.host).getTypeScriptModule) === null || _b === void 0 ? void 0 : _b.call(_a); | ||
const tsLs = ts === null || ts === void 0 ? void 0 : ts.createLanguageService(languageContext.typescript.languageServiceHost, documentRegistry); | ||
const ts = ctx.host.getTypeScriptModule?.(); | ||
const tsLs = ts?.createLanguageService(languageContext.typescript.languageServiceHost, documentRegistry); | ||
if (ts && tsLs) { | ||
@@ -56,9 +54,16 @@ tsFaster.decorate(ts, languageContext.typescript.languageServiceHost, tsLs); | ||
const documentVersions = new Map(); | ||
const context = Object.assign(Object.assign({}, ctx), { core: languageContext, plugins: {}, typescript: ts && tsLs ? { | ||
const context = { | ||
...ctx, | ||
core: languageContext, | ||
plugins: {}, | ||
typescript: ts && tsLs ? { | ||
module: ts, | ||
languageServiceHost: languageContext.typescript.languageServiceHost, | ||
languageService: tsLs, | ||
} : undefined, documents: textDocumentMapper, getTextDocument }); | ||
for (const pluginId in (_c = ctx.config.plugins) !== null && _c !== void 0 ? _c : {}) { | ||
const plugin = (_d = ctx.config.plugins) === null || _d === void 0 ? void 0 : _d[pluginId]; | ||
} : undefined, | ||
documents: textDocumentMapper, | ||
getTextDocument, | ||
}; | ||
for (const pluginId in ctx.config.plugins ?? {}) { | ||
const plugin = ctx.config.plugins?.[pluginId]; | ||
if (plugin instanceof Function) { | ||
@@ -74,3 +79,2 @@ const _plugin = plugin(context); | ||
function getTextDocument(uri) { | ||
var _a; | ||
const fileName = ctx.uriToFileName(uri); | ||
@@ -81,3 +85,3 @@ const scriptSnapshot = ctx.host.getScriptSnapshot(fileName); | ||
if (!document) { | ||
const newVersion = ((_a = documentVersions.get(uri.toLowerCase())) !== null && _a !== void 0 ? _a : 0) + 1; | ||
const newVersion = (documentVersions.get(uri.toLowerCase()) ?? 0) + 1; | ||
documentVersions.set(uri.toLowerCase(), newVersion); | ||
@@ -93,6 +97,6 @@ document = vscode_languageserver_textdocument_1.TextDocument.create(uri, (0, common_1.syntaxToLanguageId)(uri.substring(uri.lastIndexOf('.') + 1)), newVersion, scriptSnapshot.getText(0, scriptSnapshot.getLength())); | ||
return { | ||
triggerCharacters: Object.values(context.plugins).map(plugin => { var _a; return (_a = plugin === null || plugin === void 0 ? void 0 : plugin.triggerCharacters) !== null && _a !== void 0 ? _a : []; }).flat(), | ||
autoFormatTriggerCharacters: Object.values(context.plugins).map(plugin => { var _a; return (_a = plugin === null || plugin === void 0 ? void 0 : plugin.autoFormatTriggerCharacters) !== null && _a !== void 0 ? _a : []; }).flat(), | ||
signatureHelpTriggerCharacters: Object.values(context.plugins).map(plugin => { var _a; return (_a = plugin === null || plugin === void 0 ? void 0 : plugin.signatureHelpTriggerCharacters) !== null && _a !== void 0 ? _a : []; }).flat(), | ||
signatureHelpRetriggerCharacters: Object.values(context.plugins).map(plugin => { var _a; return (_a = plugin === null || plugin === void 0 ? void 0 : plugin.signatureHelpRetriggerCharacters) !== null && _a !== void 0 ? _a : []; }).flat(), | ||
triggerCharacters: Object.values(context.plugins).map(plugin => plugin?.triggerCharacters ?? []).flat(), | ||
autoFormatTriggerCharacters: Object.values(context.plugins).map(plugin => plugin?.autoFormatTriggerCharacters ?? []).flat(), | ||
signatureHelpTriggerCharacters: Object.values(context.plugins).map(plugin => plugin?.signatureHelpTriggerCharacters ?? []).flat(), | ||
signatureHelpRetriggerCharacters: Object.values(context.plugins).map(plugin => plugin?.signatureHelpRetriggerCharacters ?? []).flat(), | ||
format: format.register(context), | ||
@@ -129,3 +133,3 @@ getFoldingRanges: foldingRanges.register(context), | ||
callHierarchy: callHierarchy.register(context), | ||
dispose: () => { var _a; return (_a = context.typescript) === null || _a === void 0 ? void 0 : _a.languageService.dispose(); }, | ||
dispose: () => context.typescript?.languageService.dispose(), | ||
context, | ||
@@ -132,0 +136,0 @@ }; |
@@ -12,6 +12,5 @@ Object.defineProperty(exports, "__esModule", { value: true }); | ||
}, (plugin, document, range) => { | ||
var _a; | ||
if (token.isCancellationRequested) | ||
return; | ||
return (_a = plugin.provideColorPresentations) === null || _a === void 0 ? void 0 : _a.call(plugin, document, color, range, token); | ||
return plugin.provideColorPresentations?.(document, color, range, token); | ||
}, (data, map) => map ? data.map(cp => { | ||
@@ -18,0 +17,0 @@ if (cp.textEdit) { |
@@ -10,6 +10,5 @@ Object.defineProperty(exports, "__esModule", { value: true }); | ||
(plugin, document) => { | ||
var _a; | ||
if (token.isCancellationRequested) | ||
return; | ||
return (_a = plugin.provideDocumentColors) === null || _a === void 0 ? void 0 : _a.call(plugin, document, token); | ||
return plugin.provideDocumentColors?.(document, token); | ||
}, (data, map) => map ? data.map(color => { | ||
@@ -16,0 +15,0 @@ const range = map.toSourceRange(color.range); |
@@ -1,10 +0,1 @@ | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -17,8 +8,7 @@ exports.register = void 0; | ||
return (uri, token) => { | ||
return (0, featureWorkers_1.documentFeatureWorker)(context, uri, file => !!file.capabilities.documentSymbol, (plugin, document) => __awaiter(this, void 0, void 0, function* () { | ||
var _a; | ||
return (0, featureWorkers_1.documentFeatureWorker)(context, uri, file => !!file.capabilities.documentSymbol, async (plugin, document) => { | ||
if (token.isCancellationRequested) | ||
return; | ||
return (_a = plugin.provideDocumentSymbols) === null || _a === void 0 ? void 0 : _a.call(plugin, document, token); | ||
}), (data, map) => map | ||
return plugin.provideDocumentSymbols?.(document, token); | ||
}, (data, map) => map | ||
? data | ||
@@ -33,6 +23,5 @@ .map(symbol => transformer.asDocumentSymbol(symbol, range => map.toSourceRange(range))) | ||
results[i] = results[i].filter(child => { | ||
var _a; | ||
for (const parent of results[j]) { | ||
if ((0, common_1.isInsideRange)(parent.range, child.range)) { | ||
(_a = parent.children) !== null && _a !== void 0 ? _a : (parent.children = []); | ||
parent.children ??= []; | ||
parent.children.push(child); | ||
@@ -39,0 +28,0 @@ return false; |
@@ -8,6 +8,5 @@ Object.defineProperty(exports, "__esModule", { value: true }); | ||
return (0, featureWorkers_1.documentFeatureWorker)(context, uri, file => !!file.capabilities.foldingRange, (plugin, document) => { | ||
var _a; | ||
if (token.isCancellationRequested) | ||
return; | ||
return (_a = plugin.provideFoldingRanges) === null || _a === void 0 ? void 0 : _a.call(plugin, document, token); | ||
return plugin.provideFoldingRanges?.(document, token); | ||
}, (data, map) => map ? transformer.asFoldingRanges(data, range => map.toSourceRange(range)) : data, arr => arr.flat()); | ||
@@ -14,0 +13,0 @@ }; |
@@ -1,10 +0,1 @@ | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -16,15 +7,14 @@ exports.register = void 0; | ||
function register(context) { | ||
return (uri, options, range, onTypeParams, token) => __awaiter(this, void 0, void 0, function* () { | ||
var _a, _b, _c; | ||
return async (uri, options, range, onTypeParams, token) => { | ||
let document = context.getTextDocument(uri); | ||
if (!document) | ||
return; | ||
range !== null && range !== void 0 ? range : (range = vscode.Range.create(document.positionAt(0), document.positionAt(document.getText().length))); | ||
range ??= vscode.Range.create(document.positionAt(0), document.positionAt(document.getText().length)); | ||
const source = context.documents.getSourceByUri(document.uri); | ||
if (!source) { | ||
return onTypeParams | ||
? yield tryFormat(document, onTypeParams.position, onTypeParams.ch) | ||
: yield tryFormat(document, range, undefined); | ||
? await tryFormat(document, onTypeParams.position, onTypeParams.ch) | ||
: await tryFormat(document, range, undefined); | ||
} | ||
const initialIndentLanguageId = (_b = yield ((_a = context.configurationHost) === null || _a === void 0 ? void 0 : _a.getConfiguration('volar.format.initialIndent'))) !== null && _b !== void 0 ? _b : { html: true }; | ||
const initialIndentLanguageId = await context.configurationHost?.getConfiguration('volar.format.initialIndent') ?? { html: true }; | ||
const originalSnapshot = source.snapshot; | ||
@@ -48,3 +38,3 @@ const rootVirtualFile = source.root; | ||
const maps = [...context.documents.getMapsByVirtualFileName(embedded.fileName)]; | ||
const map = (_c = maps.find(map => map[1].sourceFileDocument.uri === document.uri)) === null || _c === void 0 ? void 0 : _c[1]; | ||
const map = maps.find(map => map[1].sourceFileDocument.uri === document.uri)?.[1]; | ||
if (!map) | ||
@@ -56,7 +46,7 @@ continue; | ||
if (embeddedPosition) { | ||
virtualCodeEdits = yield tryFormat(map.virtualFileDocument, embeddedPosition, onTypeParams.ch); | ||
virtualCodeEdits = await tryFormat(map.virtualFileDocument, embeddedPosition, onTypeParams.ch); | ||
} | ||
} | ||
else { | ||
virtualCodeEdits = yield tryFormat(map.virtualFileDocument, { | ||
virtualCodeEdits = await tryFormat(map.virtualFileDocument, { | ||
start: map.virtualFileDocument.positionAt(0), | ||
@@ -106,3 +96,3 @@ end: map.virtualFileDocument.positionAt(map.virtualFileDocument.getText().length), | ||
if (plugin.provideFormattingIndentSensitiveLines) { | ||
const lines = yield plugin.provideFormattingIndentSensitiveLines(map.virtualFileDocument, token); | ||
const lines = await plugin.provideFormattingIndentSensitiveLines(map.virtualFileDocument, token); | ||
if (lines) { | ||
@@ -161,30 +151,27 @@ for (const line of lines) { | ||
} | ||
function tryFormat(document, range, ch) { | ||
var _a, _b, _c; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
let formatRange = range; | ||
for (const plugin of Object.values(context.plugins)) { | ||
if (token.isCancellationRequested) | ||
break; | ||
let edits; | ||
try { | ||
if (ch !== undefined && vscode.Position.is(formatRange)) { | ||
if ((_a = plugin.autoFormatTriggerCharacters) === null || _a === void 0 ? void 0 : _a.includes(ch)) { | ||
edits = yield ((_b = plugin.provideOnTypeFormattingEdits) === null || _b === void 0 ? void 0 : _b.call(plugin, document, formatRange, ch, options, token)); | ||
} | ||
async function tryFormat(document, range, ch) { | ||
let formatRange = range; | ||
for (const plugin of Object.values(context.plugins)) { | ||
if (token.isCancellationRequested) | ||
break; | ||
let edits; | ||
try { | ||
if (ch !== undefined && vscode.Position.is(formatRange)) { | ||
if (plugin.autoFormatTriggerCharacters?.includes(ch)) { | ||
edits = await plugin.provideOnTypeFormattingEdits?.(document, formatRange, ch, options, token); | ||
} | ||
else if (ch === undefined && vscode.Range.is(formatRange)) { | ||
edits = yield ((_c = plugin.provideDocumentFormattingEdits) === null || _c === void 0 ? void 0 : _c.call(plugin, document, formatRange, options, token)); | ||
} | ||
} | ||
catch (err) { | ||
console.warn(err); | ||
else if (ch === undefined && vscode.Range.is(formatRange)) { | ||
edits = await plugin.provideDocumentFormattingEdits?.(document, formatRange, options, token); | ||
} | ||
if (!edits) | ||
continue; | ||
return edits; | ||
} | ||
}); | ||
catch (err) { | ||
console.warn(err); | ||
} | ||
if (!edits) | ||
continue; | ||
return edits; | ||
} | ||
} | ||
}); | ||
}; | ||
} | ||
@@ -191,0 +178,0 @@ exports.register = register; |
@@ -8,6 +8,5 @@ Object.defineProperty(exports, "__esModule", { value: true }); | ||
return (0, featureWorkers_1.languageFeatureWorker)(context, uri, position, (position, map) => map.toGeneratedPositions(position, data => !!data.completion), (plugin, document, position) => { | ||
var _a; | ||
if (token.isCancellationRequested) | ||
return; | ||
return (_a = plugin.provideLinkedEditingRanges) === null || _a === void 0 ? void 0 : _a.call(plugin, document, position, token); | ||
return plugin.provideLinkedEditingRanges?.(document, position, token); | ||
}, (data, map) => map ? ({ | ||
@@ -14,0 +13,0 @@ wordPattern: data.wordPattern, |
@@ -19,6 +19,5 @@ Object.defineProperty(exports, "__esModule", { value: true }); | ||
}, (plugin, document, positions) => { | ||
var _a; | ||
if (token.isCancellationRequested) | ||
return; | ||
return (_a = plugin.provideSelectionRanges) === null || _a === void 0 ? void 0 : _a.call(plugin, document, positions, token); | ||
return plugin.provideSelectionRanges?.(document, positions, token); | ||
}, (item, map) => map ? transformer.asSelectionRanges(item, range => map.toSourceRange(range)) : item, results => { | ||
@@ -25,0 +24,0 @@ for (let i = 0; i < results[0].length; i++) { |
@@ -179,3 +179,2 @@ Object.defineProperty(exports, "__esModule", { value: true }); | ||
*getMapsByVirtualFileName(virtualFileName) { | ||
var _a; | ||
const [virtualFile] = mapper.getVirtualFile(virtualFileName); | ||
@@ -185,3 +184,3 @@ if (virtualFile) { | ||
if (!_maps.has(map)) { | ||
const sourceSnapshot = (_a = mapper.getSource(sourceFileName)) === null || _a === void 0 ? void 0 : _a.snapshot; | ||
const sourceSnapshot = mapper.getSource(sourceFileName)?.snapshot; | ||
if (sourceSnapshot) { | ||
@@ -188,0 +187,0 @@ _maps.set(map, [virtualFile, new SourceMapWithDocuments(getDocumentByFileName(sourceSnapshot, sourceFileName), getDocumentByFileName(virtualFile.snapshot, virtualFileName), map)]); |
@@ -7,5 +7,4 @@ Object.defineProperty(exports, "__esModule", { value: true }); | ||
return (0, featureWorkers_1.languageFeatureWorker)(context, uri, { position, autoInsertContext }, function* (arg, map) { | ||
var _a; | ||
for (const position of map.toGeneratedPositions(arg.position, data => !!data.completion)) { | ||
const rangeOffset = (_a = map.map.toGeneratedOffset(arg.autoInsertContext.lastChange.rangeOffset)) === null || _a === void 0 ? void 0 : _a[0]; | ||
const rangeOffset = map.map.toGeneratedOffset(arg.autoInsertContext.lastChange.rangeOffset)?.[0]; | ||
const range = map.toGeneratedRange(arg.autoInsertContext.lastChange.range); | ||
@@ -16,4 +15,7 @@ if (rangeOffset !== undefined && range) { | ||
autoInsertContext: { | ||
lastChange: Object.assign(Object.assign({}, arg.autoInsertContext.lastChange), { rangeOffset, | ||
range }), | ||
lastChange: { | ||
...arg.autoInsertContext.lastChange, | ||
rangeOffset, | ||
range, | ||
}, | ||
}, | ||
@@ -25,6 +27,5 @@ }; | ||
}, (plugin, document, arg) => { | ||
var _a; | ||
if (token.isCancellationRequested) | ||
return; | ||
return (_a = plugin.provideAutoInsertionEdit) === null || _a === void 0 ? void 0 : _a.call(plugin, document, arg.position, arg.autoInsertContext, token); | ||
return plugin.provideAutoInsertionEdit?.(document, arg.position, arg.autoInsertContext, token); | ||
}, (item, map) => { | ||
@@ -31,0 +32,0 @@ if (!map || typeof item === 'string') |
@@ -1,10 +0,1 @@ | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -19,8 +10,7 @@ exports.register = void 0; | ||
doPrepare(uri, position, token) { | ||
return (0, featureWorkers_1.languageFeatureWorker)(context, uri, position, (position, map) => map.toGeneratedPositions(position, data => !!data.references), (plugin, document, position, map) => __awaiter(this, void 0, void 0, function* () { | ||
var _a; | ||
return (0, featureWorkers_1.languageFeatureWorker)(context, uri, position, (position, map) => map.toGeneratedPositions(position, data => !!data.references), async (plugin, document, position, map) => { | ||
if (token.isCancellationRequested) | ||
return; | ||
const items = yield ((_a = plugin.provideCallHierarchyItems) === null || _a === void 0 ? void 0 : _a.call(plugin, document, position, token)); | ||
items === null || items === void 0 ? void 0 : items.forEach(item => { | ||
const items = await plugin.provideCallHierarchyItems?.(document, position, token); | ||
items?.forEach(item => { | ||
item.data = { | ||
@@ -38,31 +28,17 @@ uri, | ||
return items; | ||
}), (data, sourceMap) => !sourceMap ? data : data | ||
.map(item => { var _a; return (_a = transformCallHierarchyItem(item, [])) === null || _a === void 0 ? void 0 : _a[0]; }) | ||
}, (data, sourceMap) => !sourceMap ? data : data | ||
.map(item => transformCallHierarchyItem(item, [])?.[0]) | ||
.filter(common_1.notEmpty), arr => dedupe.withLocations(arr.flat())); | ||
}, | ||
getIncomingCalls(item, token) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const data = item.data; | ||
let incomingItems = []; | ||
if (data) { | ||
const plugin = context.plugins[data.pluginId]; | ||
if (!plugin.provideCallHierarchyIncomingCalls) | ||
return incomingItems; | ||
Object.assign(item, data.original); | ||
if (data.map) { | ||
if (context.documents.hasVirtualFileByUri(data.map.embeddedDocumentUri)) { | ||
const _calls = yield plugin.provideCallHierarchyIncomingCalls(item, token); | ||
for (const _call of _calls) { | ||
const calls = transformCallHierarchyItem(_call.from, _call.fromRanges); | ||
if (!calls) | ||
continue; | ||
incomingItems.push({ | ||
from: calls[0], | ||
fromRanges: calls[1], | ||
}); | ||
} | ||
} | ||
} | ||
else { | ||
const _calls = yield plugin.provideCallHierarchyIncomingCalls(item, token); | ||
async getIncomingCalls(item, token) { | ||
const data = item.data; | ||
let incomingItems = []; | ||
if (data) { | ||
const plugin = context.plugins[data.pluginId]; | ||
if (!plugin.provideCallHierarchyIncomingCalls) | ||
return incomingItems; | ||
Object.assign(item, data.original); | ||
if (data.map) { | ||
if (context.documents.hasVirtualFileByUri(data.map.embeddedDocumentUri)) { | ||
const _calls = await plugin.provideCallHierarchyIncomingCalls(item, token); | ||
for (const _call of _calls) { | ||
@@ -79,30 +55,28 @@ const calls = transformCallHierarchyItem(_call.from, _call.fromRanges); | ||
} | ||
return dedupe.withCallHierarchyIncomingCalls(incomingItems); | ||
}); | ||
else { | ||
const _calls = await plugin.provideCallHierarchyIncomingCalls(item, token); | ||
for (const _call of _calls) { | ||
const calls = transformCallHierarchyItem(_call.from, _call.fromRanges); | ||
if (!calls) | ||
continue; | ||
incomingItems.push({ | ||
from: calls[0], | ||
fromRanges: calls[1], | ||
}); | ||
} | ||
} | ||
} | ||
return dedupe.withCallHierarchyIncomingCalls(incomingItems); | ||
}, | ||
getOutgoingCalls(item, token) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const data = item.data; | ||
let items = []; | ||
if (data) { | ||
const plugin = context.plugins[data.pluginId]; | ||
if (!plugin.provideCallHierarchyOutgoingCalls) | ||
return items; | ||
Object.assign(item, data.original); | ||
if (data.map) { | ||
if (context.documents.hasVirtualFileByUri(data.map.embeddedDocumentUri)) { | ||
const _calls = yield plugin.provideCallHierarchyOutgoingCalls(item, token); | ||
for (const call of _calls) { | ||
const calls = transformCallHierarchyItem(call.to, call.fromRanges); | ||
if (!calls) | ||
continue; | ||
items.push({ | ||
to: calls[0], | ||
fromRanges: calls[1], | ||
}); | ||
} | ||
} | ||
} | ||
else { | ||
const _calls = yield plugin.provideCallHierarchyOutgoingCalls(item, token); | ||
async getOutgoingCalls(item, token) { | ||
const data = item.data; | ||
let items = []; | ||
if (data) { | ||
const plugin = context.plugins[data.pluginId]; | ||
if (!plugin.provideCallHierarchyOutgoingCalls) | ||
return items; | ||
Object.assign(item, data.original); | ||
if (data.map) { | ||
if (context.documents.hasVirtualFileByUri(data.map.embeddedDocumentUri)) { | ||
const _calls = await plugin.provideCallHierarchyOutgoingCalls(item, token); | ||
for (const call of _calls) { | ||
@@ -119,4 +93,16 @@ const calls = transformCallHierarchyItem(call.to, call.fromRanges); | ||
} | ||
return dedupe.withCallHierarchyOutgoingCalls(items); | ||
}); | ||
else { | ||
const _calls = await plugin.provideCallHierarchyOutgoingCalls(item, token); | ||
for (const call of _calls) { | ||
const calls = transformCallHierarchyItem(call.to, call.fromRanges); | ||
if (!calls) | ||
continue; | ||
items.push({ | ||
to: calls[0], | ||
fromRanges: calls[1], | ||
}); | ||
} | ||
} | ||
} | ||
return dedupe.withCallHierarchyOutgoingCalls(items); | ||
}, | ||
@@ -140,3 +126,6 @@ }; | ||
const vueRanges = tsRanges.map(tsRange => map.toSourceRange(tsRange)).filter(common_1.notEmpty); | ||
const vueItem = Object.assign(Object.assign({}, tsItem), { name: tsItem.name === path_1.posix.basename(context.uriToFileName(map.virtualFileDocument.uri)) ? path_1.posix.basename(context.uriToFileName(map.sourceFileDocument.uri)) : tsItem.name, uri: map.sourceFileDocument.uri, | ||
const vueItem = { | ||
...tsItem, | ||
name: tsItem.name === path_1.posix.basename(context.uriToFileName(map.virtualFileDocument.uri)) ? path_1.posix.basename(context.uriToFileName(map.sourceFileDocument.uri)) : tsItem.name, | ||
uri: map.sourceFileDocument.uri, | ||
// TS Bug: `range: range` not works | ||
@@ -146,6 +135,8 @@ range: { | ||
end: range.end, | ||
}, selectionRange: { | ||
}, | ||
selectionRange: { | ||
start: selectionRange.start, | ||
end: selectionRange.end, | ||
} }); | ||
}, | ||
}; | ||
selectionRange.end; | ||
@@ -152,0 +143,0 @@ return [vueItem, vueRanges]; |
@@ -1,10 +0,1 @@ | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -14,6 +5,5 @@ exports.register = void 0; | ||
function register(context) { | ||
return (item, token) => __awaiter(this, void 0, void 0, function* () { | ||
var _a, _b, _c, _d, _e, _f; | ||
return async (item, token) => { | ||
const data = item.data; | ||
if ((data === null || data === void 0 ? void 0 : data.type) === 'plugin') { | ||
if (data?.type === 'plugin') { | ||
const plugin = context.plugins[data.pluginId]; | ||
@@ -23,3 +13,3 @@ if (!plugin.resolveCodeAction) | ||
Object.assign(item, data.original); | ||
item = yield plugin.resolveCodeAction(item, token); | ||
item = await plugin.resolveCodeAction(item, token); | ||
if (item.edit) { | ||
@@ -29,9 +19,9 @@ item.edit = (0, rename_1.embeddedEditToSourceEdit)(item.edit, context.documents, 'codeAction', { [data.uri]: data.version }); | ||
} | ||
if ((data === null || data === void 0 ? void 0 : data.type) === 'rule') { | ||
const fixes = (_c = (_b = (_a = context.ruleFixes) === null || _a === void 0 ? void 0 : _a[data.documentUri]) === null || _b === void 0 ? void 0 : _b[data.ruleId]) === null || _c === void 0 ? void 0 : _c[data.ruleFixIndex]; | ||
const fix = fixes === null || fixes === void 0 ? void 0 : fixes[1][data.index]; | ||
if (data?.type === 'rule') { | ||
const fixes = context.ruleFixes?.[data.documentUri]?.[data.ruleId]?.[data.ruleFixIndex]; | ||
const fix = fixes?.[1][data.index]; | ||
if (fix) { | ||
let edit = (_e = yield ((_d = fix.getWorkspaceEdit) === null || _d === void 0 ? void 0 : _d.call(fix, fixes[0]))) !== null && _e !== void 0 ? _e : undefined; | ||
let edit = await fix.getWorkspaceEdit?.(fixes[0]) ?? undefined; | ||
if (!edit) { | ||
const edits = yield ((_f = fix.getEdits) === null || _f === void 0 ? void 0 : _f.call(fix, fixes[0])); | ||
const edits = await fix.getEdits?.(fixes[0]); | ||
if (edits) { | ||
@@ -55,5 +45,5 @@ edit = { | ||
return item; | ||
}); | ||
}; | ||
} | ||
exports.register = register; | ||
//# sourceMappingURL=codeActionResolve.js.map |
@@ -1,10 +0,1 @@ | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -19,4 +10,3 @@ exports.register = void 0; | ||
function register(context) { | ||
return (uri, range, codeActionContext, token) => __awaiter(this, void 0, void 0, function* () { | ||
var _a, _b, _c, _d, _e; | ||
return async (uri, range, codeActionContext, token) => { | ||
const sourceDocument = context.getTextDocument(uri); | ||
@@ -29,4 +19,3 @@ if (!sourceDocument) | ||
}; | ||
const pluginActions = yield (0, featureWorkers_1.languageFeatureWorker)(context, uri, { range, codeActionContext }, (_arg, map, file) => { | ||
var _a, _b; | ||
const pluginActions = await (0, featureWorkers_1.languageFeatureWorker)(context, uri, { range, codeActionContext }, (_arg, map, file) => { | ||
if (!file.capabilities.codeAction) | ||
@@ -43,4 +32,4 @@ return []; | ||
if (overlapRange) { | ||
const start = (_a = map.map.toGeneratedOffset(overlapRange.start)) === null || _a === void 0 ? void 0 : _a[0]; | ||
const end = (_b = map.map.toGeneratedOffset(overlapRange.end)) === null || _b === void 0 ? void 0 : _b[0]; | ||
const start = map.map.toGeneratedOffset(overlapRange.start)?.[0]; | ||
const end = map.map.toGeneratedOffset(overlapRange.end)?.[0]; | ||
if (start !== undefined && end !== undefined) { | ||
@@ -59,4 +48,3 @@ minStart = minStart === undefined ? start : Math.min(start, minStart); | ||
return []; | ||
}, (plugin, document, { range, codeActionContext }) => __awaiter(this, void 0, void 0, function* () { | ||
var _f; | ||
}, async (plugin, document, { range, codeActionContext }) => { | ||
if (token.isCancellationRequested) | ||
@@ -71,9 +59,15 @@ return; | ||
} | ||
return (data === null || data === void 0 ? void 0 : data.type) === 'plugin' && (data === null || data === void 0 ? void 0 : data.pluginOrRuleId) === pluginId; | ||
return data?.type === 'plugin' && data?.pluginOrRuleId === pluginId; | ||
}).map(diagnostic => { | ||
const data = diagnostic.data; | ||
return Object.assign(Object.assign({}, diagnostic), data.original); | ||
return { | ||
...diagnostic, | ||
...data.original, | ||
}; | ||
}); | ||
const codeActions = yield ((_f = plugin.provideCodeActions) === null || _f === void 0 ? void 0 : _f.call(plugin, document, range, Object.assign(Object.assign({}, codeActionContext), { diagnostics }), token)); | ||
codeActions === null || codeActions === void 0 ? void 0 : codeActions.forEach(codeAction => { | ||
const codeActions = await plugin.provideCodeActions?.(document, range, { | ||
...codeActionContext, | ||
diagnostics, | ||
}, token); | ||
codeActions?.forEach(codeAction => { | ||
codeAction.data = { | ||
@@ -91,3 +85,3 @@ uri, | ||
return codeActions; | ||
}), (_codeActions, sourceMap) => _codeActions.map(_codeAction => { | ||
}, (_codeActions, sourceMap) => _codeActions.map(_codeAction => { | ||
if (!sourceMap) | ||
@@ -113,4 +107,4 @@ return _codeAction; | ||
} | ||
if ((data === null || data === void 0 ? void 0 : data.type) === 'rule') { | ||
const fixes = (_c = (_b = (_a = context.ruleFixes) === null || _a === void 0 ? void 0 : _a[data.documentUri]) === null || _b === void 0 ? void 0 : _b[data.pluginOrRuleId]) === null || _c === void 0 ? void 0 : _c[data.ruleFixIndex]; | ||
if (data?.type === 'rule') { | ||
const fixes = context.ruleFixes?.[data.documentUri]?.[data.pluginOrRuleId]?.[data.ruleFixIndex]; | ||
if (fixes) { | ||
@@ -124,3 +118,3 @@ for (let i = 0; i < fixes[1].length; i++) { | ||
else { | ||
for (const kind of (_d = fix.kinds) !== null && _d !== void 0 ? _d : ['quickfix']) { | ||
for (const kind of fix.kinds ?? ['quickfix']) { | ||
const matchOnly = matchOnlyKind(codeActionContext.only, kind); | ||
@@ -134,3 +128,3 @@ if (matchOnly) { | ||
const action = { | ||
title: (_e = fix.title) !== null && _e !== void 0 ? _e : `Fix: ${diagnostic.message}`, | ||
title: fix.title ?? `Fix: ${diagnostic.message}`, | ||
kind: matchKind, | ||
@@ -156,6 +150,6 @@ diagnostics: [diagnostic], | ||
return [ | ||
...pluginActions !== null && pluginActions !== void 0 ? pluginActions : [], | ||
...pluginActions ?? [], | ||
...ruleActions, | ||
]; | ||
}); | ||
}; | ||
} | ||
@@ -162,0 +156,0 @@ exports.register = register; |
@@ -1,10 +0,1 @@ | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -16,12 +7,10 @@ exports.register = void 0; | ||
function register(context) { | ||
return (uri, token) => __awaiter(this, void 0, void 0, function* () { | ||
var _a, _b, _c; | ||
const referencesCodeLendsEnabled = (_b = yield ((_a = context.configurationHost) === null || _a === void 0 ? void 0 : _a.getConfiguration('volar.codeLens.references'))) !== null && _b !== void 0 ? _b : true; | ||
return (_c = yield (0, featureWorkers_1.languageFeatureWorker)(context, uri, undefined, (arg) => [arg], (plugin, document) => __awaiter(this, void 0, void 0, function* () { | ||
var _d, _e; | ||
return async (uri, token) => { | ||
const referencesCodeLendsEnabled = await context.configurationHost?.getConfiguration('volar.codeLens.references') ?? true; | ||
return await (0, featureWorkers_1.languageFeatureWorker)(context, uri, undefined, (arg) => [arg], async (plugin, document) => { | ||
if (token.isCancellationRequested) | ||
return; | ||
let codeLens = yield ((_d = plugin.provideCodeLenses) === null || _d === void 0 ? void 0 : _d.call(plugin, document, token)); | ||
let codeLens = await plugin.provideCodeLenses?.(document, token); | ||
const pluginId = Object.keys(context.plugins).find(key => context.plugins[key] === plugin); | ||
codeLens === null || codeLens === void 0 ? void 0 : codeLens.forEach(codeLens => { | ||
codeLens?.forEach(codeLens => { | ||
codeLens.data = { | ||
@@ -37,4 +26,4 @@ kind: 'normal', | ||
if (referencesCodeLendsEnabled) { | ||
const referencesCodeLensLocs = yield ((_e = plugin.provideReferencesCodeLenses) === null || _e === void 0 ? void 0 : _e.call(plugin, document, token)); | ||
const referencesCodeLens = referencesCodeLensLocs === null || referencesCodeLensLocs === void 0 ? void 0 : referencesCodeLensLocs.map(loc => vscode.CodeLens.create(loc.range, { | ||
const referencesCodeLensLocs = await plugin.provideReferencesCodeLenses?.(document, token); | ||
const referencesCodeLens = referencesCodeLensLocs?.map(loc => vscode.CodeLens.create(loc.range, { | ||
kind: 'references', | ||
@@ -46,8 +35,8 @@ uri, | ||
codeLens = [ | ||
...codeLens !== null && codeLens !== void 0 ? codeLens : [], | ||
...referencesCodeLens !== null && referencesCodeLens !== void 0 ? referencesCodeLens : [], | ||
...codeLens ?? [], | ||
...referencesCodeLens ?? [], | ||
]; | ||
} | ||
return codeLens; | ||
}), (data, map) => data.map(codeLens => { | ||
}, (data, map) => data.map(codeLens => { | ||
if (!map) | ||
@@ -57,8 +46,11 @@ return codeLens; | ||
if (range) { | ||
return Object.assign(Object.assign({}, codeLens), { range }); | ||
return { | ||
...codeLens, | ||
range, | ||
}; | ||
} | ||
}).filter(common_1.notEmpty), arr => arr.flat())) !== null && _c !== void 0 ? _c : []; | ||
}); | ||
}).filter(common_1.notEmpty), arr => arr.flat()) ?? []; | ||
}; | ||
} | ||
exports.register = register; | ||
//# sourceMappingURL=codeLens.js.map |
@@ -1,10 +0,1 @@ | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -16,6 +7,5 @@ exports.register = exports.showReferencesCommand = void 0; | ||
const findReferences = references.register(context); | ||
return (item, token) => __awaiter(this, void 0, void 0, function* () { | ||
var _a; | ||
return async (item, token) => { | ||
const data = item.data; | ||
if ((data === null || data === void 0 ? void 0 : data.kind) === 'normal') { | ||
if (data?.kind === 'normal') { | ||
const plugin = context.plugins[data.pluginId]; | ||
@@ -25,11 +15,11 @@ if (!plugin.resolveCodeLens) | ||
Object.assign(item, data.original); | ||
item = yield plugin.resolveCodeLens(item, token); | ||
item = await plugin.resolveCodeLens(item, token); | ||
// item.range already transformed in codeLens request | ||
} | ||
if ((data === null || data === void 0 ? void 0 : data.kind) === 'references') { | ||
let references = (_a = yield findReferences(data.uri, item.range.start, token)) !== null && _a !== void 0 ? _a : []; | ||
if (data?.kind === 'references') { | ||
let references = await findReferences(data.uri, item.range.start, token) ?? []; | ||
const plugin = context.plugins[data.pluginId]; | ||
const document = context.getTextDocument(data.uri); | ||
if (document && plugin.resolveReferencesCodeLens) { | ||
references = yield plugin.resolveReferencesCodeLens(document, data.location, references, token); | ||
references = await plugin.resolveReferencesCodeLens(document, data.location, references, token); | ||
} | ||
@@ -43,5 +33,5 @@ item.command = { | ||
return item; | ||
}); | ||
}; | ||
} | ||
exports.register = register; | ||
//# sourceMappingURL=codeLensResolve.js.map |
@@ -1,10 +0,1 @@ | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -17,10 +8,9 @@ exports.register = void 0; | ||
let cache; | ||
return (uri, position, completionContext, token) => __awaiter(this, void 0, void 0, function* () { | ||
var _a, _b; | ||
completionContext !== null && completionContext !== void 0 ? completionContext : (completionContext = { | ||
return async (uri, position, completionContext, token) => { | ||
completionContext ??= { | ||
triggerKind: vscode.CompletionTriggerKind.Invoked, | ||
}); | ||
}; | ||
let document; | ||
if ((completionContext === null || completionContext === void 0 ? void 0 : completionContext.triggerKind) === vscode.CompletionTriggerKind.TriggerForIncompleteCompletions | ||
&& (cache === null || cache === void 0 ? void 0 : cache.uri) === uri) { | ||
if (completionContext?.triggerKind === vscode.CompletionTriggerKind.TriggerForIncompleteCompletions | ||
&& cache?.uri === uri) { | ||
for (const cacheData of cache.data) { | ||
@@ -34,3 +24,3 @@ if (!cacheData.list.isIncomplete) | ||
continue; | ||
const embeddedCompletionList = yield cacheData.plugin.provideCompletionItems(map.virtualFileDocument, mapped, completionContext, token); | ||
const embeddedCompletionList = await cacheData.plugin.provideCompletionItems(map.virtualFileDocument, mapped, completionContext, token); | ||
if (!embeddedCompletionList) { | ||
@@ -58,3 +48,3 @@ cacheData.list.isIncomplete = false; | ||
continue; | ||
const completionList = yield cacheData.plugin.provideCompletionItems(document, position, completionContext, token); | ||
const completionList = await cacheData.plugin.provideCompletionItems(document, position, completionContext, token); | ||
if (!completionList) { | ||
@@ -80,3 +70,3 @@ cacheData.list.isIncomplete = false; | ||
else { | ||
const rootFile = (_a = context.documents.getSourceByUri(uri)) === null || _a === void 0 ? void 0 : _a.root; | ||
const rootFile = context.documents.getSourceByUri(uri)?.root; | ||
cache = { | ||
@@ -90,4 +80,3 @@ uri, | ||
if (rootFile) { | ||
yield (0, definePlugin_1.visitEmbedded)(context.documents, rootFile, (_, map) => __awaiter(this, void 0, void 0, function* () { | ||
var _c; | ||
await (0, definePlugin_1.visitEmbedded)(context.documents, rootFile, async (_, map) => { | ||
const plugins = Object.values(context.plugins).sort(sortPlugins); | ||
@@ -106,14 +95,14 @@ let _data; | ||
continue; | ||
if ((completionContext === null || completionContext === void 0 ? void 0 : completionContext.triggerCharacter) && !((_c = plugin.triggerCharacters) === null || _c === void 0 ? void 0 : _c.includes(completionContext.triggerCharacter))) | ||
if (completionContext?.triggerCharacter && !plugin.triggerCharacters?.includes(completionContext.triggerCharacter)) | ||
continue; | ||
const isAdditional = _data && typeof _data.completion === 'object' && _data.completion.additional || plugin.isAdditionalCompletion; | ||
if (cache.mainCompletion && (!isAdditional || (cache === null || cache === void 0 ? void 0 : cache.mainCompletion.documentUri) !== map.virtualFileDocument.uri)) | ||
if (cache.mainCompletion && (!isAdditional || cache?.mainCompletion.documentUri !== map.virtualFileDocument.uri)) | ||
continue; | ||
// avoid duplicate items with .vue and .vue.html | ||
if (plugin.isAdditionalCompletion && (cache === null || cache === void 0 ? void 0 : cache.data.some(data => data.plugin === plugin))) | ||
if (plugin.isAdditionalCompletion && cache?.data.some(data => data.plugin === plugin)) | ||
continue; | ||
const embeddedCompletionList = yield plugin.provideCompletionItems(map.virtualFileDocument, mapped, completionContext, token); | ||
const embeddedCompletionList = await plugin.provideCompletionItems(map.virtualFileDocument, mapped, completionContext, token); | ||
if (!embeddedCompletionList || !embeddedCompletionList.items.length) | ||
continue; | ||
if (typeof (_data === null || _data === void 0 ? void 0 : _data.completion) === 'object' && _data.completion.autoImportOnly) { | ||
if (typeof _data?.completion === 'object' && _data.completion.autoImportOnly) { | ||
embeddedCompletionList.items = embeddedCompletionList.items.filter(item => !!item.labelDetails); | ||
@@ -147,3 +136,3 @@ } | ||
return true; | ||
})); | ||
}); | ||
} | ||
@@ -159,3 +148,3 @@ if (document = context.getTextDocument(uri)) { | ||
continue; | ||
if ((completionContext === null || completionContext === void 0 ? void 0 : completionContext.triggerCharacter) && !((_b = plugin.triggerCharacters) === null || _b === void 0 ? void 0 : _b.includes(completionContext.triggerCharacter))) | ||
if (completionContext?.triggerCharacter && !plugin.triggerCharacters?.includes(completionContext.triggerCharacter)) | ||
continue; | ||
@@ -165,5 +154,5 @@ if (cache.mainCompletion && (!plugin.isAdditionalCompletion || cache.mainCompletion.documentUri !== document.uri)) | ||
// avoid duplicate items with .vue and .vue.html | ||
if (plugin.isAdditionalCompletion && (cache === null || cache === void 0 ? void 0 : cache.data.some(data => data.plugin === plugin))) | ||
if (plugin.isAdditionalCompletion && cache?.data.some(data => data.plugin === plugin)) | ||
continue; | ||
const completionList = yield plugin.provideCompletionItems(document, position, completionContext, token); | ||
const completionList = await plugin.provideCompletionItems(document, position, completionContext, token); | ||
if (!completionList || !completionList.items.length) | ||
@@ -199,12 +188,11 @@ continue; | ||
function combineCompletionList(lists) { | ||
var _a; | ||
return { | ||
isIncomplete: lists.some(list => list.isIncomplete), | ||
itemDefaults: (_a = lists.find(list => list.itemDefaults)) === null || _a === void 0 ? void 0 : _a.itemDefaults, | ||
itemDefaults: lists.find(list => list.itemDefaults)?.itemDefaults, | ||
items: lists.map(list => list.items).flat(), | ||
}; | ||
} | ||
}); | ||
}; | ||
} | ||
exports.register = register; | ||
//# sourceMappingURL=complete.js.map |
@@ -1,10 +0,1 @@ | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -14,3 +5,3 @@ exports.register = void 0; | ||
function register(context) { | ||
return (item, token) => __awaiter(this, void 0, void 0, function* () { | ||
return async (item, token) => { | ||
const data = item.data; | ||
@@ -24,6 +15,5 @@ if (data) { | ||
for (const [_, map] of context.documents.getMapsByVirtualFileUri(data.map.embeddedDocumentUri)) { | ||
item = yield plugin.resolveCompletionItem(item, token); | ||
item = await plugin.resolveCompletionItem(item, token); | ||
item = transformer.asCompletionItem(item, embeddedRange => { | ||
var _a; | ||
let range = (_a = plugin.resolveEmbeddedRange) === null || _a === void 0 ? void 0 : _a.call(plugin, embeddedRange); | ||
let range = plugin.resolveEmbeddedRange?.(embeddedRange); | ||
if (range) | ||
@@ -36,3 +26,3 @@ return range; | ||
else { | ||
item = yield plugin.resolveCompletionItem(item, token); | ||
item = await plugin.resolveCompletionItem(item, token); | ||
} | ||
@@ -45,5 +35,5 @@ } | ||
return item; | ||
}); | ||
}; | ||
} | ||
exports.register = register; | ||
//# sourceMappingURL=completeResolve.js.map |
@@ -1,10 +0,1 @@ | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -17,3 +8,3 @@ exports.register = void 0; | ||
return (uri, position, token) => { | ||
return (0, featureWorkers_1.languageFeatureWorker)(context, uri, position, (position, map) => map.toGeneratedPositions(position, isValidMapping), (plugin, document, position) => __awaiter(this, void 0, void 0, function* () { | ||
return (0, featureWorkers_1.languageFeatureWorker)(context, uri, position, (position, map) => map.toGeneratedPositions(position, isValidMapping), async (plugin, document, position) => { | ||
if (token.isCancellationRequested) | ||
@@ -23,40 +14,40 @@ return; | ||
const result = []; | ||
yield withMirrors(document, position, undefined); | ||
await withMirrors(document, position, undefined); | ||
return result; | ||
function withMirrors(document, position, originDefinition) { | ||
var _a, _b; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const api = plugin[apiName]; | ||
if (!api) | ||
return; | ||
if (recursiveChecker.has({ uri: document.uri, range: { start: position, end: position } })) | ||
return; | ||
recursiveChecker.add({ uri: document.uri, range: { start: position, end: position } }); | ||
const definitions = (_a = yield (api === null || api === void 0 ? void 0 : api(document, position, token))) !== null && _a !== void 0 ? _a : []; | ||
for (const definition of definitions) { | ||
let foundMirrorPosition = false; | ||
recursiveChecker.add({ uri: definition.targetUri, range: { start: definition.targetRange.start, end: definition.targetRange.start } }); | ||
const mirrorMap = (_b = context.documents.getMirrorMapByUri(definition.targetUri)) === null || _b === void 0 ? void 0 : _b[1]; | ||
if (mirrorMap) { | ||
for (const mapped of mirrorMap.findMirrorPositions(definition.targetSelectionRange.start)) { | ||
if (!isValidMirrorPosition(mapped[1])) | ||
continue; | ||
if (recursiveChecker.has({ uri: mirrorMap.document.uri, range: { start: mapped[0], end: mapped[0] } })) | ||
continue; | ||
foundMirrorPosition = true; | ||
yield withMirrors(mirrorMap.document, mapped[0], originDefinition !== null && originDefinition !== void 0 ? originDefinition : definition); | ||
} | ||
async function withMirrors(document, position, originDefinition) { | ||
const api = plugin[apiName]; | ||
if (!api) | ||
return; | ||
if (recursiveChecker.has({ uri: document.uri, range: { start: position, end: position } })) | ||
return; | ||
recursiveChecker.add({ uri: document.uri, range: { start: position, end: position } }); | ||
const definitions = await api?.(document, position, token) ?? []; | ||
for (const definition of definitions) { | ||
let foundMirrorPosition = false; | ||
recursiveChecker.add({ uri: definition.targetUri, range: { start: definition.targetRange.start, end: definition.targetRange.start } }); | ||
const mirrorMap = context.documents.getMirrorMapByUri(definition.targetUri)?.[1]; | ||
if (mirrorMap) { | ||
for (const mapped of mirrorMap.findMirrorPositions(definition.targetSelectionRange.start)) { | ||
if (!isValidMirrorPosition(mapped[1])) | ||
continue; | ||
if (recursiveChecker.has({ uri: mirrorMap.document.uri, range: { start: mapped[0], end: mapped[0] } })) | ||
continue; | ||
foundMirrorPosition = true; | ||
await withMirrors(mirrorMap.document, mapped[0], originDefinition ?? definition); | ||
} | ||
if (!foundMirrorPosition) { | ||
if (originDefinition) { | ||
result.push(Object.assign(Object.assign({}, definition), { originSelectionRange: originDefinition.originSelectionRange })); | ||
} | ||
else { | ||
result.push(definition); | ||
} | ||
} | ||
if (!foundMirrorPosition) { | ||
if (originDefinition) { | ||
result.push({ | ||
...definition, | ||
originSelectionRange: originDefinition.originSelectionRange, | ||
}); | ||
} | ||
else { | ||
result.push(definition); | ||
} | ||
} | ||
}); | ||
} | ||
} | ||
}), (data, sourceMap) => data.map(link => { | ||
}, (data, sourceMap) => data.map(link => { | ||
if (link.originSelectionRange && sourceMap) { | ||
@@ -77,3 +68,3 @@ const originSelectionRange = toSourcePositionPreferSurroundedPosition(sourceMap, link.originSelectionRange, position); | ||
// loose range mapping to for template slots, slot properties | ||
link.targetRange = targetRange !== null && targetRange !== void 0 ? targetRange : targetSelectionRange; | ||
link.targetRange = targetRange ?? targetSelectionRange; | ||
link.targetSelectionRange = targetSelectionRange; | ||
@@ -80,0 +71,0 @@ } |
@@ -1,10 +0,1 @@ | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -19,3 +10,3 @@ exports.register = void 0; | ||
// note https://github.com/johnsoncodehk/volar/issues/2009 | ||
data => typeof data.rename === 'object' ? !!data.rename.normalize : !!data.rename), (plugin, document, position) => __awaiter(this, void 0, void 0, function* () { | ||
data => typeof data.rename === 'object' ? !!data.rename.normalize : !!data.rename), async (plugin, document, position) => { | ||
if (token.isCancellationRequested) | ||
@@ -25,34 +16,31 @@ return; | ||
const result = []; | ||
yield withMirrors(document, position); | ||
await withMirrors(document, position); | ||
return result; | ||
function withMirrors(document, position) { | ||
var _a, _b; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if (!plugin.provideDocumentHighlights) | ||
return; | ||
if (recursiveChecker.has({ uri: document.uri, range: { start: position, end: position } })) | ||
return; | ||
recursiveChecker.add({ uri: document.uri, range: { start: position, end: position } }); | ||
const references = (_a = yield plugin.provideDocumentHighlights(document, position, token)) !== null && _a !== void 0 ? _a : []; | ||
for (const reference of references) { | ||
let foundMirrorPosition = false; | ||
recursiveChecker.add({ uri: document.uri, range: { start: reference.range.start, end: reference.range.start } }); | ||
const mirrorMap = (_b = context.documents.getMirrorMapByUri(document.uri)) === null || _b === void 0 ? void 0 : _b[1]; | ||
if (mirrorMap) { | ||
for (const mapped of mirrorMap.findMirrorPositions(reference.range.start)) { | ||
if (!mapped[1].references) | ||
continue; | ||
if (recursiveChecker.has({ uri: mirrorMap.document.uri, range: { start: mapped[0], end: mapped[0] } })) | ||
continue; | ||
foundMirrorPosition = true; | ||
yield withMirrors(mirrorMap.document, mapped[0]); | ||
} | ||
async function withMirrors(document, position) { | ||
if (!plugin.provideDocumentHighlights) | ||
return; | ||
if (recursiveChecker.has({ uri: document.uri, range: { start: position, end: position } })) | ||
return; | ||
recursiveChecker.add({ uri: document.uri, range: { start: position, end: position } }); | ||
const references = await plugin.provideDocumentHighlights(document, position, token) ?? []; | ||
for (const reference of references) { | ||
let foundMirrorPosition = false; | ||
recursiveChecker.add({ uri: document.uri, range: { start: reference.range.start, end: reference.range.start } }); | ||
const mirrorMap = context.documents.getMirrorMapByUri(document.uri)?.[1]; | ||
if (mirrorMap) { | ||
for (const mapped of mirrorMap.findMirrorPositions(reference.range.start)) { | ||
if (!mapped[1].references) | ||
continue; | ||
if (recursiveChecker.has({ uri: mirrorMap.document.uri, range: { start: mapped[0], end: mapped[0] } })) | ||
continue; | ||
foundMirrorPosition = true; | ||
await withMirrors(mirrorMap.document, mapped[0]); | ||
} | ||
if (!foundMirrorPosition) { | ||
result.push(reference); | ||
} | ||
} | ||
}); | ||
if (!foundMirrorPosition) { | ||
result.push(reference); | ||
} | ||
} | ||
} | ||
}), (data, map) => data.map(highlight => { | ||
}, (data, map) => data.map(highlight => { | ||
if (!map) | ||
@@ -62,3 +50,6 @@ return highlight; | ||
if (range) { | ||
return Object.assign(Object.assign({}, highlight), { range }); | ||
return { | ||
...highlight, | ||
range, | ||
}; | ||
} | ||
@@ -65,0 +56,0 @@ }).filter(common_1.notEmpty), arr => arr.flat()); |
@@ -1,10 +0,1 @@ | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -15,9 +6,7 @@ exports.register = void 0; | ||
function register(context) { | ||
return (uri, token) => __awaiter(this, void 0, void 0, function* () { | ||
var _a; | ||
const pluginLinks = (_a = yield (0, featureWorkers_1.documentFeatureWorker)(context, uri, file => !!file.capabilities.documentSymbol, (plugin, document) => { | ||
var _a; | ||
return async (uri, token) => { | ||
const pluginLinks = await (0, featureWorkers_1.documentFeatureWorker)(context, uri, file => !!file.capabilities.documentSymbol, (plugin, document) => { | ||
if (token.isCancellationRequested) | ||
return; | ||
return (_a = plugin.provideLinks) === null || _a === void 0 ? void 0 : _a.call(plugin, document, token); | ||
return plugin.provideLinks?.(document, token); | ||
}, (data, map) => data.map(link => { | ||
@@ -28,5 +17,8 @@ if (!map) | ||
if (range) { | ||
return Object.assign(Object.assign({}, link), { range }); | ||
return { | ||
...link, | ||
range, | ||
}; | ||
} | ||
}).filter(common_1.notEmpty), arr => arr.flat())) !== null && _a !== void 0 ? _a : []; | ||
}).filter(common_1.notEmpty), arr => arr.flat()) ?? []; | ||
const maps = context.documents.getMapsBySourceFileUri(uri); | ||
@@ -57,5 +49,5 @@ const fictitiousLinks = maps ? getFictitiousLinks(context.documents.getDocumentByUri(maps.snapshot, uri), maps.maps) : []; | ||
} | ||
}); | ||
}; | ||
} | ||
exports.register = register; | ||
//# sourceMappingURL=documentLinks.js.map |
@@ -1,10 +0,1 @@ | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -17,3 +8,3 @@ exports.register = void 0; | ||
function register(context) { | ||
return (uri, range, legend, token, reportProgress) => __awaiter(this, void 0, void 0, function* () { | ||
return async (uri, range, legend, token, reportProgress) => { | ||
const document = context.getTextDocument(uri); | ||
@@ -29,3 +20,3 @@ if (!document) | ||
]; | ||
const tokens = yield (0, featureWorkers_1.languageFeatureWorker)(context, uri, offsetRange, function* (offsetRange, map) { | ||
const tokens = await (0, featureWorkers_1.languageFeatureWorker)(context, uri, offsetRange, function* (offsetRange, map) { | ||
let range; | ||
@@ -49,6 +40,5 @@ for (const mapping of map.map.mappings) { | ||
}, (plugin, document, offsetRange) => { | ||
var _a; | ||
if (token === null || token === void 0 ? void 0 : token.isCancellationRequested) | ||
if (token?.isCancellationRequested) | ||
return; | ||
return (_a = plugin.provideDocumentSemanticTokens) === null || _a === void 0 ? void 0 : _a.call(plugin, document, vscode.Range.create(document.positionAt(offsetRange[0]), document.positionAt(offsetRange[1])), legend, token); | ||
return plugin.provideDocumentSemanticTokens?.(document, vscode.Range.create(document.positionAt(offsetRange[0]), document.positionAt(offsetRange[1])), legend, token); | ||
}, (tokens, map) => tokens.map(_token => { | ||
@@ -64,7 +54,7 @@ if (!map) | ||
} | ||
}).filter(common_1.notEmpty), tokens => tokens.flat(), tokens => reportProgress === null || reportProgress === void 0 ? void 0 : reportProgress(buildTokens(tokens))); | ||
}).filter(common_1.notEmpty), tokens => tokens.flat(), tokens => reportProgress?.(buildTokens(tokens))); | ||
if (tokens) { | ||
return buildTokens(tokens); | ||
} | ||
}); | ||
}; | ||
} | ||
@@ -71,0 +61,0 @@ exports.register = register; |
@@ -1,10 +0,1 @@ | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -19,8 +10,7 @@ exports.register = void 0; | ||
yield _; | ||
}, (plugin, document) => __awaiter(this, void 0, void 0, function* () { | ||
var _a, _b; | ||
}, async (plugin, document) => { | ||
if (token.isCancellationRequested) | ||
return; | ||
return (_b = yield ((_a = plugin.provideFileReferences) === null || _a === void 0 ? void 0 : _a.call(plugin, document, token))) !== null && _b !== void 0 ? _b : []; | ||
}), (data) => data.map(reference => { | ||
return await plugin.provideFileReferences?.(document, token) ?? []; | ||
}, (data) => data.map(reference => { | ||
if (!context.documents.hasVirtualFileByUri(reference.uri)) { | ||
@@ -27,0 +17,0 @@ return reference; |
@@ -1,10 +0,1 @@ | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -16,5 +7,4 @@ exports.register = void 0; | ||
function register(context) { | ||
return (oldUri, newUri, token) => __awaiter(this, void 0, void 0, function* () { | ||
var _a; | ||
const rootFile = (_a = context.documents.getSourceByUri(oldUri)) === null || _a === void 0 ? void 0 : _a.root; | ||
return async (oldUri, newUri, token) => { | ||
const rootFile = context.documents.getSourceByUri(oldUri)?.root; | ||
if (rootFile) { | ||
@@ -38,6 +28,6 @@ let tsExt; | ||
continue; | ||
const workspaceEdit = yield plugin.provideFileRenameEdits(oldUri, newUri, token); | ||
const workspaceEdit = await plugin.provideFileRenameEdits(oldUri, newUri, token); | ||
if (workspaceEdit) { | ||
const result = (0, rename_1.embeddedEditToSourceEdit)(workspaceEdit, context.documents, 'fileName'); | ||
if (result === null || result === void 0 ? void 0 : result.documentChanges) { | ||
if (result?.documentChanges) { | ||
result.documentChanges = dedupe.withDocumentChanges(result.documentChanges); | ||
@@ -48,5 +38,5 @@ } | ||
} | ||
}); | ||
}; | ||
} | ||
exports.register = register; | ||
//# sourceMappingURL=fileRename.js.map |
@@ -9,6 +9,5 @@ Object.defineProperty(exports, "__esModule", { value: true }); | ||
return (0, featureWorkers_1.languageFeatureWorker)(context, uri, position, (position, map) => map.toGeneratedPositions(position, data => !!data.hover), (plugin, document, position) => { | ||
var _a; | ||
if (token.isCancellationRequested) | ||
return; | ||
return (_a = plugin.provideHover) === null || _a === void 0 ? void 0 : _a.call(plugin, document, position, token); | ||
return plugin.provideHover?.(document, position, token); | ||
}, (item, map) => { | ||
@@ -22,9 +21,6 @@ if (!map || !item.range) | ||
} | ||
}, hovers => { | ||
var _a, _b; | ||
return ({ | ||
contents: hovers.map(getHoverTexts).flat(), | ||
range: (_b = (_a = hovers.find(hover => hover.range && (0, common_1.isInsideRange)(hover.range, { start: position, end: position }))) === null || _a === void 0 ? void 0 : _a.range) !== null && _b !== void 0 ? _b : hovers[0].range, | ||
}); | ||
}); | ||
}, hovers => ({ | ||
contents: hovers.map(getHoverTexts).flat(), | ||
range: hovers.find(hover => hover.range && (0, common_1.isInsideRange)(hover.range, { start: position, end: position }))?.range ?? hovers[0].range, | ||
})); | ||
}; | ||
@@ -31,0 +27,0 @@ } |
@@ -1,10 +0,1 @@ | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -17,3 +8,3 @@ exports.register = void 0; | ||
function register(context) { | ||
return (uri, range, token) => __awaiter(this, void 0, void 0, function* () { | ||
return async (uri, range, token) => { | ||
const document = context.getTextDocument(uri); | ||
@@ -30,3 +21,2 @@ if (!document) | ||
*/ | ||
var _a, _b; | ||
if (!file.capabilities.inlayHint) | ||
@@ -39,4 +29,4 @@ return []; | ||
if (overlapRange) { | ||
const start = (_a = map.map.toGeneratedOffset(overlapRange.start)) === null || _a === void 0 ? void 0 : _a[0]; | ||
const end = (_b = map.map.toGeneratedOffset(overlapRange.end)) === null || _b === void 0 ? void 0 : _b[0]; | ||
const start = map.map.toGeneratedOffset(overlapRange.start)?.[0]; | ||
const end = map.map.toGeneratedOffset(overlapRange.end)?.[0]; | ||
if (start !== undefined && end !== undefined) { | ||
@@ -53,19 +43,23 @@ minStart = minStart === undefined ? start : Math.min(start, minStart); | ||
}, (plugin, document, arg) => { | ||
var _a; | ||
if (token.isCancellationRequested) | ||
return; | ||
return (_a = plugin.provideInlayHints) === null || _a === void 0 ? void 0 : _a.call(plugin, document, arg, token); | ||
return plugin.provideInlayHints?.(document, arg, token); | ||
}, (inlayHints, map) => inlayHints.map((_inlayHint) => { | ||
var _a; | ||
if (!map) | ||
return _inlayHint; | ||
const position = map.toSourcePosition(_inlayHint.position); | ||
const edits = (_a = _inlayHint.textEdits) === null || _a === void 0 ? void 0 : _a.map(textEdit => transformer.asTextEdit(textEdit, range => map.toSourceRange(range), map.virtualFileDocument)).filter(common_1.notEmpty); | ||
const edits = _inlayHint.textEdits | ||
?.map(textEdit => transformer.asTextEdit(textEdit, range => map.toSourceRange(range), map.virtualFileDocument)) | ||
.filter(common_1.notEmpty); | ||
if (position) { | ||
return Object.assign(Object.assign({}, _inlayHint), { position, textEdits: edits }); | ||
return { | ||
..._inlayHint, | ||
position, | ||
textEdits: edits, | ||
}; | ||
} | ||
}).filter(common_1.notEmpty), arr => arr.flat()); | ||
}); | ||
}; | ||
} | ||
exports.register = register; | ||
//# sourceMappingURL=inlayHints.js.map |
@@ -1,10 +0,1 @@ | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -16,3 +7,3 @@ exports.register = void 0; | ||
return (uri, position, token) => { | ||
return (0, featureWorkers_1.languageFeatureWorker)(context, uri, position, (position, map) => map.toGeneratedPositions(position, data => !!data.references), (plugin, document, position) => __awaiter(this, void 0, void 0, function* () { | ||
return (0, featureWorkers_1.languageFeatureWorker)(context, uri, position, (position, map) => map.toGeneratedPositions(position, data => !!data.references), async (plugin, document, position) => { | ||
if (token.isCancellationRequested) | ||
@@ -22,34 +13,31 @@ return; | ||
const result = []; | ||
yield withMirrors(document, position); | ||
await withMirrors(document, position); | ||
return result; | ||
function withMirrors(document, position) { | ||
var _a, _b; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if (!plugin.provideReferences) | ||
return; | ||
if (recursiveChecker.has({ uri: document.uri, range: { start: position, end: position } })) | ||
return; | ||
recursiveChecker.add({ uri: document.uri, range: { start: position, end: position } }); | ||
const references = (_a = yield plugin.provideReferences(document, position, token)) !== null && _a !== void 0 ? _a : []; | ||
for (const reference of references) { | ||
let foundMirrorPosition = false; | ||
recursiveChecker.add({ uri: reference.uri, range: { start: reference.range.start, end: reference.range.start } }); | ||
const mirrorMap = (_b = context.documents.getMirrorMapByUri(reference.uri)) === null || _b === void 0 ? void 0 : _b[1]; | ||
if (mirrorMap) { | ||
for (const mapped of mirrorMap.findMirrorPositions(reference.range.start)) { | ||
if (!mapped[1].references) | ||
continue; | ||
if (recursiveChecker.has({ uri: mirrorMap.document.uri, range: { start: mapped[0], end: mapped[0] } })) | ||
continue; | ||
foundMirrorPosition = true; | ||
yield withMirrors(mirrorMap.document, mapped[0]); | ||
} | ||
async function withMirrors(document, position) { | ||
if (!plugin.provideReferences) | ||
return; | ||
if (recursiveChecker.has({ uri: document.uri, range: { start: position, end: position } })) | ||
return; | ||
recursiveChecker.add({ uri: document.uri, range: { start: position, end: position } }); | ||
const references = await plugin.provideReferences(document, position, token) ?? []; | ||
for (const reference of references) { | ||
let foundMirrorPosition = false; | ||
recursiveChecker.add({ uri: reference.uri, range: { start: reference.range.start, end: reference.range.start } }); | ||
const mirrorMap = context.documents.getMirrorMapByUri(reference.uri)?.[1]; | ||
if (mirrorMap) { | ||
for (const mapped of mirrorMap.findMirrorPositions(reference.range.start)) { | ||
if (!mapped[1].references) | ||
continue; | ||
if (recursiveChecker.has({ uri: mirrorMap.document.uri, range: { start: mapped[0], end: mapped[0] } })) | ||
continue; | ||
foundMirrorPosition = true; | ||
await withMirrors(mirrorMap.document, mapped[0]); | ||
} | ||
if (!foundMirrorPosition) { | ||
result.push(reference); | ||
} | ||
} | ||
}); | ||
if (!foundMirrorPosition) { | ||
result.push(reference); | ||
} | ||
} | ||
} | ||
}), (data) => { | ||
}, (data) => { | ||
const results = []; | ||
@@ -56,0 +44,0 @@ for (const reference of data) { |
@@ -1,10 +0,1 @@ | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -30,3 +21,3 @@ exports.embeddedEditToSourceEdit = exports.mergeWorkspaceEdits = exports.register = void 0; | ||
; | ||
}, (plugin, document, arg) => __awaiter(this, void 0, void 0, function* () { | ||
}, async (plugin, document, arg) => { | ||
if (token.isCancellationRequested) | ||
@@ -36,59 +27,56 @@ return; | ||
let result; | ||
yield withMirrors(document, arg.position, arg.newName); | ||
await withMirrors(document, arg.position, arg.newName); | ||
return result; | ||
function withMirrors(document, position, newName) { | ||
var _a; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if (!plugin.provideRenameEdits) | ||
return; | ||
if (recursiveChecker.has({ uri: document.uri, range: { start: position, end: position } })) | ||
return; | ||
recursiveChecker.add({ uri: document.uri, range: { start: position, end: position } }); | ||
const workspaceEdit = yield plugin.provideRenameEdits(document, position, newName, token); | ||
if (!workspaceEdit) | ||
return; | ||
if (!result) | ||
result = {}; | ||
if (workspaceEdit.changes) { | ||
for (const editUri in workspaceEdit.changes) { | ||
const textEdits = workspaceEdit.changes[editUri]; | ||
for (const textEdit of textEdits) { | ||
let foundMirrorPosition = false; | ||
recursiveChecker.add({ uri: editUri, range: { start: textEdit.range.start, end: textEdit.range.start } }); | ||
const mirrorMap = (_a = context.documents.getMirrorMapByUri(editUri)) === null || _a === void 0 ? void 0 : _a[1]; | ||
if (mirrorMap) { | ||
for (const mapped of mirrorMap.findMirrorPositions(textEdit.range.start)) { | ||
if (!mapped[1].rename) | ||
continue; | ||
if (recursiveChecker.has({ uri: mirrorMap.document.uri, range: { start: mapped[0], end: mapped[0] } })) | ||
continue; | ||
foundMirrorPosition = true; | ||
yield withMirrors(mirrorMap.document, mapped[0], newName); | ||
} | ||
async function withMirrors(document, position, newName) { | ||
if (!plugin.provideRenameEdits) | ||
return; | ||
if (recursiveChecker.has({ uri: document.uri, range: { start: position, end: position } })) | ||
return; | ||
recursiveChecker.add({ uri: document.uri, range: { start: position, end: position } }); | ||
const workspaceEdit = await plugin.provideRenameEdits(document, position, newName, token); | ||
if (!workspaceEdit) | ||
return; | ||
if (!result) | ||
result = {}; | ||
if (workspaceEdit.changes) { | ||
for (const editUri in workspaceEdit.changes) { | ||
const textEdits = workspaceEdit.changes[editUri]; | ||
for (const textEdit of textEdits) { | ||
let foundMirrorPosition = false; | ||
recursiveChecker.add({ uri: editUri, range: { start: textEdit.range.start, end: textEdit.range.start } }); | ||
const mirrorMap = context.documents.getMirrorMapByUri(editUri)?.[1]; | ||
if (mirrorMap) { | ||
for (const mapped of mirrorMap.findMirrorPositions(textEdit.range.start)) { | ||
if (!mapped[1].rename) | ||
continue; | ||
if (recursiveChecker.has({ uri: mirrorMap.document.uri, range: { start: mapped[0], end: mapped[0] } })) | ||
continue; | ||
foundMirrorPosition = true; | ||
await withMirrors(mirrorMap.document, mapped[0], newName); | ||
} | ||
if (!foundMirrorPosition) { | ||
if (!result.changes) | ||
result.changes = {}; | ||
if (!result.changes[editUri]) | ||
result.changes[editUri] = []; | ||
result.changes[editUri].push(textEdit); | ||
} | ||
} | ||
if (!foundMirrorPosition) { | ||
if (!result.changes) | ||
result.changes = {}; | ||
if (!result.changes[editUri]) | ||
result.changes[editUri] = []; | ||
result.changes[editUri].push(textEdit); | ||
} | ||
} | ||
} | ||
if (workspaceEdit.changeAnnotations) { | ||
for (const uri in workspaceEdit.changeAnnotations) { | ||
if (!result.changeAnnotations) | ||
result.changeAnnotations = {}; | ||
result.changeAnnotations[uri] = workspaceEdit.changeAnnotations[uri]; | ||
} | ||
} | ||
if (workspaceEdit.changeAnnotations) { | ||
for (const uri in workspaceEdit.changeAnnotations) { | ||
if (!result.changeAnnotations) | ||
result.changeAnnotations = {}; | ||
result.changeAnnotations[uri] = workspaceEdit.changeAnnotations[uri]; | ||
} | ||
if (workspaceEdit.documentChanges) { | ||
if (!result.documentChanges) | ||
result.documentChanges = []; | ||
result.documentChanges = result.documentChanges.concat(workspaceEdit.documentChanges); | ||
} | ||
}); | ||
} | ||
if (workspaceEdit.documentChanges) { | ||
if (!result.documentChanges) | ||
result.documentChanges = []; | ||
result.documentChanges = result.documentChanges.concat(workspaceEdit.documentChanges); | ||
} | ||
} | ||
}), (data) => { | ||
}, (data) => { | ||
return embeddedEditToSourceEdit(data, context.documents, 'rename'); | ||
@@ -139,8 +127,6 @@ }, (workspaceEdits) => { | ||
function embeddedEditToSourceEdit(tsResult, documents, mode, versions = {}) { | ||
var _a, _b, _c, _d, _e, _f; | ||
var _g, _h, _j, _k; | ||
const sourceResult = {}; | ||
let hasResult = false; | ||
for (const tsUri in tsResult.changeAnnotations) { | ||
(_a = sourceResult.changeAnnotations) !== null && _a !== void 0 ? _a : (sourceResult.changeAnnotations = {}); | ||
sourceResult.changeAnnotations ??= {}; | ||
const tsAnno = tsResult.changeAnnotations[tsUri]; | ||
@@ -159,3 +145,3 @@ if (!documents.hasVirtualFileByUri(tsUri)) { | ||
for (const tsUri in tsResult.changes) { | ||
(_b = sourceResult.changes) !== null && _b !== void 0 ? _b : (sourceResult.changes = {}); | ||
sourceResult.changes ??= {}; | ||
if (!documents.hasVirtualFileByUri(tsUri)) { | ||
@@ -180,3 +166,3 @@ sourceResult.changes[tsUri] = tsResult.changes[tsUri]; | ||
} | ||
(_c = (_g = sourceResult.changes)[_h = map.sourceFileDocument.uri]) !== null && _c !== void 0 ? _c : (_g[_h] = []); | ||
sourceResult.changes[map.sourceFileDocument.uri] ??= []; | ||
sourceResult.changes[map.sourceFileDocument.uri].push({ newText, range }); | ||
@@ -189,3 +175,3 @@ hasResult = true; | ||
if (range) { | ||
(_d = (_j = sourceResult.changes)[_k = map.sourceFileDocument.uri]) !== null && _d !== void 0 ? _d : (_j[_k] = []); | ||
sourceResult.changes[map.sourceFileDocument.uri] ??= []; | ||
sourceResult.changes[map.sourceFileDocument.uri].push({ newText: tsEdit.newText, range }); | ||
@@ -200,3 +186,3 @@ hasResult = true; | ||
for (const tsDocEdit of tsResult.documentChanges) { | ||
(_e = sourceResult.documentChanges) !== null && _e !== void 0 ? _e : (sourceResult.documentChanges = []); | ||
sourceResult.documentChanges ??= []; | ||
let sourceEdit; | ||
@@ -208,3 +194,3 @@ if (vscode.TextDocumentEdit.is(tsDocEdit)) { | ||
uri: map.sourceFileDocument.uri, | ||
version: (_f = versions[map.sourceFileDocument.uri]) !== null && _f !== void 0 ? _f : null, | ||
version: versions[map.sourceFileDocument.uri] ?? null, | ||
}, []); | ||
@@ -211,0 +197,0 @@ for (const tsEdit of tsDocEdit.edits) { |
@@ -8,6 +8,5 @@ Object.defineProperty(exports, "__esModule", { value: true }); | ||
return (0, featureWorkers_1.languageFeatureWorker)(context, uri, position, (position, map) => map.toGeneratedPositions(position, data => typeof data.rename === 'object' ? !!data.rename.normalize : !!data.rename), (plugin, document, position) => { | ||
var _a; | ||
if (token.isCancellationRequested) | ||
return; | ||
return (_a = plugin.provideRenameRange) === null || _a === void 0 ? void 0 : _a.call(plugin, document, position, token); | ||
return plugin.provideRenameRange?.(document, position, token); | ||
}, (item, map) => { | ||
@@ -14,0 +13,0 @@ if (!map) { |
@@ -7,18 +7,17 @@ Object.defineProperty(exports, "__esModule", { value: true }); | ||
return (uri, position, signatureHelpContext, token) => { | ||
signatureHelpContext !== null && signatureHelpContext !== void 0 ? signatureHelpContext : (signatureHelpContext = { | ||
signatureHelpContext ??= { | ||
triggerKind: vscode.SignatureHelpTriggerKind.Invoked, | ||
isRetrigger: false, | ||
}); | ||
}; | ||
return (0, featureWorkers_1.languageFeatureWorker)(context, uri, position, (position, map) => map.toGeneratedPositions(position, data => !!data.completion), (plugin, document, position) => { | ||
var _a, _b; | ||
if (token.isCancellationRequested) | ||
return; | ||
if ((signatureHelpContext === null || signatureHelpContext === void 0 ? void 0 : signatureHelpContext.triggerKind) === vscode.SignatureHelpTriggerKind.TriggerCharacter | ||
if (signatureHelpContext?.triggerKind === vscode.SignatureHelpTriggerKind.TriggerCharacter | ||
&& signatureHelpContext.triggerCharacter | ||
&& !((_a = (signatureHelpContext.isRetrigger | ||
&& !(signatureHelpContext.isRetrigger | ||
? plugin.signatureHelpRetriggerCharacters | ||
: plugin.signatureHelpTriggerCharacters)) === null || _a === void 0 ? void 0 : _a.includes(signatureHelpContext.triggerCharacter))) { | ||
: plugin.signatureHelpTriggerCharacters)?.includes(signatureHelpContext.triggerCharacter)) { | ||
return; | ||
} | ||
return (_b = plugin.provideSignatureHelp) === null || _b === void 0 ? void 0 : _b.call(plugin, document, position, signatureHelpContext, token); | ||
return plugin.provideSignatureHelp?.(document, position, signatureHelpContext, token); | ||
}, (data) => data); | ||
@@ -25,0 +24,0 @@ }; |
@@ -1,10 +0,1 @@ | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -97,4 +88,3 @@ exports.register = exports.updateRange = void 0; | ||
}; | ||
return (uri, token, mode, response) => __awaiter(this, void 0, void 0, function* () { | ||
var _a; | ||
return async (uri, token, mode, response) => { | ||
const newDocument = context.getTextDocument(uri); | ||
@@ -104,3 +94,3 @@ if (!newDocument) { | ||
} | ||
const lastResponse = (_a = lastResponses.get(uri)) !== null && _a !== void 0 ? _a : lastResponses.set(uri, { | ||
const lastResponse = lastResponses.get(uri) ?? lastResponses.set(uri, { | ||
semantic: { errors: [] }, | ||
@@ -119,3 +109,3 @@ syntactic: { errors: [] }, | ||
const oldDocument = cache.document; | ||
const change = oldSnapshot ? newSnapshot === null || newSnapshot === void 0 ? void 0 : newSnapshot.getChangeRange(oldSnapshot) : undefined; | ||
const change = oldSnapshot ? newSnapshot?.getChangeRange(oldSnapshot) : undefined; | ||
cache.snapshot = newSnapshot; | ||
@@ -140,13 +130,13 @@ cache.document = newDocument; | ||
if (mode === 'all' || mode === 'syntactic') { | ||
yield lintWorker('onFormat', cacheMaps.format_rules, lastResponse.format_rules); | ||
await lintWorker('onFormat', cacheMaps.format_rules, lastResponse.format_rules); | ||
doResponse(); | ||
yield lintWorker('onSyntax', cacheMaps.syntax_rules, lastResponse.syntax_rules); | ||
await lintWorker('onSyntax', cacheMaps.syntax_rules, lastResponse.syntax_rules); | ||
doResponse(); | ||
yield worker('provideSyntacticDiagnostics', cacheMaps.syntactic, lastResponse.syntactic); | ||
await worker('provideSyntacticDiagnostics', cacheMaps.syntactic, lastResponse.syntactic); | ||
doResponse(); | ||
} | ||
if (mode === 'all' || mode === 'semantic') { | ||
yield lintWorker('onSemantic', cacheMaps.semantic_rules, lastResponse.semantic_rules); | ||
await lintWorker('onSemantic', cacheMaps.semantic_rules, lastResponse.semantic_rules); | ||
doResponse(); | ||
yield worker('provideSemanticDiagnostics', cacheMaps.semantic, lastResponse.semantic); | ||
await worker('provideSemanticDiagnostics', cacheMaps.semantic, lastResponse.semantic); | ||
} | ||
@@ -156,3 +146,3 @@ return collectErrors(); | ||
if (errorsUpdated && !updateCacheRangeFailed) { | ||
response === null || response === void 0 ? void 0 : response(collectErrors()); | ||
response?.(collectErrors()); | ||
errorsUpdated = false; | ||
@@ -164,146 +154,138 @@ } | ||
} | ||
function lintWorker(api, cacheMap, cache) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const result = yield (0, featureWorkers_1.ruleWorker)(context, api, uri, file => api === 'onFormat' ? !!file.capabilities.documentFormatting : !!file.capabilities.diagnostic, (ruleName, rule, ruleCtx) => __awaiter(this, void 0, void 0, function* () { | ||
var _a, _b, _c, _d, _e, _f, _g; | ||
var _h, _j, _k, _l; | ||
if (token) { | ||
if (Date.now() - lastCheckCancelAt >= 5) { | ||
yield (0, common_1.sleep)(5); // wait for LSP event polling | ||
lastCheckCancelAt = Date.now(); | ||
} | ||
if (token.isCancellationRequested) { | ||
return; | ||
} | ||
async function lintWorker(api, cacheMap, cache) { | ||
const result = await (0, featureWorkers_1.ruleWorker)(context, api, uri, file => api === 'onFormat' ? !!file.capabilities.documentFormatting : !!file.capabilities.diagnostic, async (ruleName, rule, ruleCtx) => { | ||
if (token) { | ||
if (Date.now() - lastCheckCancelAt >= 5) { | ||
await (0, common_1.sleep)(5); // wait for LSP event polling | ||
lastCheckCancelAt = Date.now(); | ||
} | ||
const pluginCache = (_a = cacheMap.get(ruleName)) !== null && _a !== void 0 ? _a : cacheMap.set(ruleName, new Map()).get(ruleName); | ||
const cache = pluginCache.get(ruleCtx.document.uri); | ||
const tsProjectVersion = (api === 'onSemantic') ? (_c = (_b = context.core.typescript.languageServiceHost).getProjectVersion) === null || _c === void 0 ? void 0 : _c.call(_b) : undefined; | ||
if (api === 'onSemantic') { | ||
if (cache && cache.documentVersion === ruleCtx.document.version && cache.tsProjectVersion === tsProjectVersion) { | ||
return cache.errors; | ||
} | ||
if (token.isCancellationRequested) { | ||
return; | ||
} | ||
else { | ||
if (cache && cache.documentVersion === ruleCtx.document.version) { | ||
return cache.errors; | ||
} | ||
} | ||
const pluginCache = cacheMap.get(ruleName) ?? cacheMap.set(ruleName, new Map()).get(ruleName); | ||
const cache = pluginCache.get(ruleCtx.document.uri); | ||
const tsProjectVersion = (api === 'onSemantic') ? context.core.typescript.languageServiceHost.getProjectVersion?.() : undefined; | ||
if (api === 'onSemantic') { | ||
if (cache && cache.documentVersion === ruleCtx.document.version && cache.tsProjectVersion === tsProjectVersion) { | ||
return cache.errors; | ||
} | ||
const reportResults = []; | ||
ruleCtx.report = (error, ...fixes) => { | ||
var _a, _b; | ||
if (!vscode.Diagnostic.is(error)) { | ||
console.warn('[volar/rules-api] report() error must be a Diagnostic.'); | ||
return; | ||
} | ||
error.message || (error.message = 'No message.'); | ||
error.source || (error.source = 'rules'); | ||
error.code || (error.code = ruleCtx.ruleId); | ||
const severity = (_b = (_a = context.config.lint) === null || _a === void 0 ? void 0 : _a.severities) === null || _b === void 0 ? void 0 : _b[ruleCtx.ruleId]; | ||
if (severity !== undefined) { | ||
error.severity = severity; | ||
} | ||
reportResults.push([error, ...fixes]); | ||
}; | ||
try { | ||
yield ((_d = rule[api]) === null || _d === void 0 ? void 0 : _d.call(rule, ruleCtx)); | ||
} | ||
else { | ||
if (cache && cache.documentVersion === ruleCtx.document.version) { | ||
return cache.errors; | ||
} | ||
catch (err) { | ||
console.warn(`[volar/rules-api] ${ruleName} ${api} error.`); | ||
console.warn(err); | ||
} | ||
const reportResults = []; | ||
ruleCtx.report = (error, ...fixes) => { | ||
if (!vscode.Diagnostic.is(error)) { | ||
console.warn('[volar/rules-api] report() error must be a Diagnostic.'); | ||
return; | ||
} | ||
(_e = context.ruleFixes) !== null && _e !== void 0 ? _e : (context.ruleFixes = {}); | ||
(_f = (_h = context.ruleFixes)[_j = ruleCtx.document.uri]) !== null && _f !== void 0 ? _f : (_h[_j] = {}); | ||
(_g = (_k = context.ruleFixes[ruleCtx.document.uri])[_l = ruleCtx.ruleId]) !== null && _g !== void 0 ? _g : (_k[_l] = {}); | ||
reportResults === null || reportResults === void 0 ? void 0 : reportResults.forEach(([error, ...fixes], index) => { | ||
context.ruleFixes[ruleCtx.document.uri][ruleCtx.ruleId][index] = [error, fixes]; | ||
error.data = { | ||
uri, | ||
version: newDocument.version, | ||
type: 'rule', | ||
isFormat: api === 'onFormat', | ||
pluginOrRuleId: ruleCtx.ruleId, | ||
original: { | ||
data: error.data, | ||
}, | ||
ruleFixIndex: index, | ||
documentUri: ruleCtx.document.uri, | ||
}; | ||
}); | ||
errorsUpdated = true; | ||
const errors = reportResults.map(reportResult => reportResult[0]); | ||
pluginCache.set(ruleCtx.document.uri, { | ||
documentVersion: ruleCtx.document.version, | ||
errors, | ||
tsProjectVersion, | ||
}); | ||
return errors; | ||
}), api === 'onFormat' ? transformFormatErrorRange : transformErrorRange, arr => arr.flat()); | ||
if (result) { | ||
cache.errors = result; | ||
cache.snapshot = newSnapshot; | ||
error.message ||= 'No message.'; | ||
error.source ||= 'rules'; | ||
error.code ||= ruleCtx.ruleId; | ||
const severity = context.config.lint?.severities?.[ruleCtx.ruleId]; | ||
if (severity !== undefined) { | ||
error.severity = severity; | ||
} | ||
reportResults.push([error, ...fixes]); | ||
}; | ||
try { | ||
await rule[api]?.(ruleCtx); | ||
} | ||
}); | ||
catch (err) { | ||
console.warn(`[volar/rules-api] ${ruleName} ${api} error.`); | ||
console.warn(err); | ||
} | ||
context.ruleFixes ??= {}; | ||
context.ruleFixes[ruleCtx.document.uri] ??= {}; | ||
context.ruleFixes[ruleCtx.document.uri][ruleCtx.ruleId] ??= {}; | ||
reportResults?.forEach(([error, ...fixes], index) => { | ||
context.ruleFixes[ruleCtx.document.uri][ruleCtx.ruleId][index] = [error, fixes]; | ||
error.data = { | ||
uri, | ||
version: newDocument.version, | ||
type: 'rule', | ||
isFormat: api === 'onFormat', | ||
pluginOrRuleId: ruleCtx.ruleId, | ||
original: { | ||
data: error.data, | ||
}, | ||
ruleFixIndex: index, | ||
documentUri: ruleCtx.document.uri, | ||
}; | ||
}); | ||
errorsUpdated = true; | ||
const errors = reportResults.map(reportResult => reportResult[0]); | ||
pluginCache.set(ruleCtx.document.uri, { | ||
documentVersion: ruleCtx.document.version, | ||
errors, | ||
tsProjectVersion, | ||
}); | ||
return errors; | ||
}, api === 'onFormat' ? transformFormatErrorRange : transformErrorRange, arr => arr.flat()); | ||
if (result) { | ||
cache.errors = result; | ||
cache.snapshot = newSnapshot; | ||
} | ||
} | ||
function worker(api, cacheMap, cache) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const result = yield (0, featureWorkers_1.languageFeatureWorker)(context, uri, true, function* (arg, _, file) { | ||
if (file.capabilities.diagnostic) { | ||
yield arg; | ||
async function worker(api, cacheMap, cache) { | ||
const result = await (0, featureWorkers_1.languageFeatureWorker)(context, uri, true, function* (arg, _, file) { | ||
if (file.capabilities.diagnostic) { | ||
yield arg; | ||
} | ||
}, async (plugin, document) => { | ||
if (token) { | ||
if (Date.now() - lastCheckCancelAt >= 5) { | ||
await (0, common_1.sleep)(5); // waiting LSP event polling | ||
lastCheckCancelAt = Date.now(); | ||
} | ||
}, (plugin, document) => __awaiter(this, void 0, void 0, function* () { | ||
var _a, _b, _c, _d; | ||
if (token) { | ||
if (Date.now() - lastCheckCancelAt >= 5) { | ||
yield (0, common_1.sleep)(5); // waiting LSP event polling | ||
lastCheckCancelAt = Date.now(); | ||
} | ||
if (token.isCancellationRequested) { | ||
return; | ||
} | ||
if (token.isCancellationRequested) { | ||
return; | ||
} | ||
const pluginId = Object.keys(context.plugins).find(key => context.plugins[key] === plugin); | ||
const pluginCache = (_a = cacheMap.get(pluginId)) !== null && _a !== void 0 ? _a : cacheMap.set(pluginId, new Map()).get(pluginId); | ||
const cache = pluginCache.get(document.uri); | ||
const tsProjectVersion = api === 'provideSemanticDiagnostics' ? (_c = (_b = context.core.typescript.languageServiceHost).getProjectVersion) === null || _c === void 0 ? void 0 : _c.call(_b) : undefined; | ||
if (api === 'provideSemanticDiagnostics') { | ||
if (cache && cache.documentVersion === document.version && cache.tsProjectVersion === tsProjectVersion) { | ||
return cache.errors; | ||
} | ||
} | ||
const pluginId = Object.keys(context.plugins).find(key => context.plugins[key] === plugin); | ||
const pluginCache = cacheMap.get(pluginId) ?? cacheMap.set(pluginId, new Map()).get(pluginId); | ||
const cache = pluginCache.get(document.uri); | ||
const tsProjectVersion = api === 'provideSemanticDiagnostics' ? context.core.typescript.languageServiceHost.getProjectVersion?.() : undefined; | ||
if (api === 'provideSemanticDiagnostics') { | ||
if (cache && cache.documentVersion === document.version && cache.tsProjectVersion === tsProjectVersion) { | ||
return cache.errors; | ||
} | ||
else { | ||
if (cache && cache.documentVersion === document.version) { | ||
return cache.errors; | ||
} | ||
} | ||
else { | ||
if (cache && cache.documentVersion === document.version) { | ||
return cache.errors; | ||
} | ||
const errors = yield ((_d = plugin[api]) === null || _d === void 0 ? void 0 : _d.call(plugin, document, token)); | ||
errors === null || errors === void 0 ? void 0 : errors.forEach(error => { | ||
error.data = { | ||
uri, | ||
version: newDocument.version, | ||
type: 'plugin', | ||
pluginOrRuleId: pluginId, | ||
isFormat: false, | ||
original: { | ||
data: error.data, | ||
}, | ||
ruleFixIndex: 0, | ||
documentUri: document.uri, | ||
}; | ||
}); | ||
errorsUpdated = true; | ||
pluginCache.set(document.uri, { | ||
documentVersion: document.version, | ||
errors, | ||
tsProjectVersion, | ||
}); | ||
return errors; | ||
}), transformErrorRange, arr => dedupe.withDiagnostics(arr.flat())); | ||
if (result) { | ||
cache.errors = result; | ||
cache.snapshot = newSnapshot; | ||
} | ||
}); | ||
const errors = await plugin[api]?.(document, token); | ||
errors?.forEach(error => { | ||
error.data = { | ||
uri, | ||
version: newDocument.version, | ||
type: 'plugin', | ||
pluginOrRuleId: pluginId, | ||
isFormat: false, | ||
original: { | ||
data: error.data, | ||
}, | ||
ruleFixIndex: 0, | ||
documentUri: document.uri, | ||
}; | ||
}); | ||
errorsUpdated = true; | ||
pluginCache.set(document.uri, { | ||
documentVersion: document.version, | ||
errors, | ||
tsProjectVersion, | ||
}); | ||
return errors; | ||
}, transformErrorRange, arr => dedupe.withDiagnostics(arr.flat())); | ||
if (result) { | ||
cache.errors = result; | ||
cache.snapshot = newSnapshot; | ||
} | ||
} | ||
}); | ||
}; | ||
function transformFormatErrorRange(errors, map) { | ||
@@ -313,3 +295,3 @@ const result = []; | ||
// clone it to avoid modify cache | ||
let _error = Object.assign({}, error); | ||
let _error = { ...error }; | ||
if (map) { | ||
@@ -330,3 +312,3 @@ const range = map.toSourceRange(error.range); | ||
// clone it to avoid modify cache | ||
let _error = Object.assign({}, error); | ||
let _error = { ...error }; | ||
if (map) { | ||
@@ -333,0 +315,0 @@ const range = map.toSourceRange(error.range, data => !!data.diagnostic); |
@@ -1,10 +0,1 @@ | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -16,3 +7,3 @@ exports.register = void 0; | ||
function register(context) { | ||
return (query, token) => __awaiter(this, void 0, void 0, function* () { | ||
return async (query, token) => { | ||
const symbolsList = []; | ||
@@ -24,3 +15,3 @@ for (const plugin of Object.values(context.plugins)) { | ||
continue; | ||
const embeddedSymbols = yield plugin.provideWorkspaceSymbols(query, token); | ||
const embeddedSymbols = await plugin.provideWorkspaceSymbols(query, token); | ||
if (!embeddedSymbols) | ||
@@ -44,5 +35,5 @@ continue; | ||
return symbolsList.flat(); | ||
}); | ||
}; | ||
} | ||
exports.register = register; | ||
//# sourceMappingURL=workspaceSymbols.js.map |
@@ -6,8 +6,13 @@ Object.defineProperty(exports, "__esModule", { value: true }); | ||
function transform(item, getOtherRange, document) { | ||
var _a; | ||
return Object.assign(Object.assign({}, item), { additionalTextEdits: (_a = item.additionalTextEdits) === null || _a === void 0 ? void 0 : _a.map(edit => (0, textEdit_1.transform)(edit, getOtherRange, document)).filter(common_1.notEmpty), textEdit: item.textEdit | ||
return { | ||
...item, | ||
additionalTextEdits: item.additionalTextEdits | ||
?.map(edit => (0, textEdit_1.transform)(edit, getOtherRange, document)) | ||
.filter(common_1.notEmpty), | ||
textEdit: item.textEdit | ||
? (0, textEdit_1.transform)(item.textEdit, getOtherRange, document) | ||
: undefined }); | ||
: undefined, | ||
}; | ||
} | ||
exports.transform = transform; | ||
//# sourceMappingURL=completionItem.js.map |
@@ -7,3 +7,5 @@ Object.defineProperty(exports, "__esModule", { value: true }); | ||
isIncomplete: completionList.isIncomplete, | ||
itemDefaults: completionList.itemDefaults ? Object.assign(Object.assign({}, completionList.itemDefaults), { editRange: completionList.itemDefaults.editRange | ||
itemDefaults: completionList.itemDefaults ? { | ||
...completionList.itemDefaults, | ||
editRange: completionList.itemDefaults.editRange | ||
? 'replace' in completionList.itemDefaults.editRange | ||
@@ -15,6 +17,7 @@ ? { | ||
: getOtherRange(completionList.itemDefaults.editRange) | ||
: undefined }) : undefined, | ||
: undefined, | ||
} : undefined, | ||
items: completionList.items.map(item => { | ||
const newItem = (0, completionItem_1.transform)(item, getOtherRange, document); | ||
onItem === null || onItem === void 0 ? void 0 : onItem(newItem, item); | ||
onItem?.(newItem, item); | ||
return newItem; | ||
@@ -21,0 +24,0 @@ }), |
@@ -5,3 +5,2 @@ Object.defineProperty(exports, "__esModule", { value: true }); | ||
function transform(symbol, getOtherRange) { | ||
var _a; | ||
const range = getOtherRange(symbol.range); | ||
@@ -15,6 +14,12 @@ if (!range) { | ||
} | ||
return Object.assign(Object.assign({}, symbol), { range, | ||
selectionRange, children: (_a = symbol.children) === null || _a === void 0 ? void 0 : _a.map(child => transform(child, getOtherRange)).filter(common_1.notEmpty) }); | ||
return { | ||
...symbol, | ||
range, | ||
selectionRange, | ||
children: symbol.children | ||
?.map(child => transform(child, getOtherRange)) | ||
.filter(common_1.notEmpty), | ||
}; | ||
} | ||
exports.transform = transform; | ||
//# sourceMappingURL=documentSymbol.js.map |
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.transform = void 0; | ||
function transform(ranges, getOtherRange) { | ||
var _a, _b; | ||
const result = []; | ||
for (const range of ranges) { | ||
const otherRange = getOtherRange({ | ||
start: { line: range.startLine, character: (_a = range.startCharacter) !== null && _a !== void 0 ? _a : 0 }, | ||
end: { line: range.endLine, character: (_b = range.endCharacter) !== null && _b !== void 0 ? _b : 0 }, | ||
start: { line: range.startLine, character: range.startCharacter ?? 0 }, | ||
end: { line: range.endLine, character: range.endCharacter ?? 0 }, | ||
}); | ||
@@ -11,0 +10,0 @@ if (otherRange) { |
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.transform = void 0; | ||
function transform(hover, getOtherRange) { | ||
if (!(hover === null || hover === void 0 ? void 0 : hover.range)) { | ||
if (!hover?.range) { | ||
return hover; | ||
@@ -10,5 +10,8 @@ } | ||
return; | ||
return Object.assign(Object.assign({}, hover), { range }); | ||
return { | ||
...hover, | ||
range, | ||
}; | ||
} | ||
exports.transform = transform; | ||
//# sourceMappingURL=hover.js.map |
@@ -7,5 +7,8 @@ Object.defineProperty(exports, "__esModule", { value: true }); | ||
return; | ||
return Object.assign(Object.assign({}, location), { range }); | ||
return { | ||
...location, | ||
range, | ||
}; | ||
} | ||
exports.transform = transform; | ||
//# sourceMappingURL=locationLike.js.map |
@@ -8,3 +8,6 @@ Object.defineProperty(exports, "__esModule", { value: true }); | ||
if (range) { | ||
return Object.assign(Object.assign({}, textEdit), { range }); | ||
return { | ||
...textEdit, | ||
range, | ||
}; | ||
} | ||
@@ -14,3 +17,7 @@ ; | ||
if (cover) { | ||
return Object.assign(Object.assign({}, textEdit), { range: cover.range, newText: cover.newText }); | ||
return { | ||
...textEdit, | ||
range: cover.range, | ||
newText: cover.newText, | ||
}; | ||
} | ||
@@ -22,4 +29,7 @@ } | ||
if (insert && replace) { | ||
return Object.assign(Object.assign({}, textEdit), { insert, | ||
replace }); | ||
return { | ||
...textEdit, | ||
insert, | ||
replace, | ||
}; | ||
} | ||
@@ -29,3 +39,8 @@ const recoverInsert = tryRecover(getOtherRange, textEdit.insert, textEdit.newText, document); | ||
if (recoverInsert && recoverReplace && recoverInsert.newText === recoverReplace.newText) { | ||
return Object.assign(Object.assign({}, textEdit), { insert: recoverInsert.range, replace: recoverReplace.range, newText: recoverInsert.newText }); | ||
return { | ||
...textEdit, | ||
insert: recoverInsert.range, | ||
replace: recoverReplace.range, | ||
newText: recoverInsert.newText, | ||
}; | ||
} | ||
@@ -32,0 +47,0 @@ } |
@@ -12,5 +12,8 @@ Object.defineProperty(exports, "__esModule", { value: true }); | ||
} | ||
return Object.assign(Object.assign({}, symbol), { location: loc }); | ||
return { | ||
...symbol, | ||
location: loc, | ||
}; | ||
} | ||
exports.transform = transform; | ||
//# sourceMappingURL=workspaceSymbol.js.map |
@@ -96,5 +96,5 @@ import { LanguageContext, LanguageModule, LanguageServiceHost } from '@volar/language-core'; | ||
provideInlayHints?(document: TextDocument, range: vscode.Range, token: vscode.CancellationToken): NullableResult<vscode.InlayHint[]>; | ||
provideCallHierarchyItems(document: TextDocument, position: vscode.Position, token: vscode.CancellationToken): NullableResult<vscode.CallHierarchyItem[]>; | ||
provideCallHierarchyIncomingCalls(item: vscode.CallHierarchyItem, token: vscode.CancellationToken): Result<vscode.CallHierarchyIncomingCall[]>; | ||
provideCallHierarchyOutgoingCalls(item: vscode.CallHierarchyItem, token: vscode.CancellationToken): Result<vscode.CallHierarchyOutgoingCall[]>; | ||
provideCallHierarchyItems?(document: TextDocument, position: vscode.Position, token: vscode.CancellationToken): NullableResult<vscode.CallHierarchyItem[]>; | ||
provideCallHierarchyIncomingCalls?(item: vscode.CallHierarchyItem, token: vscode.CancellationToken): Result<vscode.CallHierarchyIncomingCall[]>; | ||
provideCallHierarchyOutgoingCalls?(item: vscode.CallHierarchyItem, token: vscode.CancellationToken): Result<vscode.CallHierarchyOutgoingCall[]>; | ||
provideDocumentSemanticTokens?(document: TextDocument, range: vscode.Range, legend: vscode.SemanticTokensLegend, token: vscode.CancellationToken): NullableResult<SemanticToken[]>; | ||
@@ -101,0 +101,0 @@ provideWorkspaceSymbols?(query: string, token: vscode.CancellationToken): NullableResult<vscode.WorkspaceSymbol[]>; |
@@ -1,31 +0,19 @@ | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.visitEmbedded = void 0; | ||
function visitEmbedded(documents, current, cb, rootFile = current) { | ||
var _a; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
for (const embedded of current.embeddedFiles) { | ||
if (!(yield visitEmbedded(documents, embedded, cb, rootFile))) { | ||
async function visitEmbedded(documents, current, cb, rootFile = current) { | ||
for (const embedded of current.embeddedFiles) { | ||
if (!await visitEmbedded(documents, embedded, cb, rootFile)) { | ||
return false; | ||
} | ||
} | ||
for (const [_, map] of documents.getMapsByVirtualFileName(current.fileName)) { | ||
if (documents.getSourceByUri(map.sourceFileDocument.uri)?.root === rootFile) { | ||
if (!await cb(current, map)) { | ||
return false; | ||
} | ||
} | ||
for (const [_, map] of documents.getMapsByVirtualFileName(current.fileName)) { | ||
if (((_a = documents.getSourceByUri(map.sourceFileDocument.uri)) === null || _a === void 0 ? void 0 : _a.root) === rootFile) { | ||
if (!(yield cb(current, map))) { | ||
return false; | ||
} | ||
} | ||
} | ||
return true; | ||
}); | ||
} | ||
return true; | ||
} | ||
exports.visitEmbedded = visitEmbedded; | ||
//# sourceMappingURL=definePlugin.js.map |
@@ -1,122 +0,22 @@ | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.safeCall = exports.ruleWorker = exports.languageFeatureWorker = exports.documentFeatureWorker = void 0; | ||
const definePlugin_1 = require("./definePlugin"); | ||
function documentFeatureWorker(context, uri, isValidSourceMap, worker, transform, combineResult) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return languageFeatureWorker(context, uri, undefined, (_, map, file) => { | ||
if (isValidSourceMap(file, map)) { | ||
return [undefined]; | ||
} | ||
return []; | ||
}, worker, transform, combineResult); | ||
}); | ||
async function documentFeatureWorker(context, uri, isValidSourceMap, worker, transform, combineResult) { | ||
return languageFeatureWorker(context, uri, undefined, (_, map, file) => { | ||
if (isValidSourceMap(file, map)) { | ||
return [undefined]; | ||
} | ||
return []; | ||
}, worker, transform, combineResult); | ||
} | ||
exports.documentFeatureWorker = documentFeatureWorker; | ||
function languageFeatureWorker(context, uri, arg, transformArg, worker, transform, combineResult, reportProgress) { | ||
var _a; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const document = context.getTextDocument(uri); | ||
const virtualFile = (_a = context.documents.getSourceByUri(uri)) === null || _a === void 0 ? void 0 : _a.root; | ||
let results = []; | ||
if (virtualFile) { | ||
yield (0, definePlugin_1.visitEmbedded)(context.documents, virtualFile, (file, map) => __awaiter(this, void 0, void 0, function* () { | ||
for (const mappedArg of transformArg(arg, map, file)) { | ||
for (const [pluginId, plugin] of Object.entries(context.plugins)) { | ||
const embeddedResult = yield safeCall(() => worker(plugin, map.virtualFileDocument, mappedArg, map, file), 'plugin ' + pluginId + ' crashed on ' + map.virtualFileDocument.uri); | ||
if (!embeddedResult) | ||
continue; | ||
const result = transform(embeddedResult, map); | ||
if (!result) | ||
continue; | ||
results.push(result); | ||
if (!combineResult) | ||
return false; | ||
const isEmptyArray = Array.isArray(result) && result.length === 0; | ||
if (reportProgress && !isEmptyArray) { | ||
reportProgress(combineResult(results)); | ||
} | ||
} | ||
} | ||
return true; | ||
})); | ||
} | ||
else if (document) { | ||
for (const [pluginId, plugin] of Object.entries(context.plugins)) { | ||
const embeddedResult = yield safeCall(() => worker(plugin, document, arg, undefined, undefined), 'plugin ' + pluginId + ' crashed on ' + uri); | ||
if (!embeddedResult) | ||
continue; | ||
const result = transform(embeddedResult, undefined); | ||
if (!result) | ||
continue; | ||
results.push(result); | ||
if (!combineResult) | ||
break; | ||
const isEmptyArray = Array.isArray(result) && result.length === 0; | ||
if (reportProgress && !isEmptyArray) { | ||
reportProgress(combineResult(results)); | ||
} | ||
} | ||
} | ||
if (combineResult && results.length > 0) { | ||
return combineResult(results); | ||
} | ||
else if (results.length > 0) { | ||
return results[0]; | ||
} | ||
}); | ||
} | ||
exports.languageFeatureWorker = languageFeatureWorker; | ||
function ruleWorker(context, api, uri, isValidSourceMap, worker, transform, combineResult, reportProgress) { | ||
var _a, _b, _c, _d, _e, _f, _g, _h; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const document = context.getTextDocument(uri); | ||
const virtualFile = (_a = context.documents.getSourceByUri(uri)) === null || _a === void 0 ? void 0 : _a.root; | ||
let results = []; | ||
if (virtualFile) { | ||
yield (0, definePlugin_1.visitEmbedded)(context.documents, virtualFile, (file, map) => __awaiter(this, void 0, void 0, function* () { | ||
var _j, _k, _l, _m, _o, _p, _q; | ||
if (!isValidSourceMap(file)) { | ||
return true; | ||
} | ||
let ruleCtx = { | ||
// project context | ||
modules: { typescript: (_j = context.typescript) === null || _j === void 0 ? void 0 : _j.module }, | ||
uriToFileName: context.uriToFileName, | ||
fileNameToUri: context.fileNameToUri, | ||
rootUri: context.rootUri, | ||
locale: context.locale, | ||
getConfiguration: (_k = context.configurationHost) === null || _k === void 0 ? void 0 : _k.getConfiguration, | ||
onDidChangeConfiguration: (_l = context.configurationHost) === null || _l === void 0 ? void 0 : _l.onDidChangeConfiguration, | ||
settings: (_o = (_m = context.config.lint) === null || _m === void 0 ? void 0 : _m.settings) !== null && _o !== void 0 ? _o : {}, | ||
// document context | ||
ruleId: '', | ||
document: map.virtualFileDocument, | ||
report: () => { }, | ||
}; | ||
for (const plugin of Object.values(context.plugins)) { | ||
try { | ||
if (plugin.resolveRuleContext) { | ||
ruleCtx = yield plugin.resolveRuleContext(ruleCtx, api === 'onFormat' ? 'format' : api === 'onSyntax' ? 'syntax' : 'semantic'); | ||
} | ||
} | ||
catch (err) { | ||
console.warn('plugin rule context setup crashed on ' + map.virtualFileDocument.uri + ': ' + err); | ||
} | ||
} | ||
for (const ruleName in (_p = context.config.lint) === null || _p === void 0 ? void 0 : _p.rules) { | ||
const rule = (_q = context.config.lint) === null || _q === void 0 ? void 0 : _q.rules[ruleName]; | ||
if (!rule) { | ||
continue; | ||
} | ||
ruleCtx.ruleId = ruleName; | ||
const embeddedResult = yield safeCall(() => worker(ruleName, rule, ruleCtx), 'rule ' + ruleName + ' crashed on ' + map.virtualFileDocument.uri); | ||
async function languageFeatureWorker(context, uri, arg, transformArg, worker, transform, combineResult, reportProgress) { | ||
const document = context.getTextDocument(uri); | ||
const virtualFile = context.documents.getSourceByUri(uri)?.root; | ||
let results = []; | ||
if (virtualFile) { | ||
await (0, definePlugin_1.visitEmbedded)(context.documents, virtualFile, async (file, map) => { | ||
for (const mappedArg of transformArg(arg, map, file)) { | ||
for (const [pluginId, plugin] of Object.entries(context.plugins)) { | ||
const embeddedResult = await safeCall(() => worker(plugin, map.virtualFileDocument, mappedArg, map, file), 'plugin ' + pluginId + ' crashed on ' + map.virtualFileDocument.uri); | ||
if (!embeddedResult) | ||
@@ -135,9 +35,43 @@ continue; | ||
} | ||
} | ||
return true; | ||
}); | ||
} | ||
else if (document) { | ||
for (const [pluginId, plugin] of Object.entries(context.plugins)) { | ||
const embeddedResult = await safeCall(() => worker(plugin, document, arg, undefined, undefined), 'plugin ' + pluginId + ' crashed on ' + uri); | ||
if (!embeddedResult) | ||
continue; | ||
const result = transform(embeddedResult, undefined); | ||
if (!result) | ||
continue; | ||
results.push(result); | ||
if (!combineResult) | ||
break; | ||
const isEmptyArray = Array.isArray(result) && result.length === 0; | ||
if (reportProgress && !isEmptyArray) { | ||
reportProgress(combineResult(results)); | ||
} | ||
} | ||
} | ||
if (combineResult && results.length > 0) { | ||
return combineResult(results); | ||
} | ||
else if (results.length > 0) { | ||
return results[0]; | ||
} | ||
} | ||
exports.languageFeatureWorker = languageFeatureWorker; | ||
async function ruleWorker(context, api, uri, isValidSourceMap, worker, transform, combineResult, reportProgress) { | ||
const document = context.getTextDocument(uri); | ||
const virtualFile = context.documents.getSourceByUri(uri)?.root; | ||
let results = []; | ||
if (virtualFile) { | ||
await (0, definePlugin_1.visitEmbedded)(context.documents, virtualFile, async (file, map) => { | ||
if (!isValidSourceMap(file)) { | ||
return true; | ||
})); | ||
} | ||
else if (document) { | ||
} | ||
let ruleCtx = { | ||
// project context | ||
modules: { typescript: (_b = context.typescript) === null || _b === void 0 ? void 0 : _b.module }, | ||
modules: { typescript: context.typescript?.module }, | ||
uriToFileName: context.uriToFileName, | ||
@@ -147,8 +81,8 @@ fileNameToUri: context.fileNameToUri, | ||
locale: context.locale, | ||
getConfiguration: (_c = context.configurationHost) === null || _c === void 0 ? void 0 : _c.getConfiguration, | ||
onDidChangeConfiguration: (_d = context.configurationHost) === null || _d === void 0 ? void 0 : _d.onDidChangeConfiguration, | ||
settings: (_f = (_e = context.config.lint) === null || _e === void 0 ? void 0 : _e.settings) !== null && _f !== void 0 ? _f : {}, | ||
getConfiguration: context.configurationHost?.getConfiguration, | ||
onDidChangeConfiguration: context.configurationHost?.onDidChangeConfiguration, | ||
settings: context.config.lint?.settings ?? {}, | ||
// document context | ||
ruleId: '', | ||
document, | ||
document: map.virtualFileDocument, | ||
report: () => { }, | ||
@@ -159,11 +93,11 @@ }; | ||
if (plugin.resolveRuleContext) { | ||
ruleCtx = yield plugin.resolveRuleContext(ruleCtx, api === 'onFormat' ? 'format' : api === 'onSyntax' ? 'syntax' : 'semantic'); | ||
ruleCtx = await plugin.resolveRuleContext(ruleCtx, api === 'onFormat' ? 'format' : api === 'onSyntax' ? 'syntax' : 'semantic'); | ||
} | ||
} | ||
catch (err) { | ||
console.warn('plugin rule context setup crashed on ' + document.uri + ': ' + err); | ||
console.warn('plugin rule context setup crashed on ' + map.virtualFileDocument.uri + ': ' + err); | ||
} | ||
} | ||
for (const ruleName in (_g = context.config.lint) === null || _g === void 0 ? void 0 : _g.rules) { | ||
const rule = (_h = context.config.lint) === null || _h === void 0 ? void 0 : _h.rules[ruleName]; | ||
for (const ruleName in context.config.lint?.rules) { | ||
const rule = context.config.lint?.rules[ruleName]; | ||
if (!rule) { | ||
@@ -173,6 +107,6 @@ continue; | ||
ruleCtx.ruleId = ruleName; | ||
const embeddedResult = yield safeCall(() => worker(ruleName, rule, ruleCtx), 'rule ' + ruleName + ' crashed on ' + document.uri); | ||
const embeddedResult = await safeCall(() => worker(ruleName, rule, ruleCtx), 'rule ' + ruleName + ' crashed on ' + map.virtualFileDocument.uri); | ||
if (!embeddedResult) | ||
continue; | ||
const result = transform(embeddedResult, undefined); | ||
const result = transform(embeddedResult, map); | ||
if (!result) | ||
@@ -182,3 +116,3 @@ continue; | ||
if (!combineResult) | ||
break; | ||
return false; | ||
const isEmptyArray = Array.isArray(result) && result.length === 0; | ||
@@ -189,23 +123,69 @@ if (reportProgress && !isEmptyArray) { | ||
} | ||
return true; | ||
}); | ||
} | ||
else if (document) { | ||
let ruleCtx = { | ||
// project context | ||
modules: { typescript: context.typescript?.module }, | ||
uriToFileName: context.uriToFileName, | ||
fileNameToUri: context.fileNameToUri, | ||
rootUri: context.rootUri, | ||
locale: context.locale, | ||
getConfiguration: context.configurationHost?.getConfiguration, | ||
onDidChangeConfiguration: context.configurationHost?.onDidChangeConfiguration, | ||
settings: context.config.lint?.settings ?? {}, | ||
// document context | ||
ruleId: '', | ||
document, | ||
report: () => { }, | ||
}; | ||
for (const plugin of Object.values(context.plugins)) { | ||
try { | ||
if (plugin.resolveRuleContext) { | ||
ruleCtx = await plugin.resolveRuleContext(ruleCtx, api === 'onFormat' ? 'format' : api === 'onSyntax' ? 'syntax' : 'semantic'); | ||
} | ||
} | ||
catch (err) { | ||
console.warn('plugin rule context setup crashed on ' + document.uri + ': ' + err); | ||
} | ||
} | ||
if (combineResult && results.length > 0) { | ||
return combineResult(results); | ||
for (const ruleName in context.config.lint?.rules) { | ||
const rule = context.config.lint?.rules[ruleName]; | ||
if (!rule) { | ||
continue; | ||
} | ||
ruleCtx.ruleId = ruleName; | ||
const embeddedResult = await safeCall(() => worker(ruleName, rule, ruleCtx), 'rule ' + ruleName + ' crashed on ' + document.uri); | ||
if (!embeddedResult) | ||
continue; | ||
const result = transform(embeddedResult, undefined); | ||
if (!result) | ||
continue; | ||
results.push(result); | ||
if (!combineResult) | ||
break; | ||
const isEmptyArray = Array.isArray(result) && result.length === 0; | ||
if (reportProgress && !isEmptyArray) { | ||
reportProgress(combineResult(results)); | ||
} | ||
} | ||
else if (results.length > 0) { | ||
return results[0]; | ||
} | ||
}); | ||
} | ||
if (combineResult && results.length > 0) { | ||
return combineResult(results); | ||
} | ||
else if (results.length > 0) { | ||
return results[0]; | ||
} | ||
} | ||
exports.ruleWorker = ruleWorker; | ||
function safeCall(cb, errorMsg) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
try { | ||
return yield cb(); | ||
} | ||
catch (err) { | ||
console.warn(errorMsg, err); | ||
} | ||
}); | ||
async function safeCall(cb, errorMsg) { | ||
try { | ||
return await cb(); | ||
} | ||
catch (err) { | ||
console.warn(errorMsg, err); | ||
} | ||
} | ||
exports.safeCall = safeCall; | ||
//# sourceMappingURL=featureWorkers.js.map |
{ | ||
"name": "@volar/language-service", | ||
"version": "1.4.0-alpha.0", | ||
"version": "1.4.0-alpha.1", | ||
"main": "out/index.js", | ||
@@ -16,4 +16,4 @@ "license": "MIT", | ||
"dependencies": { | ||
"@volar/language-core": "1.4.0-alpha.0", | ||
"@volar/source-map": "1.4.0-alpha.0", | ||
"@volar/language-core": "1.4.0-alpha.1", | ||
"@volar/source-map": "1.4.0-alpha.1", | ||
"typescript-auto-import-cache": "^0.0.1", | ||
@@ -26,3 +26,3 @@ "vscode-html-languageservice": "^5.0.4", | ||
}, | ||
"gitHead": "2607410cae341cf802b446062d446ad497be2057" | ||
"gitHead": "41ea915b137aea284e2bf5edd98a788ce21b779c" | ||
} |
197969
3924
+ Added@volar/language-core@1.4.0-alpha.1(transitive)
+ Added@volar/source-map@1.4.0-alpha.1(transitive)
- Removed@volar/language-core@1.4.0-alpha.0(transitive)
- Removed@volar/source-map@1.4.0-alpha.0(transitive)