MCPcopy Index your code
hub / github.com/microsoft/vscode-js-debug / createSource

Method createSource

src/adapter/threads.ts:1678–1746  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1676 }
1677
1678 const createSource = async () => {
1679 const prevSource = this._sourceContainer.getSourceByOriginalUrl(event.url);
1680 if (event.hash && prevSource?.contentHash === event.hash) {
1681 prevSource.addScript({
1682 scriptId: event.scriptId,
1683 url: event.url,
1684 embedderName: event.embedderName,
1685 hasSourceURL: !!event.hasSourceURL,
1686 executionContextId: event.executionContextId,
1687 });
1688 return prevSource;
1689 }
1690
1691 const contentGetter = async () => {
1692 const response = await this._cdp.Debugger.getScriptSource({ scriptId: event.scriptId });
1693 return response ? response.scriptSource : undefined;
1694 };
1695
1696 const inlineSourceOffset = event.startLine || event.startColumn
1697 ? { lineOffset: event.startLine, columnOffset: event.startColumn }
1698 : undefined;
1699
1700 // see https://github.com/microsoft/vscode/issues/103027
1701 const runtimeScriptOffset = event.url.endsWith('#vscode-extension')
1702 ? { lineOffset: 2, columnOffset: 0 }
1703 : undefined;
1704
1705 let resolvedSourceMapUrl: string | undefined;
1706 if (event.sourceMapURL) {
1707 // Note: we should in theory refetch source maps with relative urls, if the base url has changed,
1708 // but in practice that usually means new scripts with new source maps anyway.
1709 resolvedSourceMapUrl = urlUtils.isDataUri(event.sourceMapURL)
1710 ? event.sourceMapURL
1711 : (event.url && urlUtils.completeUrl(event.url, event.sourceMapURL)) || event.url;
1712 if (!resolvedSourceMapUrl) {
1713 this._dap.with(dap =>
1714 errors.reportToConsole(dap, `Could not load source map from ${event.sourceMapURL}`)
1715 );
1716 }
1717 }
1718
1719 if (event.scriptLanguage === 'WebAssembly') {
1720 this._lastParsedWasmScriptIds ??= [];
1721 this._lastParsedWasmScriptIds.push(event.scriptId);
1722 }
1723
1724 const source = await this._sourceContainer.addSource(
1725 event,
1726 contentGetter,
1727 resolvedSourceMapUrl,
1728 inlineSourceOffset,
1729 runtimeScriptOffset,
1730 // only include the script hash if content validation is enabled, and if
1731 // the source does not have a redirected URL. In the latter case the
1732 // original file won't have a `# sourceURL=...` comment, so the hash
1733 // never matches: https://github.com/microsoft/vscode-js-debug/issues/1476
1734 !event.hasSourceURL && this.launchConfig.enableContentValidation ? event.hash : undefined,
1735 );

Callers

nothing calls this directly

Calls 6

addScriptMethod · 0.80
withMethod · 0.80
addSourceMethod · 0.80
pushMethod · 0.65
completeUrlMethod · 0.45

Tested by

no test coverage detected