mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-25 19:18:59 +01:00
some early sketches of a read api #30075
This commit is contained in:
@@ -232,6 +232,11 @@ export function createApiFactory(
|
||||
createDiagnosticCollection(name?: string): vscode.DiagnosticCollection {
|
||||
return extHostDiagnostics.createDiagnosticCollection(name);
|
||||
},
|
||||
diagnostics: {
|
||||
has: proposedApiFunction(extension, uri => extHostDiagnostics.hasDiagnostics(uri)),
|
||||
get: proposedApiFunction(extension, uri => extHostDiagnostics.getDiagnostics(uri)),
|
||||
all: proposedApiFunction(extension, () => extHostDiagnostics.getAllDiagnostics())
|
||||
},
|
||||
getLanguages(): TPromise<string[]> {
|
||||
return extHostLanguages.getLanguages();
|
||||
},
|
||||
|
||||
@@ -220,12 +220,11 @@ export class ExtHostDiagnostics implements ExtHostDiagnosticsShape {
|
||||
|
||||
private static _idPool: number = 0;
|
||||
|
||||
private _proxy: MainThreadDiagnosticsShape;
|
||||
private _collections: DiagnosticCollection[];
|
||||
private readonly _proxy: MainThreadDiagnosticsShape;
|
||||
private readonly _collections: DiagnosticCollection[] = [];
|
||||
|
||||
constructor(mainContext: IMainContext) {
|
||||
this._proxy = mainContext.getProxy(MainContext.MainThreadDiagnostics);
|
||||
this._collections = [];
|
||||
}
|
||||
|
||||
createDiagnosticCollection(name: string): vscode.DiagnosticCollection {
|
||||
@@ -251,7 +250,39 @@ export class ExtHostDiagnostics implements ExtHostDiagnosticsShape {
|
||||
return result;
|
||||
}
|
||||
|
||||
forEach(callback: (collection: DiagnosticCollection) => any): void {
|
||||
this._collections.forEach(callback);
|
||||
hasDiagnostics(resource: vscode.Uri): boolean {
|
||||
for (const collection of this._collections) {
|
||||
if (collection.has(resource)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
getDiagnostics(resource: vscode.Uri): vscode.Diagnostic[] {
|
||||
let res: vscode.Diagnostic[] = [];
|
||||
for (const collection of this._collections) {
|
||||
if (collection.has(resource)) {
|
||||
res = res.concat(collection.get(resource));
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
getAllDiagnostics(): [vscode.Uri, vscode.Diagnostic[]][] {
|
||||
let map = new Map<string, number>();
|
||||
let res: [vscode.Uri, vscode.Diagnostic[]][] = [];
|
||||
for (const collection of this._collections) {
|
||||
collection.forEach((resource: vscode.Uri, diagnostics: vscode.Diagnostic[]) => {
|
||||
let index = map.get(resource.toString());
|
||||
if (typeof index === 'undefined') {
|
||||
index = res.length;
|
||||
res.push([resource, []]);
|
||||
map.set(resource.toString(), index);
|
||||
}
|
||||
res[index][1] = res[index][1].concat(diagnostics);
|
||||
});
|
||||
}
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -280,15 +280,11 @@ class CodeActionAdapter {
|
||||
const ran = <vscode.Range>TypeConverters.toRange(range);
|
||||
const allDiagnostics: vscode.Diagnostic[] = [];
|
||||
|
||||
this._diagnostics.forEach(collection => {
|
||||
if (collection.has(resource)) {
|
||||
for (let diagnostic of collection.get(resource)) {
|
||||
if (ran.contains(diagnostic.range)) {
|
||||
allDiagnostics.push(diagnostic);
|
||||
}
|
||||
}
|
||||
for (const diagnostic of this._diagnostics.getDiagnostics(resource)) {
|
||||
if (ran.contains(diagnostic.range)) {
|
||||
allDiagnostics.push(diagnostic);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
const codeActionContext: vscode.CodeActionContext = {
|
||||
diagnostics: allDiagnostics,
|
||||
|
||||
Reference in New Issue
Block a user