allow empty string as valid document content, fixes #6526

This commit is contained in:
Johannes Rieken 2016-05-19 12:45:37 +02:00
parent b6f0eee29e
commit d37a76dc92
2 changed files with 18 additions and 1 deletions

View file

@ -294,6 +294,23 @@ suite('workspace-namespace', () => {
});
});
test('registerTextDocumentContentProvider, empty doc', function () {
let registration = workspace.registerTextDocumentContentProvider('foo', {
provideTextDocumentContent(uri) {
return '';
}
});
const uri = Uri.parse('foo:doc/empty');
return workspace.openTextDocument(uri).then(doc => {
assert.equal(doc.getText(), '');
assert.equal(doc.uri.toString(), uri.toString());
registration.dispose();
});
});
test('registerTextDocumentContentProvider, change event', function () {
let callCount = 0;

View file

@ -631,7 +631,7 @@ export class MainThreadDocuments {
this._resourceContentProvider[handle] = ResourceEditorInput.registerResourceContentProvider(scheme, {
provideTextContent: (uri: URI): TPromise<EditorCommon.IModel> => {
return this._proxy.$provideTextDocumentContent(handle, uri).then(value => {
if (value) {
if (typeof value === 'string') {
this._virtualDocumentSet[uri.toString()] = true;
const firstLineText = value.substr(0, 1 + value.search(/\r?\n/));
const mode = this._modeService.getOrCreateModeByFilenameOrFirstLine(uri.fsPath, firstLineText);