Show cron description on hover (#291)
Related #286 - When hovering over a cron expression, show the human-readable description instead of empty content. Users who have inlay hints disabled can now still see the cron description.
This commit is contained in:
@@ -110,8 +110,7 @@ jobs:
|
|||||||
`;
|
`;
|
||||||
const result = await hover(...getPositionFromCursor(input));
|
const result = await hover(...getPositionFromCursor(input));
|
||||||
expect(result).not.toBeUndefined();
|
expect(result).not.toBeUndefined();
|
||||||
// Cron description is now shown via diagnostics, not hover
|
expect(result?.contents).toEqual("Runs at 0 and 30 minutes past the hour, at 00:00 and 12:00");
|
||||||
expect(result?.contents).toEqual("");
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("on a cron mapping key", async () => {
|
it("on a cron mapping key", async () => {
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ import {data, DescriptionDictionary, Parser} from "@actions/expressions";
|
|||||||
import {FunctionDefinition, FunctionInfo} from "@actions/expressions/funcs/info";
|
import {FunctionDefinition, FunctionInfo} from "@actions/expressions/funcs/info";
|
||||||
import {Lexer} from "@actions/expressions/lexer";
|
import {Lexer} from "@actions/expressions/lexer";
|
||||||
import {parseAction} from "@actions/workflow-parser/actions/action-parser";
|
import {parseAction} from "@actions/workflow-parser/actions/action-parser";
|
||||||
|
import {isString} from "@actions/workflow-parser";
|
||||||
|
import {getCronDescription} from "@actions/workflow-parser/model/converter/cron";
|
||||||
import {ErrorPolicy} from "@actions/workflow-parser/model/convert";
|
import {ErrorPolicy} from "@actions/workflow-parser/model/convert";
|
||||||
import {splitAllowedContext} from "@actions/workflow-parser/templates/allowed-context";
|
import {splitAllowedContext} from "@actions/workflow-parser/templates/allowed-context";
|
||||||
import {TemplateToken} from "@actions/workflow-parser/templates/tokens/template-token";
|
import {TemplateToken} from "@actions/workflow-parser/templates/tokens/template-token";
|
||||||
@@ -134,6 +136,17 @@ export async function hover(document: TextDocument, position: Position, config?:
|
|||||||
// Non-expression hover: show the schema description for the YAML key or value
|
// Non-expression hover: show the schema description for the YAML key or value
|
||||||
info(`Calculating hover for token with definition ${hoverToken.definition.key}`);
|
info(`Calculating hover for token with definition ${hoverToken.definition.key}`);
|
||||||
|
|
||||||
|
// Check for cron expression hover
|
||||||
|
if (isString(hoverToken) && hoverToken.definition.key === "cron-pattern") {
|
||||||
|
const cronDescription = getCronDescription(hoverToken.value);
|
||||||
|
if (cronDescription) {
|
||||||
|
return {
|
||||||
|
contents: cronDescription,
|
||||||
|
range: mapRange(hoverToken.range)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let description: string;
|
let description: string;
|
||||||
if (!isAction && tokenResult.parent && isReusableWorkflowJobInput(tokenResult)) {
|
if (!isAction && tokenResult.parent && isReusableWorkflowJobInput(tokenResult)) {
|
||||||
// Reusable workflow call: fetch the called workflow's input descriptions
|
// Reusable workflow call: fetch the called workflow's input descriptions
|
||||||
|
|||||||
Reference in New Issue
Block a user