Skip to content

add debounce to codelens reload #8742

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
34 changes: 34 additions & 0 deletions firebase-vscode/src/data-connect/code-lens-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { Disposable } from "vscode";
import { Signal } from "@preact/signals-core";
import { dataConnectConfigs, firebaseRC } from "./config";
import { EmulatorsController } from "../core/emulators";
import { debounce } from "../../../src/utils";

export enum InstanceType {
LOCAL = "local",
Expand All @@ -17,6 +18,39 @@ abstract class ComputedCodeLensProvider implements vscode.CodeLensProvider {
onDidChangeCodeLenses = this._onChangeCodeLensesEmitter.event;

private readonly subscriptions: Map<Signal<any>, Disposable> = new Map();
private debouncedParse: () => void;
private document?: vscode.TextDocument;

constructor() {
this.debouncedParse = debounce(() => {
if (this.document) {
const documentText = this.document.getText();
// TODO: replace w/ online-parser to work with malformed documents
const documentNode = parse(documentText);
if (documentNode) {
this._onChangeCodeLensesEmitter.fire();
}
}
}, 1000);

vscode.workspace.onDidChangeTextDocument((event) => {
if (this.document && event.document === this.document) {
this.debouncedParse();
}
});

vscode.window.onDidChangeActiveTextEditor((editor) => {
if (editor) {
this.document = editor.document;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this parse non-graphql documents too?

Copy link
Contributor

@joehan joehan Jun 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope - this code implements the code lens provider but does not register it. We tell vscode what files to apply this for when we register it (see src/dataconnect/index.ts)

this.debouncedParse();
}
});

if (vscode.window.activeTextEditor) {
this.document = vscode.window.activeTextEditor.document;
this.debouncedParse();
}
}

watch<T>(signal: Signal<T>): T {
if (!this.subscriptions.has(signal)) {
Expand Down
Loading