Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/providers/completionProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ export class CompletionProvider implements vscode.CompletionItemProvider {
}
try {
const fetched = await getComponentService().getComponentFromUrl(expandedUrl);
if (!fetched) {
if (!fetched || fetched.fetchFailure) {
return null;
}
getComponentCacheManager().addDynamicComponent({
Expand Down
2 changes: 1 addition & 1 deletion src/providers/componentDetector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ export async function detectIncludeComponent(document: vscode.TextDocument, posi
const componentService = getComponentService();
const specificVersionComponent = await componentService.getComponentFromUrl(componentUrl);

if (specificVersionComponent) {
if (specificVersionComponent && !specificVersionComponent.fetchFailure) {
logger.debug(`[ComponentDetector] Successfully fetched specific version ${requestedVersion} for ${cachedComponent.name}`, 'ComponentDetector');

const cacheVersion = requestedVersion || 'main';
Expand Down
10 changes: 10 additions & 0 deletions src/providers/validationProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ export class ValidationProvider implements vscode.CodeActionProvider {
}

this.logger.debug(`[ValidationProvider] Validating ${document.fileName}`, 'ValidationProvider');
const validatedVersion = document.version;
const findings = await validateIncludes({
text: document.getText(),
file: document.uri.fsPath,
Expand All @@ -150,6 +151,12 @@ export class ValidationProvider implements vscode.CodeActionProvider {
resolveLocalInclude: localPath => resolveLocalIncludeOutcome(localPath, document),
});

// A slow pass on a half-typed ref would overwrite the newer pass; the edit already scheduled one for this text.
if (document.version !== validatedVersion) {
this.logger.debug(`[ValidationProvider] Discarding stale findings for ${document.fileName} (v${validatedVersion}, now v${document.version})`, 'ValidationProvider');
return;
}

this.logger.debug(`[ValidationProvider] Created ${findings.length} total diagnostics for ${document.fileName}`, 'ValidationProvider');
this.diagnosticCollection.set(document.uri, findings.map(findingToDiagnostic));
}
Expand All @@ -167,6 +174,9 @@ export class ValidationProvider implements vscode.CodeActionProvider {
*/
private async fetchComponent(expandedUrl: string): Promise<Component | null> {
const fetchedComponent = await getComponentService().getComponentFromUrl(expandedUrl);
if (fetchedComponent?.fetchFailure) {
return null;
}
if (fetchedComponent) {
this.addComponentToCache(expandedUrl, fetchedComponent);
return fetchedComponent;
Expand Down
17 changes: 8 additions & 9 deletions src/services/component/componentFetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import type { GitLabProjectInfo, GitLabTreeItem } from '../../types/api';
import { HttpClient } from '../../utils/httpClient';
import { Logger } from '../../utils/logger';
import { GitLabSpecParser, ComponentVariable } from '../../parsers/specParser';
import { classifyFetchFailure, isAuthError } from '../../errors';
import { classifyFetchFailure, isAuthError, NetworkError } from '../../errors';
import { TokenManager } from './tokenManager';
import { UrlParser } from './urlParser';
import {
Expand Down Expand Up @@ -212,15 +212,14 @@ export class ComponentFetcher {

const project = projectInfo.value;

// Process template result
let resolvedTemplatePath: string | undefined;
if (templateResult.status === 'fulfilled' && templateResult.value) {
const { content, parameters: extractedParams, templatePath } = templateResult.value;
templateContent = content;
parameters = extractedParams;
resolvedTemplatePath = templatePath;
this.logger.debug(`Found component template with ${parameters.length} parameters at ${templatePath}`);
// A component with no inputs would flag every provided input as unknown.
if (templateResult.status !== 'fulfilled' || !templateResult.value) {
throw new NetworkError(`No template for component '${componentName}' at ref '${version}'`, { statusCode: 404 });
}
const { content, parameters: extractedParams, templatePath: resolvedTemplatePath } = templateResult.value;
templateContent = content;
parameters = extractedParams;
this.logger.debug(`Found component template with ${parameters.length} parameters at ${resolvedTemplatePath}`);

// A component's README sits next to its template; fall back to the repo root for flat layouts.
const readmeDirs = [readmeDirForTemplate(resolvedTemplatePath), ''];
Expand Down
14 changes: 12 additions & 2 deletions tests/unit/componentFetcherUrl.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// @mocha
/**
* `fetchComponentMetadata` must address the right project and ref for a component URL whose version contains `/`
* (a branch such as `feature/my-branch`). The HTTP client is a fake that records every URL it is asked for, so
* nothing leaves the process.
* (a branch such as `feature/my-branch`), and report a ref with no template as not found. The HTTP client is a fake
* that records every URL it is asked for, so nothing leaves the process.
*/

import * as assert from 'node:assert/strict';
Expand Down Expand Up @@ -63,6 +63,16 @@ suite('ComponentFetcher.fetchComponentMetadata with a slashed version', () => {
assert.deepEqual(component.parameters.map((p) => p.name), ['stage']);
});

test('fails as not-found, not as a component with no inputs, when the ref has no template', async () => {
const fetcher = new ComponentFetcher(createFakeHttp([], true), new TokenManager(), new UrlParser());

const component = await fetcher.fetchComponentMetadata(`https://gitlab.com/${PROJECT_PATH}/other-component@${BRANCH}`);

assert.deepEqual(component.fetchFailure, { kind: 'not-found', statusCode: NOT_FOUND });
assert.equal(component.name, 'other-component');
assert.deepEqual(component.parameters, []);
});

test('names the fallback component after the component, not the branch', async () => {
const fetcher = new ComponentFetcher(createFakeHttp([], false), new TokenManager(), new UrlParser());

Expand Down
Loading