diff --git a/actions-languageservice/src/complete.ts b/actions-languageservice/src/complete.ts index 1ba93ad..3b0d218 100644 --- a/actions-languageservice/src/complete.ts +++ b/actions-languageservice/src/complete.ts @@ -89,12 +89,13 @@ export async function complete( } } - const values = await getValues(token, parent, valueProviderConfig, workflowContext); + const values = await getValues(token, keyToken, parent, valueProviderConfig, workflowContext); return values.map(value => CompletionItem.create(value.label)); } async function getValues( token: TemplateToken | null, + keyToken: TemplateToken | null, parent: TemplateToken | null, valueProviderConfig: ValueProviderConfig | undefined, workflowContext: WorkflowContext @@ -105,8 +106,8 @@ async function getValues( const existingValues = getExistingValues(token, parent); - if (token?.definition?.key) { - const customValues = await valueProviderConfig?.[token.definition.key]?.get(workflowContext); + if (keyToken?.definition?.key) { + const customValues = await valueProviderConfig?.[keyToken.definition.key]?.get(workflowContext); if (customValues) { return filterAndSortCompletionOptions(customValues, existingValues); @@ -115,7 +116,7 @@ async function getValues( // Use the value provider from the parent if we don't have a value provider for the current key const valueProvider = - (token?.definition?.key && defaultValueProviders[token.definition.key]) || + (keyToken?.definition?.key && defaultValueProviders[keyToken.definition.key]) || (parent.definition?.key && defaultValueProviders[parent.definition.key]); if (valueProvider) { @@ -124,7 +125,7 @@ async function getValues( } // Use the definition if there are no value providers - const def = token?.definition || parent.definition; + const def = keyToken?.definition || parent.definition; if (!def) { return []; } diff --git a/actions-languageservice/src/hover.ts b/actions-languageservice/src/hover.ts index 388236e..ba272dc 100644 --- a/actions-languageservice/src/hover.ts +++ b/actions-languageservice/src/hover.ts @@ -17,43 +17,35 @@ export async function hover(document: TextDocument, position: Position): Promise const {token, keyToken, parent} = findToken(position, result.value); if (result.value && token) { - // If the parent is a MappingToken and no keyToken was returned, our token is the key - if (parent && isMapping(parent) && !keyToken) { - const value = parent.find(token.toString()); - if (value) { - return getHover(token, value); - } - } + return getHover(token); } return null; } -// PositionToken is the token that the cursor is on -// DescriptionToken may differ if the description is stored on an associated token, such as when hovering over a key in a mapping -function getHover(positionToken: TemplateToken, descriptionToken: TemplateToken): Hover | null { - if (descriptionToken.definition) { +function getHover(token: TemplateToken): Hover | null { + if (token.definition) { let description = ""; - if (descriptionToken.description) { - description = descriptionToken.description; + if (token.description) { + description = token.description; } - if (descriptionToken.definition.evaluatorContext.length > 0) { + if (token.definition.evaluatorContext.length > 0) { // Only add padding if there is a description - description += `${ - description.length > 0 ? `\n\n` : "" - }**Context:** ${descriptionToken.definition.evaluatorContext.join(", ")}`; + description += `${description.length > 0 ? `\n\n` : ""}**Context:** ${token.definition.evaluatorContext.join( + ", " + )}`; } return { contents: description, range: { start: { - line: positionToken.range!.start[0] - 1, - character: positionToken.range!.start[1] - 1 + line: token.range!.start[0] - 1, + character: token.range!.start[1] - 1 }, end: { - line: positionToken.range!.end[0] - 1, - character: positionToken.range!.end[1] - 1 + line: token.range!.end[0] - 1, + character: token.range!.end[1] - 1 } } } as Hover;