Skip to content

Commit dbf7752

Browse files
authored
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.
1 parent 7823148 commit dbf7752

2 files changed

Lines changed: 14 additions & 2 deletions

File tree

languageservice/src/hover.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,7 @@ jobs:
110110
`;
111111
const result = await hover(...getPositionFromCursor(input));
112112
expect(result).not.toBeUndefined();
113-
// Cron description is now shown via diagnostics, not hover
114-
expect(result?.contents).toEqual("");
113+
expect(result?.contents).toEqual("Runs at 0 and 30 minutes past the hour, at 00:00 and 12:00");
115114
});
116115

117116
it("on a cron mapping key", async () => {

languageservice/src/hover.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import {data, DescriptionDictionary, Parser} from "@actions/expressions";
22
import {FunctionDefinition, FunctionInfo} from "@actions/expressions/funcs/info";
33
import {Lexer} from "@actions/expressions/lexer";
44
import {parseAction} from "@actions/workflow-parser/actions/action-parser";
5+
import {isString} from "@actions/workflow-parser";
6+
import {getCronDescription} from "@actions/workflow-parser/model/converter/cron";
57
import {ErrorPolicy} from "@actions/workflow-parser/model/convert";
68
import {splitAllowedContext} from "@actions/workflow-parser/templates/allowed-context";
79
import {TemplateToken} from "@actions/workflow-parser/templates/tokens/template-token";
@@ -134,6 +136,17 @@ export async function hover(document: TextDocument, position: Position, config?:
134136
// Non-expression hover: show the schema description for the YAML key or value
135137
info(`Calculating hover for token with definition ${hoverToken.definition.key}`);
136138

139+
// Check for cron expression hover
140+
if (isString(hoverToken) && hoverToken.definition.key === "cron-pattern") {
141+
const cronDescription = getCronDescription(hoverToken.value);
142+
if (cronDescription) {
143+
return {
144+
contents: cronDescription,
145+
range: mapRange(hoverToken.range)
146+
};
147+
}
148+
}
149+
137150
let description: string;
138151
if (!isAction && tokenResult.parent && isReusableWorkflowJobInput(tokenResult)) {
139152
// Reusable workflow call: fetch the called workflow's input descriptions

0 commit comments

Comments
 (0)