mirror of
https://github.com/microsoft/vscode.git
synced 2025-12-24 20:26:08 +00:00
virtual doc - support content provider signalling change via onDidChange event
This commit is contained in:
@@ -6,11 +6,10 @@
|
||||
'use strict';
|
||||
|
||||
import * as assert from 'assert';
|
||||
import {workspace, TextDocument, window, Position, Uri, CancellationTokenSource} from 'vscode';
|
||||
import {workspace, TextDocument, window, Position, Uri, CancellationTokenSource, Disposable} from 'vscode';
|
||||
import {createRandomFile, deleteFile, cleanUp, pathEquals} from './utils';
|
||||
import {join, basename} from 'path';
|
||||
import * as fs from 'fs';
|
||||
import * as os from 'os';
|
||||
|
||||
suite('workspace-namespace', () => {
|
||||
|
||||
@@ -209,6 +208,50 @@ suite('workspace-namespace', () => {
|
||||
});
|
||||
});
|
||||
|
||||
test('registerTextDocumentContentProvider, change event', function() {
|
||||
|
||||
let callCount = 0;
|
||||
let listeners: Function[] = [];
|
||||
let registration = workspace.registerTextDocumentContentProvider('foo', {
|
||||
onDidChange(callback, thisArg, disposables) {
|
||||
let actual = thisArg ? callback.bind(thisArg) : callback;
|
||||
listeners.push(actual);
|
||||
let subscription = new Disposable(() => {
|
||||
const idx = listeners.indexOf(actual);
|
||||
listeners.splice(idx, 1);
|
||||
});
|
||||
if (Array.isArray(disposables)) {
|
||||
disposables.push(subscription);
|
||||
}
|
||||
return subscription;
|
||||
},
|
||||
provideTextDocumentContent(uri) {
|
||||
return 'call' + (callCount++);
|
||||
}
|
||||
});
|
||||
|
||||
const uri = Uri.parse('foo://testing/path2');
|
||||
|
||||
return workspace.openTextDocument(uri).then(doc => {
|
||||
|
||||
assert.equal(callCount, 1);
|
||||
assert.equal(doc.getText(), 'call0');
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
|
||||
workspace.onDidChangeTextDocument(event => {
|
||||
assert.ok(event.document === doc);
|
||||
assert.equal(event.document.getText(), 'call1');
|
||||
resolve();
|
||||
});
|
||||
|
||||
listeners.forEach(l => l(doc.uri));
|
||||
|
||||
registration.dispose();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
test('findFiles', () => {
|
||||
return workspace.findFiles('*.js', null).then((res) => {
|
||||
assert.equal(res.length, 1);
|
||||
@@ -226,4 +269,4 @@ suite('workspace-namespace', () => {
|
||||
assert.equal(res, void 0);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user