Fix hover over 'cron:' token

This commit is contained in:
Jacob Wallraff
2023-01-23 16:53:29 -08:00
parent d3d55ffc08
commit 615ba46960
2 changed files with 17 additions and 4 deletions
+10
View File
@@ -91,6 +91,16 @@ jobs:
);
});
it("on a cron identifier", async () => {
const input = `on:
schedule:
- c|ron: '0 0 * * *'
`;
const result = await hover(...getPositionFromCursor(input));
expect(result).not.toBeUndefined();
expect(result?.contents).toEqual("");
});
it("on an invalid cron schedule", async () => {
const input = `on:
schedule:
+7 -4
View File
@@ -33,8 +33,9 @@ function getHover(tokenResult: TokenResult): Hover | null {
if (!token) {
return null;
}
if (tokenResult.parent && isCronMapping(tokenResult.parent) && isString(token)) {
let description = getSentence((token as StringToken).value);
if (tokenResult.parent && isCronMappingValue(tokenResult)) {
const tokenValue = (token as StringToken).value
let description = getSentence(tokenValue);
if (description) {
description +=
"\n\nActions schedules run at most every 5 minutes." +
@@ -72,6 +73,8 @@ function getHover(tokenResult: TokenResult): Hover | null {
return null;
}
function isCronMapping(token: TemplateToken): boolean {
return token.definition?.key === "cron-mapping";
function isCronMappingValue(tokenResult: TokenResult): boolean {
return tokenResult.parent?.definition?.key === "cron-mapping" &&
(tokenResult.token as StringToken).value !== "cron" &&
isString(tokenResult.token!);
}