Skip to content

Commit

Permalink
Merge pull request #341 from alecmerdler/CONSOLE-641
Browse files Browse the repository at this point in the history
Fix YAML Editor `RangeError`
  • Loading branch information
openshift-merge-robot authored Jul 30, 2018
2 parents e55b3e4 + ee439d8 commit 89f0948
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
11 changes: 11 additions & 0 deletions frontend/__tests__/module/k8s/autocomplete.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,17 @@ describe('getCompletions', () => {
});
});

it('does not invoke callback with completions if no matches for property values', (done) => {
sessionMock.getLine = jasmine.createSpy('getLineSpy').and.returnValue('apiVersion: ');
position = {row: 0, column: 'apiVersion: '.length};

getCompletions(editorMock, sessionMock, position, '', () => {
fail('Should not be called');
done();
});
done();
});

it('invokes callback with appropriate completions for properties', (done) => {
const swagger = {
definitions: {
Expand Down
11 changes: 8 additions & 3 deletions frontend/public/module/k8s/autocomplete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,14 @@ export const getPropertyValueCompletions = async(state: Editor, session: IEditSe
const line = session.getLine(pos.row).substr(0, pos.column);
const field = (/([\w]+):[^:]*$/.exec(line) || {})[1];

const parentPropertyFor = (currentRow: number): string => session.getLine(currentRow - 1).trim().endsWith(':')
? (/([\w]+):[^:]*$/.exec(session.getLine(currentRow - 1)) || {})[1]
: parentPropertyFor(currentRow - 1);
const parentPropertyFor = (currentRow: number): string => {
if (currentRow < 1) {
return '';
}
return session.getLine(currentRow - 1).trim().endsWith(':')
? (/([\w]+):[^:]*$/.exec(session.getLine(currentRow - 1)) || {})[1]
: parentPropertyFor(currentRow - 1);
};

if (simpleCompletions.has(field)) {
callback(null, simpleCompletions.get(field).map((value, i) => ({
Expand Down

0 comments on commit 89f0948

Please sign in to comment.