MCPcopy Create free account
hub / github.com/Snapchat/Valdi / prettyPrint

Method prettyPrint

valdi/vscode_debugger/src/adapter/sources.ts:208–244  ·  view source on GitHub ↗

* Pretty-prints the source. Generates a beauitified source map if possible * and it hasn't already been done, and returns the created map and created * ephemeral source. Returns undefined if the source can't be beautified.

()

Source from the content-addressed store, hash-verified

206 * ephemeral source. Returns undefined if the source can't be beautified.
207 */
208 public async prettyPrint(): Promise<{ map: SourceMap; source: Source } | undefined> {
209 if (!this._container || !this.canPrettyPrint()) {
210 return undefined;
211 }
212
213 if (isSourceWithMap(this) && this.sourceMap.url.endsWith('-pretty.map')) {
214 const map = this._container._sourceMaps.get(this.sourceMap?.url)?.map;
215 // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
216 return map && { map, source: [...this.sourceMap.sourceByUrl!.values()][0] };
217 }
218
219 const content = await this.content();
220 if (!content) {
221 return undefined;
222 }
223
224 const sourceMapUrl = this.url + '-pretty.map';
225 const basename = this.url.split(/[\/\\]/).pop() as string;
226 const fileName = basename + '-pretty.js';
227 const map = await prettyPrintAsSourceMap(fileName, content, this.url, sourceMapUrl);
228 if (!map) {
229 return undefined;
230 }
231
232 // Note: this overwrites existing source map.
233 this.setSourceMapUrl(sourceMapUrl);
234 const asCompiled = this as ISourceWithMap;
235 const sourceMap: SourceMapData = {
236 compiled: new Set([asCompiled]),
237 map,
238 loaded: Promise.resolve(),
239 };
240 this._container._sourceMaps.set(sourceMapUrl, sourceMap);
241 await this._container._addSourceMapSources(asCompiled, map);
242 // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
243 return { map, source: [...asCompiled.sourceMap.sourceByUrl.values()][0] };
244 }
245
246 /**
247 * Returns a DAP representation of the source.

Callers 1

_prettyPrintSourceMethod · 0.80

Calls 12

canPrettyPrintMethod · 0.95
contentMethod · 0.95
setSourceMapUrlMethod · 0.95
prettyPrintAsSourceMapFunction · 0.90
isSourceWithMapFunction · 0.85
valuesMethod · 0.80
splitMethod · 0.80
_addSourceMapSourcesMethod · 0.80
getMethod · 0.65
popMethod · 0.65
resolveMethod · 0.65
setMethod · 0.65

Tested by

no test coverage detected