Merge pull request #135 from github/elbrenn/expression-complete
Complete multi-segment expressions
This commit is contained in:
@@ -278,6 +278,13 @@ jobs:
|
|||||||
expect(result.map(x => x.label)).toEqual(["event"]);
|
expect(result.map(x => x.label)).toEqual(["event"]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("auto-complete complex partial", async () => {
|
||||||
|
const input = 'run-name: "run ${{ github.ev| }} run"';
|
||||||
|
const result = await complete(...getPositionFromCursor(input), undefined, contextProviderConfig);
|
||||||
|
|
||||||
|
expect(result.map(x => x.label)).toEqual(["event"]);
|
||||||
|
});
|
||||||
|
|
||||||
it("using default context provider", async () => {
|
it("using default context provider", async () => {
|
||||||
const input =
|
const input =
|
||||||
"on: push\njobs:\n build:\n runs-on: ubuntu-latest\n environment:\n url: ${{ runner.| }}\n steps:\n - run: echo";
|
"on: push\njobs:\n build:\n runs-on: ubuntu-latest\n environment:\n url: ${{ runner.| }}\n steps:\n - run: echo";
|
||||||
|
|||||||
@@ -217,20 +217,18 @@ function getExpressionCompletionItems(
|
|||||||
context: DescriptionDictionary,
|
context: DescriptionDictionary,
|
||||||
pos: Position
|
pos: Position
|
||||||
): CompletionItem[] {
|
): CompletionItem[] {
|
||||||
let expressionInput = "";
|
|
||||||
let currentInput = "";
|
let currentInput = "";
|
||||||
let relCharOffset: number = 0;
|
|
||||||
|
|
||||||
if (isBasicExpression(token)) {
|
if (isBasicExpression(token)) {
|
||||||
expressionInput = currentInput = token.expression;
|
currentInput = token.source || token.expression;
|
||||||
relCharOffset = getRelCharOffset(token.range!, expressionInput, pos);
|
|
||||||
} else {
|
} else {
|
||||||
const stringToken = token.assertString("Expected string token for expression completion");
|
const stringToken = token.assertString("Expected string token for expression completion");
|
||||||
currentInput = stringToken.source || stringToken.value;
|
currentInput = stringToken.source || stringToken.value;
|
||||||
relCharOffset = getRelCharOffset(stringToken.range!, currentInput, pos);
|
|
||||||
expressionInput = (getExpressionInput(currentInput, relCharOffset) || "").trim();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const relCharOffset = getRelCharOffset(token.range!, currentInput, pos);
|
||||||
|
const expressionInput = (getExpressionInput(currentInput, relCharOffset) || "").trim();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return completeExpression(expressionInput, context, [], validatorFunctions).map(item =>
|
return completeExpression(expressionInput, context, [], validatorFunctions).map(item =>
|
||||||
mapExpressionCompletionItem(item, currentInput[relCharOffset])
|
mapExpressionCompletionItem(item, currentInput[relCharOffset])
|
||||||
|
|||||||
@@ -606,9 +606,9 @@ class TemplateReader {
|
|||||||
this._fileId,
|
this._fileId,
|
||||||
token.range,
|
token.range,
|
||||||
`format('${format.join("")}'${args.join("")})`,
|
`format('${format.join("")}'${args.join("")})`,
|
||||||
token.definitionInfo,
|
definitionInfo,
|
||||||
expressionTokens,
|
expressionTokens,
|
||||||
undefined
|
raw
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user