Merge pull request #178 from github/joshmgross/hover-context-description
Improve hover context description
This commit is contained in:
@@ -21,7 +21,7 @@ jobs:
|
|||||||
const result = await hover(...getPositionFromCursor(input), testHoverConfig("username", "scalar-needs-context"));
|
const result = await hover(...getPositionFromCursor(input), testHoverConfig("username", "scalar-needs-context"));
|
||||||
expect(result).not.toBeUndefined();
|
expect(result).not.toBeUndefined();
|
||||||
expect(result?.contents).toEqual(
|
expect(result?.contents).toEqual(
|
||||||
"A username passed from the caller workflow\n\n**Context:** github, inputs, vars, needs, strategy, matrix"
|
"A username passed from the caller workflow\n\nAvailable expression contexts: `github`, `inputs`, `vars`, `needs`, `strategy`, `matrix`"
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -37,7 +37,9 @@ jobs:
|
|||||||
`;
|
`;
|
||||||
const result = await hover(...getPositionFromCursor(input));
|
const result = await hover(...getPositionFromCursor(input));
|
||||||
expect(result).not.toBeUndefined();
|
expect(result).not.toBeUndefined();
|
||||||
expect(result?.contents).toEqual("**Context:** github, inputs, vars, needs, strategy, matrix");
|
expect(result?.contents).toEqual(
|
||||||
|
"Available expression contexts: `github`, `inputs`, `vars`, `needs`, `strategy`, `matrix`"
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("hover on job output with description", async () => {
|
it("hover on job output with description", async () => {
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ jobs:
|
|||||||
expect(result).not.toBeUndefined();
|
expect(result).not.toBeUndefined();
|
||||||
expect(result?.contents).toEqual(
|
expect(result?.contents).toEqual(
|
||||||
"Prevents a workflow run from failing when a job fails. Set to true to allow a workflow run to pass when this job fails.\n\n" +
|
"Prevents a workflow run from failing when a job fails. Set to true to allow a workflow run to pass when this job fails.\n\n" +
|
||||||
"**Context:** github, inputs, vars, needs, strategy, matrix"
|
"Available expression contexts: `github`, `inputs`, `vars`, `needs`, `strategy`, `matrix`"
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -154,7 +154,7 @@ jobs:
|
|||||||
|
|
||||||
// The `ref` is a `string` definition and inherits the context from `step-with`
|
// The `ref` is a `string` definition and inherits the context from `step-with`
|
||||||
const expected =
|
const expected =
|
||||||
"**Context:** github, inputs, vars, needs, strategy, matrix, secrets, steps, job, runner, env, hashFiles(1,255)";
|
"Available expression contexts: `github`, `inputs`, `vars`, `needs`, `strategy`, `matrix`, `secrets`, `steps`, `job`, `runner`, `env`, `hashFiles(1,255)`";
|
||||||
expect(result?.contents).toEqual(expected);
|
expect(result?.contents).toEqual(expected);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -180,7 +180,7 @@ jobs:
|
|||||||
|
|
||||||
const expected =
|
const expected =
|
||||||
"The branch, tag or SHA to checkout.\n\n" +
|
"The branch, tag or SHA to checkout.\n\n" +
|
||||||
"**Context:** github, inputs, vars, needs, strategy, matrix, secrets, steps, job, runner, env, hashFiles(1,255)";
|
"Available expression contexts: `github`, `inputs`, `vars`, `needs`, `strategy`, `matrix`, `secrets`, `steps`, `job`, `runner`, `env`, `hashFiles(1,255)`";
|
||||||
expect(result?.contents).toEqual(expected);
|
expect(result?.contents).toEqual(expected);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -109,11 +109,16 @@ export async function hover(document: TextDocument, position: Position, config?:
|
|||||||
}
|
}
|
||||||
|
|
||||||
function appendContext(description: string, allowedContext?: string[]) {
|
function appendContext(description: string, allowedContext?: string[]) {
|
||||||
if (allowedContext && allowedContext?.length > 0) {
|
if (!allowedContext || allowedContext.length == 0) {
|
||||||
// Only add padding if there is a description
|
return description;
|
||||||
description += `${description.length > 0 ? `\n\n` : ""}**Context:** ${allowedContext.join(", ")}`;
|
|
||||||
}
|
}
|
||||||
return description;
|
|
||||||
|
const contextDescription = `Available expression contexts: ${allowedContext.map(c => `\`${c}\``).join(", ")}`;
|
||||||
|
if (description.length == 0) {
|
||||||
|
return contextDescription;
|
||||||
|
}
|
||||||
|
|
||||||
|
return `${description}\n\n${contextDescription}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getDescription(
|
async function getDescription(
|
||||||
|
|||||||
Reference in New Issue
Block a user