Skip to content

Commit

Permalink
#512 add snippet for inline task
Browse files Browse the repository at this point in the history
Signed-off-by: Yevhen Vydolob <yvydolob@redhat.com>
  • Loading branch information
evidolob committed Apr 8, 2021
1 parent 96cec31 commit fe3d348
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
17 changes: 16 additions & 1 deletion src/yaml-support/tkn-yaml-scheme-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,21 @@ export function generateScheme(vsDocument: vscode.TextDocument, schemaPath: stri

// eslint-disable-next-line @typescript-eslint/no-explicit-any
function injectTaskSnippets(templateObj: any, snippets: Snippet<{}>[]): {} {
snippets.push({
label: 'inline task',
description: 'Snippet for inline task',
body: {
name: '$1',
taskSpec: {
steps: [
{
name: '$2\n',
}
]
}
},

})
templateObj.definitions.PipelineSpec.properties.tasks.defaultSnippets = snippets;
return templateObj;
}
Expand Down Expand Up @@ -183,7 +198,7 @@ async function generate(doc: vscode.TextDocument, schemaPath: string): Promise<s

const resNames = declaredResources.map(item => item.name);
const templateObj = JSON.parse(template);
let templateWithSnippets = injectTaskSnippets(templateObj, snippets);
let templateWithSnippets = injectTaskSnippets(templateObj, [...snippets]);
const tasksRef = snippets.map(value => value.body.taskRef.name);
const customTasks = pipelineYaml.getCustomTasks(doc);
if (customTasks.length > 0){
Expand Down
2 changes: 1 addition & 1 deletion src/yaml-support/tkn-yaml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,7 @@ function getTasksSeq(specMap: YamlMap): YamlSequence | undefined {
}

export function findNodeAndKeyByKeyValue<K, T>(key: string, yamlMap: YamlMap): [K, T] | undefined {
if (!yamlMap) {
if (!yamlMap || !yamlMap.mappings) {
return;
}
const mapItem = yamlMap.mappings.find(item => item.key.raw === key);
Expand Down

0 comments on commit fe3d348

Please sign in to comment.