MCPcopy Create free account
hub / github.com/angular/angular / getOutliningSpans

Function getOutliningSpans

packages/language-service/src/outlining_spans.ts:28–58  ·  view source on GitHub ↗
(compiler: NgCompiler, fileName: string)

Source from the content-addressed store, hash-verified

26import {getFirstComponentForTemplateFile, isTypeScriptFile, toTextSpan} from './utils';
27
28export function getOutliningSpans(compiler: NgCompiler, fileName: string): ts.OutliningSpan[] {
29 if (isTypeScriptFile(fileName)) {
30 const sf = compiler.getCurrentProgram().getSourceFile(fileName);
31 if (sf === undefined) {
32 return [];
33 }
34
35 const templatesInFile: Array<TmplAstNode[]> = [];
36 for (const stmt of sf.statements) {
37 if (isNamedClassDeclaration(stmt)) {
38 const resources = compiler.getDirectiveResources(stmt);
39 if (
40 resources === null ||
41 resources.template === null ||
42 isExternalResource(resources.template)
43 ) {
44 continue;
45 }
46 const template = compiler.getTemplateTypeChecker().getTemplate(stmt);
47 if (template === null) {
48 continue;
49 }
50 templatesInFile.push(template);
51 }
52 }
53 return templatesInFile.map((template) => BlockVisitor.getBlockSpans(template)).flat();
54 } else {
55 const typeCheckInfo = getFirstComponentForTemplateFile(fileName, compiler);
56 return typeCheckInfo === undefined ? [] : BlockVisitor.getBlockSpans(typeCheckInfo.nodes);
57 }
58}
59
60class BlockVisitor extends TmplAstRecursiveVisitor {
61 readonly blocks = [] as Array<TmplAstBlockNode>;

Callers 1

getOutliningSpansMethod · 0.90

Calls 12

isTypeScriptFileFunction · 0.90
isNamedClassDeclarationFunction · 0.90
isExternalResourceFunction · 0.90
getCurrentProgramMethod · 0.80
getDirectiveResourcesMethod · 0.80
mapMethod · 0.80
getBlockSpansMethod · 0.80
getTemplateMethod · 0.65
getSourceFileMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected