diff --git a/client/web/src/codeintel/ReferencesPanel.module.scss b/client/web/src/codeintel/ReferencesPanel.module.scss index df3fff82cda..051f2054d46 100644 --- a/client/web/src/codeintel/ReferencesPanel.module.scss +++ b/client/web/src/codeintel/ReferencesPanel.module.scss @@ -68,6 +68,6 @@ // Code needs to be smaller than 100% so it scrolls correctly &--side-blob-code { // Subtract the space taken up by the filename - height: calc(100% - #{$references-filter-height + $references-token-height}); + height: calc(100% - #{$references-filter-height}); } } diff --git a/client/web/src/codeintel/ReferencesPanel.tsx b/client/web/src/codeintel/ReferencesPanel.tsx index e32ed5fa8aa..b5205236b31 100644 --- a/client/web/src/codeintel/ReferencesPanel.tsx +++ b/client/web/src/codeintel/ReferencesPanel.tsx @@ -263,8 +263,8 @@ export const ReferencesList: React.FunctionComponent< fileContent: props.fileContent, searchToken: props.searchToken, spec: props.spec, - repoIsFork: props.isFork, - repoIsArchived: props.isArchived, + isFork: props.isFork, + isArchived: props.isArchived, getSetting, }) diff --git a/client/web/src/codeintel/useCodeIntel.ts b/client/web/src/codeintel/useCodeIntel.ts index 04c8a461ba1..a2c715d2deb 100644 --- a/client/web/src/codeintel/useCodeIntel.ts +++ b/client/web/src/codeintel/useCodeIntel.ts @@ -41,6 +41,12 @@ interface CodeIntelData { } } +const EMPTY_CODE_INTEL_DATA = { + implementations: { endCursor: null, nodes: [] }, + definitions: { endCursor: null, nodes: [] }, + references: { endCursor: null, nodes: [] }, +} + export interface UseCodeIntelResult { data?: CodeIntelData error?: ErrorLike @@ -57,11 +63,15 @@ export interface UseCodeIntelResult { interface UseCodeIntelParameters { variables: UsePreciseCodeIntelForPositionVariables & ConnectionQueryArguments + searchToken: string - spec: LanguageSpec fileContent: string - repoIsFork: boolean - repoIsArchived: boolean + + spec: LanguageSpec + + isFork: boolean + isArchived: boolean + getSetting: SettingsGetter } @@ -70,17 +80,38 @@ export const useCodeIntel = ({ searchToken, spec, fileContent, - repoIsFork, - repoIsArchived, + isFork, + isArchived, getSetting, }: UseCodeIntelParameters): UseCodeIntelResult => { const [codeIntelData, setCodeIntelData] = useState() + const setReferences = (references: Location[]): void => { + setCodeIntelData(previousData => ({ + ...(previousData || EMPTY_CODE_INTEL_DATA), + references: { + endCursor: null, + nodes: references, + }, + })) + } + + const setDefinitions = (definitions: Location[]): void => { + setCodeIntelData(previousData => ({ + ...(previousData || EMPTY_CODE_INTEL_DATA), + definitions: { + endCursor: null, + nodes: definitions, + }, + })) + } + const fellBackToSearchBased = useRef(false) const shouldFetchPrecise = useRef(true) useEffect(() => { // We need to fetch again if the variables change shouldFetchPrecise.current = true + fellBackToSearchBased.current = false }, [ variables.repository, variables.commit, @@ -92,32 +123,6 @@ export const useCodeIntel = ({ variables.firstImplementations, ]) - const handleSearchBasedReferences = (references: Location[]): void => { - setCodeIntelData(previousData => ({ - ...(previousData || { - implementations: { endCursor: null, nodes: [] }, - definitions: { endCursor: null, nodes: [] }, - }), - references: { - endCursor: null, - nodes: references, - }, - })) - } - - const handleSearchBasedDefinitions = (definitions: Location[]): void => { - setCodeIntelData(previousData => ({ - ...(previousData || { - implementations: { endCursor: null, nodes: [] }, - references: { endCursor: null, nodes: [] }, - }), - definitions: { - endCursor: null, - nodes: definitions, - }, - })) - } - const { loading: searchBasedLoading, error: searchBasedError, @@ -129,8 +134,8 @@ export const useCodeIntel = ({ searchToken, fileContent, spec, - isFork: repoIsFork, - isArchived: repoIsArchived, + isFork, + isArchived, getSetting, }) @@ -153,7 +158,7 @@ export const useCodeIntel = ({ console.info('No LSIF data. Falling back to search-based code intelligence.') fellBackToSearchBased.current = true - fetchSearchBasedCodeIntel(handleSearchBasedReferences, handleSearchBasedDefinitions) + fetchSearchBasedCodeIntel(setReferences, setDefinitions) } } },