MCPcopy
hub / github.com/microsoft/vscode-js-debug / prettyPrint

Method prettyPrint

src/adapter/source.ts:222–263  ·  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

220 * ephemeral source. Returns undefined if the source can't be beautified.
221 */
222 public async prettyPrint(): Promise<{ map: SourceMap; source: Source } | undefined> {
223 if (!this._container) {
224 return undefined;
225 }
226
227 if (
228 isSourceWithSourceMap(this)
229 && this.sourceMap.metadata.sourceMapUrl.endsWith('-pretty.map')
230 ) {
231 const map = this.sourceMap.value.settledValue;
232 // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
233 return map && { map, source: [...this.sourceMap.sourceByUrl!.values()][0] };
234 }
235
236 const content = await this.content();
237 if (!content) {
238 return undefined;
239 }
240
241 // Eval'd scripts have empty urls, give them a temporary one for the purpose
242 // of the sourcemap. See #929
243 const baseUrl = this.url || `eval://${this.sourceReference}.js`;
244 const sourceMapUrl = baseUrl + '-pretty.map';
245 const basename = baseUrl.split(/[\/\\]/).pop() as string;
246 const fileName = basename + '-pretty.js';
247 const map = await prettyPrintAsSourceMap(fileName, content, baseUrl, sourceMapUrl);
248 if (!map) {
249 return undefined;
250 }
251
252 // Note: this overwrites existing source map.
253 this.setSourceMapUrl({
254 compiledPath: this.absolutePath,
255 sourceMapUrl: '',
256 });
257 (this.sourceMap as ISourceMapLocationProvider).value.resolve(map);
258
259 const asCompiled = this as ISourceWithMap;
260 await this._container._addSourceMapSources(asCompiled, map);
261 // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
262 return { map, source: [...asCompiled.sourceMap.sourceByUrl.values()][0] };
263 }
264
265 /**
266 * Returns a DAP representation of the source.

Callers 1

_prettyPrintSourceMethod · 0.80

Calls 8

contentMethod · 0.95
setSourceMapUrlMethod · 0.95
prettyPrintAsSourceMapFunction · 0.90
isSourceWithSourceMapFunction · 0.85
valuesMethod · 0.80
popMethod · 0.80
resolveMethod · 0.80
_addSourceMapSourcesMethod · 0.80

Tested by

no test coverage detected