Skip to content
Merged
Show file tree
Hide file tree
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
5 changes: 3 additions & 2 deletions src/components/ReferenceSuggestionDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import { RenderSymbolicUri } from "./RenderUri";
import { SymbolicLinkPreview } from "./SymbolicLinkPreview";

const SNIFFY_REVIEW_DIALOG_HEIGHT = "90dvh";
const SNIFFY_REVIEW_DIALOG_WIDTH = "50vw";
const SNIFFY_REVIEW_DIALOG_WIDTH = "75vw";

type Props = {
opened: boolean;
Expand Down Expand Up @@ -230,10 +230,11 @@ export function ReferenceSuggestionDialog({
showRightLabel={false}
/>
</Box>
<Box style={{ flexShrink: 0, minWidth: 0 }}>
<Box style={{ flexShrink: 0 }}>
<SymbolicLinkPreview
uri={candidate.uri}
label={candidate.label}
allowHoverOverflow
/>
</Box>
</Group>
Expand Down
7 changes: 5 additions & 2 deletions src/components/SymbolicLinkPreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,15 @@ type SymbolicLinkPreviewProps = {
uri: string;
label?: string;
compact?: boolean;
/** Let FloDown symref hover cards extend outside the preview box (e.g. sn-ify dialog). */
allowHoverOverflow?: boolean;
};

export function SymbolicLinkPreview({
uri,
label,
compact = false,
allowHoverOverflow = false,
}: SymbolicLinkPreviewProps) {
const text = (() => {
if (label?.trim()) return label.trim();
Expand Down Expand Up @@ -57,8 +60,8 @@ export function SymbolicLinkPreview({
<Box
data-compact-symref={compact ? "true" : undefined}
style={{
minWidth: 0,
overflow: "hidden",
minWidth: allowHoverOverflow ? undefined : 0,
overflow: allowHoverOverflow ? "visible" : "hidden",
...(compact
? {
display: "inline-block",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ export function ModuleDefinitionsSection({

<ReferenceSuggestionDialog
opened={sniffyFlow.suggestOpen}
onClose={() => sniffyFlow.setSuggestOpen(false)}
onClose={sniffyFlow.closeSuggest}
floDownBlockId={sniffyFlow.activeFloDownBlockId ?? ""}
floDownBlockStatement={sniffyFlow.activeFloDownBlockStatement}
declaredSymbolsInfo={sniffyFlow.activeDeclaredSymbolsInfo}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ export function ModuleStatementsSection({

<ReferenceSuggestionDialog
opened={sniffyFlow.suggestOpen}
onClose={() => sniffyFlow.setSuggestOpen(false)}
onClose={sniffyFlow.closeSuggest}
floDownBlockId={sniffyFlow.activeFloDownBlockId ?? ""}
floDownBlockStatement={sniffyFlow.activeFloDownBlockStatement}
declaredSymbolsInfo={sniffyFlow.activeDeclaredSymbolsInfo}
Expand Down
28 changes: 27 additions & 1 deletion src/hooks/module-descriptions/useModuleSniffyFlow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
moduleDefinitionsToExtractedItems,
type ModuleDefinitionBlock,
} from "@/lib/moduleDefinitionExtracts";
import { useRef } from "react";

type SniffyCatalog = Parameters<
typeof useSniffyReferenceSuggestions
Expand All @@ -26,12 +27,17 @@ export function useModuleSniffyFlow({
staticCatalogError: Error | null;
retryStaticCatalog: () => Promise<void>;
}) {
return useSniffyReferenceSuggestions({
const pendingPageRefreshRef = useRef(false);

const sniffyFlow = useSniffyReferenceSuggestions({
floDownBlocks: extracts,
catalog: sniffyCatalog,
catalogLoading: staticCatalogLoading,
catalogError: staticCatalogError,
retryCatalog: retryStaticCatalog,
onSessionMutated: () => {
pendingPageRefreshRef.current = true;
},
invalidate: () =>
queryClient.invalidateQueries({
queryKey: ["module-description", moduleId],
Expand All @@ -44,4 +50,24 @@ export function useModuleSniffyFlow({
return moduleDefinitionsToExtractedItems(blocks);
},
});

async function handleRecomputeReferences(floDownBlockId: string) {
pendingPageRefreshRef.current = false;
await sniffyFlow.handleRecomputeReferences(floDownBlockId);
}

function closeSuggest() {
sniffyFlow.setSuggestOpen(false);
if (!pendingPageRefreshRef.current) return;
pendingPageRefreshRef.current = false;
void queryClient.invalidateQueries({
queryKey: ["module-description", moduleId],
});
}

return {
...sniffyFlow,
handleRecomputeReferences,
closeSuggest,
};
}
27 changes: 26 additions & 1 deletion src/hooks/module-descriptions/useModuleStatementSemantics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,12 +265,17 @@ export function useModuleStatementSniffyFlow({
staticCatalogError: Error | null;
retryStaticCatalog: () => Promise<void>;
}) {
return useSniffyReferenceSuggestions({
const pendingPageRefreshRef = useRef(false);

const sniffyFlow = useSniffyReferenceSuggestions({
floDownBlocks: extracts,
catalog: sniffyCatalog,
catalogLoading: staticCatalogLoading,
catalogError: staticCatalogError,
retryCatalog: retryStaticCatalog,
onSessionMutated: () => {
pendingPageRefreshRef.current = true;
},
invalidate: () =>
queryClient.invalidateQueries({
queryKey: ["module-description", moduleId],
Expand Down Expand Up @@ -304,4 +309,24 @@ export function useModuleStatementSniffyFlow({
});
},
});

async function handleRecomputeReferences(floDownBlockId: string) {
pendingPageRefreshRef.current = false;
await sniffyFlow.handleRecomputeReferences(floDownBlockId);
}

function closeSuggest() {
sniffyFlow.setSuggestOpen(false);
if (!pendingPageRefreshRef.current) return;
pendingPageRefreshRef.current = false;
void queryClient.invalidateQueries({
queryKey: ["module-description", moduleId],
});
}

return {
...sniffyFlow,
handleRecomputeReferences,
closeSuggest,
};
}
10 changes: 4 additions & 6 deletions src/hooks/useSniffyReferenceSuggestions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type UseSniffyReferenceSuggestionsParams = {
selection: { text: string; startOffset: number; endOffset: number };
symRef: UnifiedSymbolicReference;
}) => Promise<void>;
onSessionMutated?: () => void;
};

export function useSniffyReferenceSuggestions({
Expand All @@ -38,6 +39,7 @@ export function useSniffyReferenceSuggestions({
invalidate,
refetchFloDownBlocks,
applySymbolicRef,
onSessionMutated,
}: UseSniffyReferenceSuggestionsParams) {
const [suggestOpen, setSuggestOpen] = useState(false);
const [suggestLoading, setSuggestLoading] = useState(false);
Expand Down Expand Up @@ -172,12 +174,8 @@ export function useSniffyReferenceSuggestions({
});
}

setSuggestLoading(true);
try {
await reloadSniffySession(activeFloDownBlockId);
} finally {
setSuggestLoading(false);
}
await reloadSniffySession(activeFloDownBlockId);
onSessionMutated?.();
}

return {
Expand Down
Loading