mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-23 01:58:53 +01:00
provideCodeActions get those diagnostic instances others provided, not a clone
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
'use strict';
|
||||
|
||||
import * as assert from 'assert';
|
||||
import {languages, Uri, Diagnostic, Range} from 'vscode';
|
||||
import {languages, workspace, commands, Uri, Diagnostic, Range, Command, Disposable} from 'vscode';
|
||||
|
||||
suite('languages namespace tests', () => {
|
||||
|
||||
@@ -49,6 +49,8 @@ suite('languages namespace tests', () => {
|
||||
assert.ok(!collection.has(Uri.parse('foo:bar3')));
|
||||
collection.delete(Uri.parse('foo:bar1'));
|
||||
assert.ok(!collection.has(Uri.parse('foo:bar1')));
|
||||
|
||||
collection.dispose();
|
||||
});
|
||||
|
||||
test('diagnostic collection, immutable read', function () {
|
||||
@@ -71,5 +73,55 @@ suite('languages namespace tests', () => {
|
||||
|
||||
array = collection.get(Uri.parse('foo:bar'));
|
||||
assert.equal(array.length, 2);
|
||||
|
||||
collection.dispose();
|
||||
});
|
||||
|
||||
test('diagnostics & CodeActionProvider', function () {
|
||||
|
||||
class D2 extends Diagnostic {
|
||||
customProp = { complex() { } };
|
||||
constructor() {
|
||||
super(new Range(0, 2, 0, 7), 'sonntag');
|
||||
}
|
||||
};
|
||||
|
||||
let diag1 = new Diagnostic(new Range(0, 0, 0, 5), 'montag');
|
||||
let diag2 = new D2();
|
||||
|
||||
let ran = false;
|
||||
let uri = Uri.parse('ttt:path.far');
|
||||
|
||||
let r1 = languages.registerCodeActionsProvider({ pattern: '*.far' }, {
|
||||
provideCodeActions(document, range, ctx): Command[] {
|
||||
|
||||
assert.equal(ctx.diagnostics.length, 2);
|
||||
let [first, second] = ctx.diagnostics;
|
||||
assert.ok(first === diag1);
|
||||
assert.ok(second === diag2);
|
||||
assert.ok(diag2 instanceof D2);
|
||||
ran = true;
|
||||
return [];
|
||||
}
|
||||
});
|
||||
|
||||
let r2 = workspace.registerTextDocumentContentProvider('ttt', {
|
||||
provideTextDocumentContent() {
|
||||
return 'this is some text';
|
||||
}
|
||||
});
|
||||
|
||||
let r3 = languages.createDiagnosticCollection();
|
||||
r3.set(uri, [diag1]);
|
||||
|
||||
let r4 = languages.createDiagnosticCollection();
|
||||
r4.set(uri, [diag2]);
|
||||
|
||||
workspace.openTextDocument(uri).then(doc => {
|
||||
return commands.executeCommand('vscode.executeCodeActionProvider', uri, new Range(0, 0, 0, 10));
|
||||
}).then(commands => {
|
||||
assert.ok(ran);
|
||||
Disposable.from(r1, r2, r3, r4).dispose();
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user