Skip to content

Commit fe3d348

Browse files
committed
redhat-developer#512 add snippet for inline task
Signed-off-by: Yevhen Vydolob <[email protected]>
1 parent 96cec31 commit fe3d348

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

src/yaml-support/tkn-yaml-scheme-generator.ts

+16-1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,21 @@ export function generateScheme(vsDocument: vscode.TextDocument, schemaPath: stri
4848

4949
// eslint-disable-next-line @typescript-eslint/no-explicit-any
5050
function injectTaskSnippets(templateObj: any, snippets: Snippet<{}>[]): {} {
51+
snippets.push({
52+
label: 'inline task',
53+
description: 'Snippet for inline task',
54+
body: {
55+
name: '$1',
56+
taskSpec: {
57+
steps: [
58+
{
59+
name: '$2\n',
60+
}
61+
]
62+
}
63+
},
64+
65+
})
5166
templateObj.definitions.PipelineSpec.properties.tasks.defaultSnippets = snippets;
5267
return templateObj;
5368
}
@@ -183,7 +198,7 @@ async function generate(doc: vscode.TextDocument, schemaPath: string): Promise<s
183198

184199
const resNames = declaredResources.map(item => item.name);
185200
const templateObj = JSON.parse(template);
186-
let templateWithSnippets = injectTaskSnippets(templateObj, snippets);
201+
let templateWithSnippets = injectTaskSnippets(templateObj, [...snippets]);
187202
const tasksRef = snippets.map(value => value.body.taskRef.name);
188203
const customTasks = pipelineYaml.getCustomTasks(doc);
189204
if (customTasks.length > 0){

src/yaml-support/tkn-yaml.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -669,7 +669,7 @@ function getTasksSeq(specMap: YamlMap): YamlSequence | undefined {
669669
}
670670

671671
export function findNodeAndKeyByKeyValue<K, T>(key: string, yamlMap: YamlMap): [K, T] | undefined {
672-
if (!yamlMap) {
672+
if (!yamlMap || !yamlMap.mappings) {
673673
return;
674674
}
675675
const mapItem = yamlMap.mappings.find(item => item.key.raw === key);

0 commit comments

Comments
 (0)