PostHog event for measuring duration of resolving symbol definitions for hover preview

This commit is contained in:
bkellam 2025-11-30 18:17:07 -08:00
parent c868109ea8
commit a80e92eb3d
2 changed files with 28 additions and 13 deletions

View file

@ -1,7 +1,8 @@
import { findSearchBasedSymbolDefinitions } from "@/app/api/(client)/client"; import { findSearchBasedSymbolDefinitions } from "@/app/api/(client)/client";
import { SourceRange } from "@/features/search"; import { SourceRange } from "@/features/search";
import useCaptureEvent from "@/hooks/useCaptureEvent";
import { useDomain } from "@/hooks/useDomain"; import { useDomain } from "@/hooks/useDomain";
import { unwrapServiceError } from "@/lib/utils"; import { measure, unwrapServiceError } from "@/lib/utils";
import { useQuery } from "@tanstack/react-query"; import { useQuery } from "@tanstack/react-query";
import { ReactCodeMirrorRef } from "@uiw/react-codemirror"; import { ReactCodeMirrorRef } from "@uiw/react-codemirror";
import { useCallback, useEffect, useMemo, useRef, useState } from "react"; import { useCallback, useEffect, useMemo, useRef, useState } from "react";
@ -53,16 +54,26 @@ export const useHoveredOverSymbolInfo = ({
return (symbolElement && symbolElement.textContent) ?? undefined; return (symbolElement && symbolElement.textContent) ?? undefined;
}, [symbolElement]); }, [symbolElement]);
const captureEvent = useCaptureEvent();
const { data: symbolDefinitions, isLoading: isSymbolDefinitionsLoading } = useQuery({ const { data: symbolDefinitions, isLoading: isSymbolDefinitionsLoading } = useQuery({
queryKey: ["definitions", symbolName, revisionName, language, domain, repoName], queryKey: ["definitions", symbolName, revisionName, language, domain, repoName],
queryFn: () => unwrapServiceError( queryFn: async () => {
findSearchBasedSymbolDefinitions({ const response = await measure(() => unwrapServiceError(
symbolName: symbolName!, findSearchBasedSymbolDefinitions({
language, symbolName: symbolName!,
revisionName, language,
repoName, revisionName,
}) repoName,
), })
), 'findSearchBasedSymbolDefinitions', false);
captureEvent('wa_find_hovered_over_symbol_definitions', {
durationMs: response.durationMs,
});
return response.data;
},
select: ((data) => { select: ((data) => {
return data.files.flatMap((file) => { return data.files.flatMap((file) => {
return file.matches.map((match) => { return file.matches.map((match) => {
@ -113,7 +124,7 @@ export const useHoveredOverSymbolInfo = ({
const handleMouseOut = () => { const handleMouseOut = () => {
clearTimers(); clearTimers();
mouseOutTimerRef.current = setTimeout(() => { mouseOutTimerRef.current = setTimeout(() => {
setIsVisible(false); setIsVisible(false);
}, SYMBOL_HOVER_POPUP_MOUSE_OUT_TIMEOUT_MS); }, SYMBOL_HOVER_POPUP_MOUSE_OUT_TIMEOUT_MS);
@ -136,13 +147,13 @@ export const useHoveredOverSymbolInfo = ({
const view = editorRef.view; const view = editorRef.view;
const rect = symbolElement.getBoundingClientRect(); const rect = symbolElement.getBoundingClientRect();
// Get the start position (left edge, middle vertically) // Get the start position (left edge, middle vertically)
const startPos = view.posAtCoords({ const startPos = view.posAtCoords({
x: rect.left, x: rect.left,
y: rect.top + rect.height / 2, y: rect.top + rect.height / 2,
}); });
// Get the end position (right edge, middle vertically) // Get the end position (right edge, middle vertically)
const endPos = view.posAtCoords({ const endPos = view.posAtCoords({
x: rect.right, x: rect.right,
@ -156,7 +167,7 @@ export const useHoveredOverSymbolInfo = ({
// Convert CodeMirror positions to SourceRange format // Convert CodeMirror positions to SourceRange format
const startLine = view.state.doc.lineAt(startPos); const startLine = view.state.doc.lineAt(startPos);
const endLine = view.state.doc.lineAt(endPos); const endLine = view.state.doc.lineAt(endPos);
const startColumn = startPos - startLine.from + 1; // 1-based column const startColumn = startPos - startLine.from + 1; // 1-based column
const endColumn = endPos - endLine.from + 1; // 1-based column const endColumn = endPos - endLine.from + 1; // 1-based column

View file

@ -302,5 +302,9 @@ export type PosthogEventMap = {
////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////
wa_github_star_toast_displayed: {}, wa_github_star_toast_displayed: {},
wa_github_star_toast_clicked: {}, wa_github_star_toast_clicked: {},
//////////////////////////////////////////////////////////////////
wa_find_hovered_over_symbol_definitions: {
durationMs: number,
}
} }
export type PosthogEvent = keyof PosthogEventMap; export type PosthogEvent = keyof PosthogEventMap;