diff --git a/actions-languageservice/src/complete.expressions.test.ts b/actions-languageservice/src/complete.expressions.test.ts index 67ac358..b0be3c8 100644 --- a/actions-languageservice/src/complete.expressions.test.ts +++ b/actions-languageservice/src/complete.expressions.test.ts @@ -241,21 +241,43 @@ jobs: expect(result.map(x => x.label)).toEqual(["another-name", "name"]); }); + it("no inputs", async () => { + const input = ` +on: + workflow_dispatch: +jobs: + a: + outputs: + build_id: my-build-id + runs-on: ubuntu-latest + steps: + - run: echo hello a + b: + needs: [a] + runs-on: ubuntu-latest + steps: + - run: echo "hello \${{ inputs.| +`; + const result = await complete(...getPositionFromCursor(input), undefined, contextProviderConfig); + + expect(result).toEqual([]); + }); + describe("steps context", () => { it("includes defined step IDs", async () => { const input = ` - on: push - jobs: - one: - runs-on: ubuntu-latest - steps: - - id: a - run: echo hello a - - id: b - run: echo hello b - - id: c - run: echo "hello \${{ steps.| - `; +on: push +jobs: + one: + runs-on: ubuntu-latest + steps: + - id: a + run: echo hello a + - id: b + run: echo hello b + - id: c + run: echo "hello \${{ steps.| +`; const result = await complete(...getPositionFromCursor(input), undefined, contextProviderConfig); expect(result.map(x => x.label)).toEqual(["a", "b"]); @@ -263,14 +285,14 @@ jobs: it("step.", async () => { const input = ` - on: push - jobs: - one: - runs-on: ubuntu-latest - steps: - - id: a - run: echo hello a - - run: echo "hello \${{ steps.a.| +on: push +jobs: + one: + runs-on: ubuntu-latest + steps: + - id: a + run: echo hello a + - run: echo "hello \${{ steps.a.| `; const result = await complete(...getPositionFromCursor(input), undefined, contextProviderConfig); @@ -279,17 +301,17 @@ jobs: it("ignores IDs from later steps", async () => { const input = ` - on: push - jobs: - one: - runs-on: ubuntu-latest - steps: - - id: a - run: echo hello a - - id: b - run: echo "hello \${{ steps.| - - id: c - run: echo hello c +on: push +jobs: + one: + runs-on: ubuntu-latest + steps: + - id: a + run: echo hello a + - id: b + run: echo "hello \${{ steps.| + - id: c + run: echo hello c `; const result = await complete(...getPositionFromCursor(input), undefined, contextProviderConfig); diff --git a/actions-languageservice/src/context-providers/inputs.ts b/actions-languageservice/src/context-providers/inputs.ts index 0d5a951..167669f 100644 --- a/actions-languageservice/src/context-providers/inputs.ts +++ b/actions-languageservice/src/context-providers/inputs.ts @@ -13,6 +13,9 @@ export function getInputsContext(workflowContext: WorkflowContext): data.Diction } const inputs = event.inputs; + if (!inputs) { + return d; + } for (const inputName of Object.keys(inputs)) { const input = inputs[inputName]; switch (input.type) {