getVirtualCodeTSX() — astro Function Reference
Architecture documentation for the getVirtualCodeTSX() function in astro2tsx.ts from the astro codebase.
Entity Profile
Dependency Diagram
graph TD 00848da5_4f63_d1d3_21f7_67bc828a4fce["getVirtualCodeTSX()"] f004a067_f0ae_35cb_fc32_ccf4d7476223["astro2tsx.ts"] 00848da5_4f63_d1d3_21f7_67bc828a4fce -->|defined in| f004a067_f0ae_35cb_fc32_ccf4d7476223 3b0a8762_2dc4_2dd5_6c0b_507bb1bd0169["astro2tsx()"] 3b0a8762_2dc4_2dd5_6c0b_507bb1bd0169 -->|calls| 00848da5_4f63_d1d3_21f7_67bc828a4fce style 00848da5_4f63_d1d3_21f7_67bc828a4fce fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
packages/language-tools/language-server/src/core/astro2tsx.ts lines 95–174
function getVirtualCodeTSX(input: string, tsx: TSXResult, fileName: string): VirtualCode {
tsx.code = patchTSX(tsx.code, fileName);
const v3Mappings = decode(tsx.map.mappings);
const sourcedDoc = TextDocument.create('', 'astro', 0, input);
const genDoc = TextDocument.create('', 'typescriptreact', 0, tsx.code);
const mappings: CodeMapping[] = [];
let current:
| {
genOffset: number;
sourceOffset: number;
}
| undefined;
for (let genLine = 0; genLine < v3Mappings.length; genLine++) {
for (const segment of v3Mappings[genLine]) {
const genCharacter = segment[0];
const genOffset = genDoc.offsetAt({ line: genLine, character: genCharacter });
if (current) {
let length = genOffset - current.genOffset;
const sourceText = input.substring(current.sourceOffset, current.sourceOffset + length);
const genText = tsx.code.substring(current.genOffset, current.genOffset + length);
if (sourceText !== genText) {
length = 0;
for (let i = 0; i < genOffset - current.genOffset; i++) {
if (sourceText[i] === genText[i]) {
length = i + 1;
} else {
break;
}
}
}
if (length > 0) {
const lastMapping = mappings.length ? mappings[mappings.length - 1] : undefined;
if (
lastMapping &&
lastMapping.generatedOffsets[0] + lastMapping.lengths[0] === current.genOffset &&
lastMapping.sourceOffsets[0] + lastMapping.lengths[0] === current.sourceOffset
) {
lastMapping.lengths[0] += length;
} else {
mappings.push({
sourceOffsets: [current.sourceOffset],
generatedOffsets: [current.genOffset],
lengths: [length],
data: {
verification: true,
completion: true,
semantic: true,
navigation: true,
structure: true,
format: false,
},
});
}
}
current = undefined;
}
if (segment[2] !== undefined && segment[3] !== undefined) {
const sourceOffset = sourcedDoc.offsetAt({ line: segment[2], character: segment[3] });
current = {
genOffset,
sourceOffset,
};
}
}
}
return {
id: 'tsx',
languageId: 'typescriptreact',
snapshot: {
getText: (start, end) => tsx.code.substring(start, end),
getLength: () => tsx.code.length,
getChangeRange: () => undefined,
},
mappings: mappings,
embeddedCodes: [],
};
}
Domain
Subdomains
Called By
Source
Frequently Asked Questions
What does getVirtualCodeTSX() do?
getVirtualCodeTSX() is a function in the astro codebase, defined in packages/language-tools/language-server/src/core/astro2tsx.ts.
Where is getVirtualCodeTSX() defined?
getVirtualCodeTSX() is defined in packages/language-tools/language-server/src/core/astro2tsx.ts at line 95.
What calls getVirtualCodeTSX()?
getVirtualCodeTSX() is called by 1 function(s): astro2tsx.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free