UNPKG

@autorest/common

Version:
73 lines 2.47 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.LogSourceEnhancer = void 0; class LogSourceEnhancer { constructor(dataStore) { this.dataStore = dataStore; } async process(log) { if (log.source === undefined) { return log; } const sources = await this.resolveOriginalSources(log, log.source); return { ...log, source: this.resolveOriginalDocumentNames(sources), }; } async resolveOriginalSources(message, source) { const blameSources = source.map(async (s) => { let blameTree = null; try { while (blameTree === null) { try { blameTree = await this.dataStore.blame(s.document, s.position); } catch (e) { if ("path" in s.position) { const path = s.position.path; if (path.length === 0) { throw e; } // adjustment // 1) skip leading `$` if (path[0] === "$") { path.shift(); } else { path.pop(); } } else { throw e; } } } } catch (e) { return [s]; } return blameTree.getMappingLeafs().map((r) => ({ document: r.source, position: { line: r.line, column: r.column }, })); }); return (await Promise.all(blameSources)).flat(); } resolveOriginalDocumentNames(sources) { return sources.map((source) => { if (source.position) { try { const document = this.dataStore.readStrictSync(source.document).description; return { ...source, document }; } catch (_a) { // no worries } } return source; }); } } exports.LogSourceEnhancer = LogSourceEnhancer; //# sourceMappingURL=log-source-enhancer.js.map