-
Notifications
You must be signed in to change notification settings - Fork 268
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix issue: Array item properties are created with the wrong indent #h… (
#172) * Fix issue: Array item properties are created with the wrong indent #redhat-developer/vscode-yaml#192 Signed-off-by: andxu <[email protected]>
- Loading branch information
Showing
3 changed files
with
123 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* 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/testArrayIndent.json')); | ||
const fileMatch = ['*.yml', '*.yaml']; | ||
languageSettings.schemas.push({ uri, fileMatch: fileMatch }); | ||
languageService.configure(languageSettings); | ||
|
||
suite('Auto Completion Tests', () => { | ||
|
||
describe('yamlCompletion with array object', 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('Indent should be considered with position relative to slash', done => { | ||
const content = 'install:\n - he'; | ||
const completion = parseSetup(content, content.lastIndexOf('he') + 2); | ||
completion.then(function (result) { | ||
assert.equal('helm:\n \tname: $1', result.items[0].insertText); | ||
}).then(done, done); | ||
}); | ||
|
||
it('Large indent should be considered with position relative to slash', done => { | ||
const content = 'install:\n - he'; | ||
const completion = parseSetup(content, content.lastIndexOf('he') + 2); | ||
completion.then(function (result) { | ||
assert.equal('helm:\n \tname: $1', result.items[0].insertText); | ||
}).then(done, done); | ||
}); | ||
|
||
it('Tab indent should be considered with position relative to slash', done => { | ||
const content = 'install:\n -\t he'; | ||
const completion = parseSetup(content, content.lastIndexOf('he') + 2); | ||
completion.then(function (result) { | ||
assert.equal('helm:\n \t \tname: $1', result.items[0].insertText); | ||
}).then(done, done); | ||
}); | ||
|
||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-07/schema#", | ||
"definitions": { | ||
"installStep": { | ||
"properties": { | ||
"helm": { | ||
"additionalProperties": false, | ||
"properties": { | ||
"name": { | ||
"type": "string" | ||
} | ||
}, | ||
"required": [ | ||
"name" | ||
], | ||
"type": "object" | ||
} | ||
}, | ||
"required": [ | ||
"helm" | ||
], | ||
"type": "object" | ||
} | ||
}, | ||
"properties": { | ||
"install": { | ||
"items": { | ||
"anyOf": [ | ||
{ | ||
"$ref": "#/definitions/installStep" | ||
} | ||
] | ||
}, | ||
"type": "array" | ||
} | ||
}, | ||
"type": "object" | ||
} |