New reference panel: some minor fixes and refactorings (#33415)

This doesn't change behaviour at all.

* Fixes CSS of mini code view so there's no empty margin at bottom
* Renames props so they're more consistent
* Adds a constant that was repeated
This commit is contained in:
Thorsten Ball 2022-04-05 13:19:58 +02:00 committed by GitHub
parent 82929363fa
commit fa0c0bbb07
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 42 additions and 37 deletions

View File

@ -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});
}
}

View File

@ -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,
})

View File

@ -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<CodeIntelData>()
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)
}
}
},