Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Insert empty string instead of 'null' for string array completion #277

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/languageservice/services/yamlCompletion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,7 @@ export class YAMLCompletion extends JSONCompletion {
insertText = `\${${insertIndex++}:0}`;
break;
case 'string':
insertText = `\${${insertIndex++}:null}`;
insertText = `\${${insertIndex++}:""}`;
break;
case 'object':
const objectInsertResult = this.getInsertTextForObject(schema, separatorAfter, `${indent}\t`, insertIndex++);
Expand Down
51 changes: 51 additions & 0 deletions test/autoCompletion6.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Red Hat. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { TextDocument } from 'vscode-languageserver';
import { getLanguageService } from '../src/languageservice/yamlLanguageService';
import { toFsPath, schemaRequestService, workspaceContext } from './utils/testHelper';
import assert = require('assert');
import path = require('path');

const languageService = getLanguageService(schemaRequestService, workspaceContext, [], null);

const languageSettings = {
schemas: [],
completion: true
};

const uri = toFsPath(path.join(__dirname, './fixtures/testStringArray.json'));
const fileMatch = ['*.yml', '*.yaml'];
languageSettings.schemas.push({ uri, fileMatch: fileMatch });
languageService.configure(languageSettings);

suite('Auto Completion Tests', () => {


describe('yamlCompletion with string array ', function () {

describe('doComplete', function () {

function setup (content: string) {
return TextDocument.create('file://~/Desktop/vscode-k8s/test.yaml', 'yaml', 0, content);
}

function parseSetup (content: string, position) {
const testTextDocument = setup(content);
return languageService.doComplete(testTextDocument, testTextDocument.positionAt(position), false);
}

it('Completion should insert ""', done => {
const content = 'fooBa';
const completion = parseSetup(content, content.lastIndexOf('Ba') + 2);
completion.then(function (result) {
assert.strictEqual('fooBar:\n\t- ${1:""}', result.items[0].insertText);
}).then(done, done);
});

});
});
});

12 changes: 12 additions & 0 deletions test/fixtures/testStringArray.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"properties": {
"fooBar": {
"items": {
"type": "string"
},
"type": "array"
}
},
"type": "object"
}