Rename helper

This commit is contained in:
Christopher Schleiden
2023-02-02 13:14:02 -08:00
parent 903c813ad1
commit 1faf6572b7
3 changed files with 11 additions and 17 deletions
+2 -5
View File
@@ -21,12 +21,12 @@ import {getWorkflowContext, WorkflowContext} from "./context/workflow-context";
import {validatorFunctions} from "./expression-validation/functions";
import {error} from "./log";
import {nullTrace} from "./nulltrace";
import {isPotentiallyExpression} from "./utils/expression-detection";
import {findToken} from "./utils/find-token";
import {guessIndentation} from "./utils/indentation-guesser";
import {mapRange} from "./utils/range";
import {getRelCharOffset} from "./utils/rel-char-pos";
import {transform} from "./utils/transform";
import {isStringExpression} from "./utils/type-guards";
import {Value, ValueProviderConfig} from "./value-providers/config";
import {defaultValueProviders} from "./value-providers/default";
import {definitionValues} from "./value-providers/definition";
@@ -77,10 +77,7 @@ export async function complete(
// If we are inside an expression, take a different code-path. The workflow parser does not correctly create
// expression nodes for invalid expressions and during editing expressions are invalid most of the time.
if (token) {
const isStringExpressionToken = isStringExpression(token);
const isBasicExpressionToken = isBasicExpression(token);
if (isStringExpressionToken || isBasicExpressionToken) {
if (isBasicExpression(token) || isPotentiallyExpression(token)) {
const allowedContext = token.definitionInfo?.allowedContext || [];
const context = await getContext(allowedContext, contextProviderConfig, workflowContext, Mode.Completion);
+6 -9
View File
@@ -19,9 +19,9 @@ import {HoverVisitor} from "./expression-hover/visitor";
import {validatorFunctions} from "./expression-validation/functions";
import {info} from "./log";
import {nullTrace} from "./nulltrace";
import {isPotentiallyExpression} from "./utils/expression-detection";
import {findToken, TokenResult} from "./utils/find-token";
import {mapRange} from "./utils/range";
import {isStringExpression} from "./utils/type-guards";
export type HoverConfig = {
descriptionProvider?: DescriptionProvider;
@@ -45,15 +45,12 @@ export async function hover(document: TextDocument, position: Position, config?:
const tokenResult = findToken(position, result.value);
const {token, keyToken, parent} = tokenResult;
const hoverToken = keyToken || parent || token;
if (config?.contextProviderConfig && token && hoverToken?.definition) {
const isStringExpressionToken = isStringExpression(token);
const isBasicExpressionToken = isBasicExpression(token);
const tokenDefinitionInfo = (keyToken || parent || token)?.definitionInfo;
if (config?.contextProviderConfig && token && tokenDefinitionInfo) {
if (isBasicExpression(token) || isPotentiallyExpression(token)) {
info(`Calculating expression hover for token with definition ${tokenDefinitionInfo.definition.key}`);
if (isStringExpressionToken || isBasicExpressionToken) {
info(`Calculating expression hover for token with definition ${hoverToken.definition.key}`);
const allowedContext = hoverToken.definitionInfo?.allowedContext || [];
const allowedContext = tokenDefinitionInfo.allowedContext || [];
const {namedContexts, functions} = splitAllowedContext(allowedContext);
const template = convertWorkflowTemplate(result.context, result.value, ErrorPolicy.TryConversion);
@@ -4,9 +4,9 @@ import {StringDefinition} from "@github/actions-workflow-parser/templates/schema
import {OPEN_EXPRESSION} from "@github/actions-workflow-parser/templates/template-constants";
import {TemplateToken} from "@github/actions-workflow-parser/templates/tokens/index";
export function isStringExpression(token: TemplateToken): boolean {
const isExpression =
export function isPotentiallyExpression(token: TemplateToken): boolean {
const isAlwaysExpression =
token.definition?.definitionType === DefinitionType.String && (token.definition as StringDefinition).isExpression;
const containsExpression = isString(token) && token.value.indexOf(OPEN_EXPRESSION) >= 0;
return isExpression || containsExpression;
return isAlwaysExpression || containsExpression;
}