2022-11-15 14:08:12 -05:00
|
|
|
import {parseWorkflow, ParseWorkflowResult} from "@github/actions-workflow-parser";
|
|
|
|
|
import {TemplateToken} from "@github/actions-workflow-parser/templates/tokens/template-token";
|
|
|
|
|
import {MappingToken} from "@github/actions-workflow-parser/templates/tokens/mapping-token";
|
|
|
|
|
import {SequenceToken} from "@github/actions-workflow-parser/templates/tokens/sequence-token";
|
|
|
|
|
import {File} from "@github/actions-workflow-parser/workflows/file";
|
|
|
|
|
import {Position, TextDocument} from "vscode-languageserver-textdocument";
|
|
|
|
|
import {Hover} from "vscode-languageserver-types";
|
|
|
|
|
import {nullTrace} from "./nulltrace";
|
|
|
|
|
import {findInnerToken} from "./utils/find-token";
|
2022-11-08 17:00:59 -08:00
|
|
|
|
2022-11-15 14:08:12 -05:00
|
|
|
export async function hover(document: TextDocument, position: Position): Promise<Hover | null> {
|
2022-11-08 17:00:59 -08:00
|
|
|
const file: File = {
|
|
|
|
|
name: document.uri,
|
2022-11-15 14:08:12 -05:00
|
|
|
content: document.getText()
|
2022-11-08 17:00:59 -08:00
|
|
|
};
|
|
|
|
|
const result = parseWorkflow(file.name, [file], nullTrace);
|
|
|
|
|
|
|
|
|
|
// Find inner token returns null if position is not in a token
|
|
|
|
|
const innerToken = findInnerToken(position, result.value);
|
|
|
|
|
if (result.value && innerToken) {
|
|
|
|
|
return getHover(innerToken);
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getHover(innerToken: TemplateToken): Hover | null {
|
|
|
|
|
if (innerToken.definition) {
|
|
|
|
|
let description = "";
|
|
|
|
|
if (innerToken.description) {
|
|
|
|
|
description = innerToken.description;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (innerToken.definition.evaluatorContext.length > 0) {
|
|
|
|
|
// Only add padding if there is a description
|
2022-11-15 14:08:12 -05:00
|
|
|
description += `${description.length > 0 ? `\n\n` : ""}**Context:** ${innerToken.definition.evaluatorContext.join(
|
|
|
|
|
", "
|
|
|
|
|
)}`;
|
2022-11-08 17:00:59 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
contents: description,
|
|
|
|
|
range: {
|
|
|
|
|
start: {
|
|
|
|
|
line: innerToken.range!.start[0],
|
2022-11-15 14:08:12 -05:00
|
|
|
character: innerToken.range!.start[1]
|
2022-11-08 17:00:59 -08:00
|
|
|
},
|
|
|
|
|
end: {
|
|
|
|
|
line: innerToken.range!.end[0],
|
2022-11-15 14:08:12 -05:00
|
|
|
character: innerToken.range!.end[1]
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-11-08 17:00:59 -08:00
|
|
|
} as Hover;
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|