Fix Completion bug with null string (#168)
This commit is contained in:
@@ -320,6 +320,19 @@ on:
|
||||
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 () => {
|
||||
const input = `
|
||||
o|
|
||||
|
||||
@@ -7,6 +7,6 @@ import {TemplateToken} from "@github/actions-workflow-parser/templates/tokens/in
|
||||
export function isPotentiallyExpression(token: TemplateToken): boolean {
|
||||
const isAlwaysExpression =
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -203,14 +203,15 @@ class TemplateReader {
|
||||
);
|
||||
|
||||
// Duplicate
|
||||
const upperKey = nextKey.value.toUpperCase();
|
||||
if (upperKeys[upperKey]) {
|
||||
this._context.error(nextKey, `'${nextKey.value}' is already defined`);
|
||||
this.skipValue();
|
||||
continue;
|
||||
if (nextKey.value) {
|
||||
const upperKey = nextKey.value.toUpperCase();
|
||||
if (upperKeys[upperKey]) {
|
||||
this._context.error(nextKey, `'${nextKey.value}' is already defined`);
|
||||
this.skipValue();
|
||||
continue;
|
||||
}
|
||||
upperKeys[upperKey] = true;
|
||||
}
|
||||
upperKeys[upperKey] = true;
|
||||
|
||||
// Well known
|
||||
const nextPropertyDef = this._schema.matchPropertyAndFilter(mappingDefinitions, nextKey.value);
|
||||
if (nextPropertyDef) {
|
||||
@@ -339,13 +340,15 @@ class TemplateReader {
|
||||
);
|
||||
|
||||
// Duplicate
|
||||
const upperKey = nextKey.value.toUpperCase();
|
||||
if (upperKeys[upperKey]) {
|
||||
this._context.error(nextKey, `'${nextKey.value}' is already defined`);
|
||||
this.skipValue();
|
||||
continue;
|
||||
if (nextKey.value) {
|
||||
const upperKey = nextKey.value.toUpperCase();
|
||||
if (upperKeys[upperKey]) {
|
||||
this._context.error(nextKey, `'${nextKey.value}' is already defined`);
|
||||
this.skipValue();
|
||||
continue;
|
||||
}
|
||||
upperKeys[upperKey] = true;
|
||||
}
|
||||
upperKeys[upperKey] = true;
|
||||
|
||||
// Validate
|
||||
this.validate(nextKey, keyDefinition);
|
||||
@@ -443,7 +446,7 @@ class TemplateReader {
|
||||
|
||||
private parseScalar(token: LiteralToken, definitionInfo: DefinitionInfo): ScalarToken {
|
||||
// Not a string
|
||||
if (!isString(token)) {
|
||||
if (!isString(token) || !token.value) {
|
||||
return token;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user