public static create()

in src/documents/templates/ChildTemplateCodeLens.ts [114:210]


    public static create(
        fullValidationStatus: IFullValidationStatus | undefined,
        scope: LinkedTemplateScope,
        span: Span,
        linkedTemplateReferences: ILinkedTemplateReference[] | undefined,
        topLevelParameterValuesProvider: IParameterValuesSourceProvider | undefined
    ): ResolvableCodeLens[] {
        const lenses: ResolvableCodeLens[] = [];
        let title: string;
        const isRelativePath = scope.isRelativePath;
        const hasParameterFile = !!topLevelParameterValuesProvider?.parameterFileUri;

        fullValidationStatus = fullValidationStatus ?? {
            hasParameterFile,
            allParametersHaveDefaults: false,
            fullValidationEnabled: hasParameterFile,
        };

        // Currently only dealing with the first reference at the same location (e.g. if in a copy loop, multiple
        // instances will be at the same ilne)
        const firstLinkedTemplateRef = linkedTemplateReferences ? linkedTemplateReferences[0] : undefined;

        if (isRelativePath) {
            title = "Relative linked template";
        } else {
            title = "Linked template";
        }

        if (!fullValidationStatus.fullValidationEnabled) {
            // title += ` ${fullValidationOffMsg}`;
        } else if (!firstLinkedTemplateRef) {
            title += " " + "(cannot validate - make sure all other validation errors have been fixed)";
        }

        let langServerLoadState: string | undefined;

        // If language server not running yet, show language server state instead of file load state
        langServerLoadState = getLoadStateFromLanguageServerStatus();

        let linkedUri: Uri | undefined;
        let friendlyPath: string | undefined;
        let fullPath: string | undefined;
        try {
            const templateUri = scope.document.documentUri;
            linkedUri = firstLinkedTemplateRef?.fullUri ? parseUri(firstLinkedTemplateRef.fullUri) : undefined;
            if (linkedUri && templateUri.fsPath && linkedUri.scheme === documentSchemes.file) {
                const templateFolder = path.dirname(templateUri.fsPath);
                friendlyPath = path.relative(templateFolder, linkedUri.fsPath);
                fullPath = linkedUri.fsPath;
                if (!path.isAbsolute(friendlyPath) && !friendlyPath.startsWith('.')) {
                    friendlyPath = `.${ext.pathSeparator}${friendlyPath}`;
                }
            } else {
                const maxQueryLength = 40;
                let shortenedUri = linkedUri;
                fullPath = linkedUri?.toString(true);
                if (linkedUri && linkedUri?.query.length > maxQueryLength) {
                    shortenedUri = shortenedUri?.with({
                        query: `${linkedUri.query.slice(0, maxQueryLength)}...`
                    });
                }
                friendlyPath = shortenedUri ? shortenedUri.toString(true) : undefined;
            }
        } catch (error) {
            console.warn(parseError(error).message);
        }

        if (firstLinkedTemplateRef && !langServerLoadState) {
            if (friendlyPath) {
                title += `: "${friendlyPath}"`;
            }

            langServerLoadState = getLinkedFileLoadStateLabelSuffix(firstLinkedTemplateRef);
        }

        if (langServerLoadState) {
            title += ` - ${langServerLoadState}`;
        }

        lenses.push(new LinkedTemplateCodeLens(scope, span, title, linkedUri, fullPath));

        addSelectParamFileLensIfNeeded(lenses, fullValidationStatus, topLevelParameterValuesProvider, scope, span);

        // tslint:disable-next-line: no-suspicious-comment
        /* TODO: Need to also resend to language server
        if (!isRelativePath && linkedUri && linkedUri?.scheme !== documentSchemes.file && linkedUri?.scheme !== documentSchemes.untitled) {
            lenses.push(
                new ReloadLinkedTemplateCodeLens(
                    scope,
                    span,
                    linkedUri
                ));
        }
        */

        return lenses;
    }