Skip to content
This repository has been archived by the owner on Jul 15, 2023. It is now read-only.

Use resolveCodeLens for better performance #938

Merged
merged 1 commit into from
Apr 23, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 17 additions & 9 deletions src/goCodelens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@ import { CodeLensProvider, SymbolInformation, SymbolKind, TextDocument, Cancella
import { documentSymbols, GoDocumentSymbolProvider } from './goOutline';
import { GoReferenceProvider } from './goReferences';

class ReferencesCodeLens extends CodeLens {
constructor(
public document: TextDocument,
public symbol: SymbolInformation,
range: Range
) {
super(range);
}
}

export class GoCodeLensProvider implements CodeLensProvider {
public provideCodeLenses(document: TextDocument, token: CancellationToken): CodeLens[] | Thenable<CodeLens[]> {
let codelensEnabled = vscode.workspace.getConfiguration('go').get('referencesCodeLens.enabled');
Expand All @@ -13,19 +23,17 @@ export class GoCodeLensProvider implements CodeLensProvider {
}

return this.provideDocumentSymbols(document, token).then(symbols => {
let symbolReferences = symbols.map(symbol => this.provideSymbolReferences(document, symbol, token));
return Promise.all(symbolReferences).then(values => {
let codelenses = [];
values.forEach(lens => {
if (lens) {
codelenses.push(lens);
}
});
return codelenses;
return symbols.map(symbol => {
return new ReferencesCodeLens(document, symbol, symbol.location.range);
});
});
}

public resolveCodeLens?(inputCodeLens: CodeLens, token: CancellationToken): CodeLens | Thenable<CodeLens> {
let codeLens = inputCodeLens as ReferencesCodeLens;
return this.provideSymbolReferences(codeLens.document, codeLens.symbol, token);
}

private provideDocumentSymbols(document: TextDocument, token: CancellationToken): Thenable<vscode.SymbolInformation[]> {
let symbolProvider = new GoDocumentSymbolProvider();
return symbolProvider.provideDocumentSymbols(document, token).then(symbols => {
Expand Down