Fix Completion bug with null string (#168)
This commit is contained in:
@@ -320,6 +320,19 @@ on:
|
|||||||
expect(result).toHaveLength(0);
|
expect(result).toHaveLength(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("null strings still give suggestions", async () => {
|
||||||
|
const input = `
|
||||||
|
on: push
|
||||||
|
jobs:
|
||||||
|
one:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
`;
|
||||||
|
const result = await complete(...getPositionFromCursor(input));
|
||||||
|
expect(result).toHaveLength(16);
|
||||||
|
});
|
||||||
|
|
||||||
it("well known mapping keys have descriptions", async () => {
|
it("well known mapping keys have descriptions", async () => {
|
||||||
const input = `
|
const input = `
|
||||||
o|
|
o|
|
||||||
|
|||||||
@@ -7,6 +7,6 @@ import {TemplateToken} from "@github/actions-workflow-parser/templates/tokens/in
|
|||||||
export function isPotentiallyExpression(token: TemplateToken): boolean {
|
export function isPotentiallyExpression(token: TemplateToken): boolean {
|
||||||
const isAlwaysExpression =
|
const isAlwaysExpression =
|
||||||
token.definition?.definitionType === DefinitionType.String && (token.definition as StringDefinition).isExpression;
|
token.definition?.definitionType === DefinitionType.String && (token.definition as StringDefinition).isExpression;
|
||||||
const containsExpression = isString(token) && token.value.indexOf(OPEN_EXPRESSION) >= 0;
|
const containsExpression = isString(token) && token.value != null && token.value.indexOf(OPEN_EXPRESSION) >= 0;
|
||||||
return isAlwaysExpression || containsExpression;
|
return isAlwaysExpression || containsExpression;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -203,14 +203,15 @@ class TemplateReader {
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Duplicate
|
// Duplicate
|
||||||
const upperKey = nextKey.value.toUpperCase();
|
if (nextKey.value) {
|
||||||
if (upperKeys[upperKey]) {
|
const upperKey = nextKey.value.toUpperCase();
|
||||||
this._context.error(nextKey, `'${nextKey.value}' is already defined`);
|
if (upperKeys[upperKey]) {
|
||||||
this.skipValue();
|
this._context.error(nextKey, `'${nextKey.value}' is already defined`);
|
||||||
continue;
|
this.skipValue();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
upperKeys[upperKey] = true;
|
||||||
}
|
}
|
||||||
upperKeys[upperKey] = true;
|
|
||||||
|
|
||||||
// Well known
|
// Well known
|
||||||
const nextPropertyDef = this._schema.matchPropertyAndFilter(mappingDefinitions, nextKey.value);
|
const nextPropertyDef = this._schema.matchPropertyAndFilter(mappingDefinitions, nextKey.value);
|
||||||
if (nextPropertyDef) {
|
if (nextPropertyDef) {
|
||||||
@@ -339,13 +340,15 @@ class TemplateReader {
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Duplicate
|
// Duplicate
|
||||||
const upperKey = nextKey.value.toUpperCase();
|
if (nextKey.value) {
|
||||||
if (upperKeys[upperKey]) {
|
const upperKey = nextKey.value.toUpperCase();
|
||||||
this._context.error(nextKey, `'${nextKey.value}' is already defined`);
|
if (upperKeys[upperKey]) {
|
||||||
this.skipValue();
|
this._context.error(nextKey, `'${nextKey.value}' is already defined`);
|
||||||
continue;
|
this.skipValue();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
upperKeys[upperKey] = true;
|
||||||
}
|
}
|
||||||
upperKeys[upperKey] = true;
|
|
||||||
|
|
||||||
// Validate
|
// Validate
|
||||||
this.validate(nextKey, keyDefinition);
|
this.validate(nextKey, keyDefinition);
|
||||||
@@ -443,7 +446,7 @@ class TemplateReader {
|
|||||||
|
|
||||||
private parseScalar(token: LiteralToken, definitionInfo: DefinitionInfo): ScalarToken {
|
private parseScalar(token: LiteralToken, definitionInfo: DefinitionInfo): ScalarToken {
|
||||||
// Not a string
|
// Not a string
|
||||||
if (!isString(token)) {
|
if (!isString(token) || !token.value) {
|
||||||
return token;
|
return token;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user