Merge pull request #93 from github/cschleiden/expression-complete-without-markers
Improve auto-completion for `if:` properties
This commit is contained in:
@@ -30,6 +30,7 @@ describe("expressions", () => {
|
|||||||
return getExpressionInput(doc.getText(), pos.character);
|
return getExpressionInput(doc.getText(), pos.character);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// With ${{ }}
|
||||||
expect(test("${{ gh |")).toBe(" gh ");
|
expect(test("${{ gh |")).toBe(" gh ");
|
||||||
expect(test("${{ gh |}}")).toBe(" gh ");
|
expect(test("${{ gh |}}")).toBe(" gh ");
|
||||||
expect(test("${{ vars| == 'test' }}")).toBe(" vars");
|
expect(test("${{ vars| == 'test' }}")).toBe(" vars");
|
||||||
@@ -41,6 +42,18 @@ describe("expressions", () => {
|
|||||||
expect(test("${{ test.|")).toBe(" test.");
|
expect(test("${{ test.|")).toBe(" test.");
|
||||||
expect(test("${{ test.| }}")).toBe(" test.");
|
expect(test("${{ test.| }}")).toBe(" test.");
|
||||||
expect(test("${{ 1 == (test.|)")).toBe(" 1 == (test.");
|
expect(test("${{ 1 == (test.|)")).toBe(" 1 == (test.");
|
||||||
|
|
||||||
|
// Without ${{ }}
|
||||||
|
expect(test("gh |")).toBe("gh ");
|
||||||
|
expect(test("gh |}}")).toBe("gh ");
|
||||||
|
expect(test("vars| == 'test' }}")).toBe("vars");
|
||||||
|
expect(test("fromJso|('test').bar == 'test' }}")).toBe("fromJso");
|
||||||
|
expect(test("github.| == 'test' }}")).toBe("github.");
|
||||||
|
expect(test("github.| == 'test' }}")).toBe("github.");
|
||||||
|
|
||||||
|
expect(test("test.|")).toBe("test.");
|
||||||
|
expect(test("test.| }}")).toBe("test.");
|
||||||
|
expect(test("1 == (test.|)")).toBe("1 == (test.");
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("top-level auto-complete", () => {
|
describe("top-level auto-complete", () => {
|
||||||
@@ -250,30 +263,90 @@ jobs:
|
|||||||
expect(result.map(x => x.label)).toEqual(["arch", "name", "os", "temp", "tool_cache"]);
|
expect(result.map(x => x.label)).toEqual(["arch", "name", "os", "temp", "tool_cache"]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("job if", async () => {
|
describe("job if", () => {
|
||||||
const input = `on: push
|
describe("without ${{", () => {
|
||||||
|
it("simple", async () => {
|
||||||
|
const input = `on: push
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
if: github.|
|
if: github.|
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- run: echo`;
|
- run: echo`;
|
||||||
const result = await complete(...getPositionFromCursor(input), undefined, contextProviderConfig);
|
const result = await complete(...getPositionFromCursor(input), undefined, contextProviderConfig);
|
||||||
|
|
||||||
expect(result.map(x => x.label)).toEqual(["event"]);
|
expect(result.map(x => x.label)).toEqual(["event"]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("complex", async () => {
|
||||||
|
const input = `on: push
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
if: false && github.| == 'some-repo'
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- run: echo`;
|
||||||
|
const result = await complete(...getPositionFromCursor(input), undefined, contextProviderConfig);
|
||||||
|
|
||||||
|
expect(result.map(x => x.label)).toEqual(["event"]);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("with ${{", () => {
|
||||||
|
it("simple", async () => {
|
||||||
|
const input = `on: push
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
if: \${{ github.| }}
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- run: echo`;
|
||||||
|
const result = await complete(...getPositionFromCursor(input), undefined, contextProviderConfig);
|
||||||
|
|
||||||
|
expect(result.map(x => x.label)).toEqual(["event"]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("complex", async () => {
|
||||||
|
const input = `on: push
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
if: \${{ false && github.| == 'some-repo' }}
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- run: echo`;
|
||||||
|
const result = await complete(...getPositionFromCursor(input), undefined, contextProviderConfig);
|
||||||
|
|
||||||
|
expect(result.map(x => x.label)).toEqual(["event"]);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("step if", async () => {
|
describe("step if", () => {
|
||||||
const input = `on: push
|
it("with ${{", async () => {
|
||||||
|
const input = `on: push
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- run: echo
|
||||||
|
if: \${{ github.| }}`;
|
||||||
|
const result = await complete(...getPositionFromCursor(input), undefined, contextProviderConfig);
|
||||||
|
|
||||||
|
expect(result.map(x => x.label)).toEqual(["event"]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("without ${{", async () => {
|
||||||
|
const input = `on: push
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- run: echo
|
- run: echo
|
||||||
if: github.|`;
|
if: github.|`;
|
||||||
const result = await complete(...getPositionFromCursor(input), undefined, contextProviderConfig);
|
const result = await complete(...getPositionFromCursor(input), undefined, contextProviderConfig);
|
||||||
|
|
||||||
expect(result.map(x => x.label)).toEqual(["event"]);
|
expect(result.map(x => x.label)).toEqual(["event"]);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -27,12 +27,14 @@ import {definitionValues} from "./value-providers/definition";
|
|||||||
|
|
||||||
export function getExpressionInput(input: string, pos: number): string {
|
export function getExpressionInput(input: string, pos: number): string {
|
||||||
// Find start marker around the cursor position
|
// Find start marker around the cursor position
|
||||||
const startPos = input.lastIndexOf(OPEN_EXPRESSION, pos);
|
let startPos = input.lastIndexOf(OPEN_EXPRESSION, pos);
|
||||||
if (startPos === -1) {
|
if (startPos === -1) {
|
||||||
return input;
|
startPos = 0;
|
||||||
|
} else {
|
||||||
|
startPos += OPEN_EXPRESSION.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
return input.substring(startPos + OPEN_EXPRESSION.length, pos);
|
return input.substring(startPos, pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function complete(
|
export async function complete(
|
||||||
|
|||||||
Reference in New Issue
Block a user