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

Commit

Permalink
Use resolveCodeLens for performance (#938)
Browse files Browse the repository at this point in the history
  • Loading branch information
theSoenke authored and ramya-rao-a committed Apr 23, 2017
1 parent b5f541f commit 46d0377
Showing 1 changed file with 17 additions and 9 deletions.
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

0 comments on commit 46d0377

Please sign in to comment.