Use file provider in test
This commit is contained in:
@@ -1,13 +1,26 @@
|
||||
import {isString} from "@github/actions-workflow-parser";
|
||||
import {StringToken} from "@github/actions-workflow-parser/templates/tokens/string-token";
|
||||
import {CompletionItem, MarkupContent} from "vscode-languageserver-types";
|
||||
import {DescriptionProvider, hover, HoverConfig} from "./hover";
|
||||
import {testHoverConfig} from "./hover.test";
|
||||
import {getPositionFromCursor} from "./test-utils/cursor-position";
|
||||
import {testFileProvider} from "./test-utils/test-file-provider";
|
||||
|
||||
function mapResult(result: CompletionItem[]) {
|
||||
return result.map(x => {
|
||||
return {label: x.label, description: (x.documentation as MarkupContent).value};
|
||||
});
|
||||
export function testHoverReusableWorkflowConfig(tokenValue: string, tokenKey: string) {
|
||||
return {
|
||||
descriptionProvider: {
|
||||
getDescription: async (_, token, __) => {
|
||||
if (!isString(token)) {
|
||||
throw new Error("Test provider only supports string tokens");
|
||||
}
|
||||
|
||||
expect((token as StringToken).value).toEqual(tokenValue);
|
||||
expect(token.definition!.key).toEqual(tokenKey);
|
||||
|
||||
return token.description;
|
||||
}
|
||||
} satisfies DescriptionProvider,
|
||||
fileProvider: testFileProvider
|
||||
} satisfies HoverConfig;
|
||||
}
|
||||
|
||||
describe("completion with reusable workflows", () => {
|
||||
@@ -23,7 +36,7 @@ jobs:
|
||||
`;
|
||||
const result = await hover(
|
||||
...getPositionFromCursor(input),
|
||||
{fileProvider: testFileProvider}
|
||||
testHoverReusableWorkflowConfig("username", "scalar-needs-context")
|
||||
);
|
||||
expect(result).not.toBeUndefined();
|
||||
expect(result?.contents).toEqual(
|
||||
|
||||
@@ -2,6 +2,7 @@ import {DescriptionDictionary, Parser} from "@github/actions-expressions";
|
||||
import {FunctionInfo} from "@github/actions-expressions/funcs/info";
|
||||
import {Lexer} from "@github/actions-expressions/lexer";
|
||||
import {convertWorkflowTemplate, parseWorkflow, ParseWorkflowResult} from "@github/actions-workflow-parser";
|
||||
import {WorkflowTemplate} from "@github/actions-workflow-parser";
|
||||
import {ErrorPolicy} from "@github/actions-workflow-parser/model/convert";
|
||||
import {getCronDescription} from "@github/actions-workflow-parser/model/converter/cron";
|
||||
import {splitAllowedContext} from "@github/actions-workflow-parser/templates/allowed-context";
|
||||
@@ -35,7 +36,7 @@ export type DescriptionProvider = {
|
||||
context: WorkflowContext,
|
||||
token: TemplateToken,
|
||||
path: TemplateToken[],
|
||||
fileProvider?: FileProvider
|
||||
template?: WorkflowTemplate
|
||||
): Promise<string | undefined>
|
||||
};
|
||||
|
||||
@@ -110,8 +111,8 @@ async function getDescription(
|
||||
path: TemplateToken[]
|
||||
) {
|
||||
const defaultDescription = token.description || "";
|
||||
// TODO fix this check
|
||||
if (!result?.value || !config?.descriptionProvider) {
|
||||
// TODO fix this check - description provider is null for rusable workflows
|
||||
if (!result?.value/* || !config?.descriptionProvider*/) {
|
||||
return defaultDescription;
|
||||
}
|
||||
|
||||
@@ -125,7 +126,7 @@ async function getDescription(
|
||||
}
|
||||
);
|
||||
const workflowContext = getWorkflowContext(document.uri, template, path);
|
||||
const description = await config.descriptionProvider.getDescription(workflowContext, token, path, config.fileProvider);
|
||||
const description = await config?.descriptionProvider?.getDescription(workflowContext, token, path, template);
|
||||
return description || defaultDescription;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user