Fix action snippet completions: sort order, indent, and $ escaping (#300)
This commit is contained in:
@@ -265,8 +265,8 @@ runs:
|
|||||||
const usingCompletion = completions.find(c => c.label === "using");
|
const usingCompletion = completions.find(c => c.label === "using");
|
||||||
expect(usingCompletion).toBeDefined();
|
expect(usingCompletion).toBeDefined();
|
||||||
|
|
||||||
// It should have a sortText that makes it sort first
|
// It should have a sortText that makes it sort after snippets
|
||||||
expect(usingCompletion?.sortText).toBe("0_using");
|
expect(usingCompletion?.sortText).toBe("9_using");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("completes step keys inside composite action steps", async () => {
|
it("completes step keys inside composite action steps", async () => {
|
||||||
|
|||||||
@@ -83,14 +83,15 @@ runs:
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
const ACTION_SNIPPET_NODEJS_USING = `# For more on JavaScript actions (including @actions/toolkit), see:
|
const ACTION_SNIPPET_NODEJS_USING = `# For more on JavaScript actions (including @actions/toolkit), see:
|
||||||
# https://docs.github.com/en/actions/sharing-automations/creating-actions/creating-a-javascript-action
|
# https://docs.github.com/en/actions/sharing-automations/creating-actions/creating-a-javascript-action
|
||||||
using: node24
|
using: node24
|
||||||
main: index.js
|
main: index.js
|
||||||
# Sample index.js (vanilla JS, no build required):
|
# Sample index.js (vanilla JS, no build required):
|
||||||
#
|
#
|
||||||
# console.log('Hello World');
|
# console.log('Hello World');
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
/* eslint-disable no-useless-escape -- \$ is required to escape $ in VS Code snippets */
|
||||||
const ACTION_SNIPPET_COMPOSITE_FULL = `name: '\${1:Action Name}'
|
const ACTION_SNIPPET_COMPOSITE_FULL = `name: '\${1:Action Name}'
|
||||||
description: '\${2:What this action does}'
|
description: '\${2:What this action does}'
|
||||||
|
|
||||||
@@ -115,9 +116,9 @@ runs:
|
|||||||
env:
|
env:
|
||||||
INPUT_NAME: \\\${{ inputs.name }}
|
INPUT_NAME: \\\${{ inputs.name }}
|
||||||
run: |
|
run: |
|
||||||
GREETING="Hello $INPUT_NAME"
|
GREETING="Hello \$INPUT_NAME"
|
||||||
echo "$GREETING"
|
echo "\$GREETING"
|
||||||
echo "greeting=$GREETING" >> $GITHUB_OUTPUT
|
echo "greeting=\$GREETING" >> \$GITHUB_OUTPUT
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const ACTION_SNIPPET_COMPOSITE_RUNS = `inputs:
|
const ACTION_SNIPPET_COMPOSITE_RUNS = `inputs:
|
||||||
@@ -141,15 +142,15 @@ runs:
|
|||||||
env:
|
env:
|
||||||
INPUT_NAME: \\\${{ inputs.name }}
|
INPUT_NAME: \\\${{ inputs.name }}
|
||||||
run: |
|
run: |
|
||||||
GREETING="Hello $INPUT_NAME"
|
GREETING="Hello \$INPUT_NAME"
|
||||||
echo "$GREETING"
|
echo "\$GREETING"
|
||||||
echo "greeting=$GREETING" >> $GITHUB_OUTPUT
|
echo "greeting=\$GREETING" >> \$GITHUB_OUTPUT
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const ACTION_SNIPPET_COMPOSITE_USING = `# For more on composite actions, see:
|
const ACTION_SNIPPET_COMPOSITE_USING = `# For more on composite actions, see:
|
||||||
# https://docs.github.com/en/actions/sharing-automations/creating-actions/creating-a-composite-action
|
# https://docs.github.com/en/actions/sharing-automations/creating-actions/creating-a-composite-action
|
||||||
using: composite
|
using: composite
|
||||||
steps:
|
steps:
|
||||||
- shell: bash
|
- shell: bash
|
||||||
run: echo "Hello World"
|
run: echo "Hello World"
|
||||||
`;
|
`;
|
||||||
@@ -179,9 +180,9 @@ runs:
|
|||||||
args:
|
args:
|
||||||
- -c
|
- -c
|
||||||
- |
|
- |
|
||||||
GREETING="Hello $INPUT_NAME"
|
GREETING="Hello \$INPUT_NAME"
|
||||||
echo "$GREETING"
|
echo "\$GREETING"
|
||||||
echo "greeting=$GREETING" >> $GITHUB_OUTPUT
|
echo "greeting=\$GREETING" >> \$GITHUB_OUTPUT
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const ACTION_SNIPPET_DOCKER_RUNS = `inputs:
|
const ACTION_SNIPPET_DOCKER_RUNS = `inputs:
|
||||||
@@ -206,18 +207,19 @@ runs:
|
|||||||
args:
|
args:
|
||||||
- -c
|
- -c
|
||||||
- |
|
- |
|
||||||
GREETING="Hello $INPUT_NAME"
|
GREETING="Hello \$INPUT_NAME"
|
||||||
echo "$GREETING"
|
echo "\$GREETING"
|
||||||
echo "greeting=$GREETING" >> $GITHUB_OUTPUT
|
echo "greeting=\$GREETING" >> \$GITHUB_OUTPUT
|
||||||
`;
|
`;
|
||||||
|
/* eslint-enable no-useless-escape */
|
||||||
|
|
||||||
const ACTION_SNIPPET_DOCKER_USING = `# For more on Docker actions, see:
|
const ACTION_SNIPPET_DOCKER_USING = `# For more on Docker actions, see:
|
||||||
# https://docs.github.com/en/actions/sharing-automations/creating-actions/creating-a-docker-container-action
|
# https://docs.github.com/en/actions/sharing-automations/creating-actions/creating-a-docker-container-action
|
||||||
using: docker
|
using: docker
|
||||||
# 'docker://image:tag' uses pre-built image, 'Dockerfile' builds locally
|
# 'docker://image:tag' uses pre-built image, 'Dockerfile' builds locally
|
||||||
image: '\${1:docker://alpine:3.20}'
|
image: '\${1:docker://alpine:3.20}'
|
||||||
entrypoint: '\${2:sh}'
|
entrypoint: '\${2:sh}'
|
||||||
args:
|
args:
|
||||||
- -c
|
- -c
|
||||||
- echo "Hello World"
|
- echo "Hello World"
|
||||||
`;
|
`;
|
||||||
@@ -282,7 +284,7 @@ export function filterActionRunsCompletions(values: Value[], path: TemplateToken
|
|||||||
// No using value set - show all keys but prioritize "using"
|
// No using value set - show all keys but prioritize "using"
|
||||||
return values.map(v => {
|
return values.map(v => {
|
||||||
if (v.label.toLowerCase() === "using") {
|
if (v.label.toLowerCase() === "using") {
|
||||||
return {...v, sortText: "0_using"}; // Sort first
|
return {...v, sortText: "9_using"}; // Sort after snippets (0_, 1_, 2_)
|
||||||
}
|
}
|
||||||
return v;
|
return v;
|
||||||
});
|
});
|
||||||
@@ -354,21 +356,21 @@ export function getActionScaffoldingSnippets(
|
|||||||
"Scaffold a Node.js action",
|
"Scaffold a Node.js action",
|
||||||
ACTION_SNIPPET_NODEJS_USING,
|
ACTION_SNIPPET_NODEJS_USING,
|
||||||
position,
|
position,
|
||||||
"1_nodejs"
|
"0_nodejs"
|
||||||
),
|
),
|
||||||
createSnippetCompletion(
|
createSnippetCompletion(
|
||||||
"Composite Action",
|
"Composite Action",
|
||||||
"Scaffold a composite action",
|
"Scaffold a composite action",
|
||||||
ACTION_SNIPPET_COMPOSITE_USING,
|
ACTION_SNIPPET_COMPOSITE_USING,
|
||||||
position,
|
position,
|
||||||
"2_composite"
|
"1_composite"
|
||||||
),
|
),
|
||||||
createSnippetCompletion(
|
createSnippetCompletion(
|
||||||
"Docker Action",
|
"Docker Action",
|
||||||
"Scaffold a Docker action",
|
"Scaffold a Docker action",
|
||||||
ACTION_SNIPPET_DOCKER_USING,
|
ACTION_SNIPPET_DOCKER_USING,
|
||||||
position,
|
position,
|
||||||
"3_docker"
|
"2_docker"
|
||||||
)
|
)
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user