Skip to content

Commit

Permalink
use correct repo for xlang xrefs for mirrored repos
Browse files Browse the repository at this point in the history
Summary:
Reminder: fbsource/www and www/ paths both map to the same dbs. In Glass, we consider that "fbsource/www" is a mirror of www, and we're careful to translate the returned paths so they match the repo query. See this [post](https://fb.workplace.com/groups/csi.eng/permalink/1990139908151741/).

There's a corner case that wasn't handled correctly: When processing DocumentSymbols() query, we need to resolve the location of cross-dbs entities. We pick the db based on
- the query repo
- the cross-db target entity language

The rules are currently
- (fbsource, thrift) -> fbsource.fbthrift
- (www, thrift) -> www.fbthrift

There's an issue in the case of fbsource/www hack documents. The source repo is fbsource, which means we use the wrong thrift db.

Proposed fix is to again use the MirrorConfig mapping and make sure we use the "origin" repo to determine the target entity db (e.g. www instead of fbsource).

Reviewed By: iamirzhan

Differential Revision: D66679488

fbshipit-source-id: a640830d21c5ee9eafc6dd3cc6eb32ad55e038db
  • Loading branch information
Philippe Bidinger authored and facebook-github-bot committed Dec 3, 2024
1 parent e0adb52 commit 9f4d815
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions glean/glass/Glean/Glass/Handler/Documents.hs
Original file line number Diff line number Diff line change
Expand Up @@ -175,16 +175,19 @@ toFileReference :: RepoName -> Path -> FileReference
toFileReference repo path =
FileReference repo (toGleanPath $ SymbolRepoPath repo path)

repoPathToMirror :: RepoName -> Path -> Maybe Mirror
repoPathToMirror repository (Path filepath) =
let isReqInMirror (Mirror mirrorRepo prefix _) =
repository == mirrorRepo && isPrefixOf prefix filepath in
find isReqInMirror mirrorConfig

translateMirroredRepoListXResult
:: DocumentSymbolsRequest
-> DocumentSymbolListXResult
-> DocumentSymbolListXResult
translateMirroredRepoListXResult
(DocumentSymbolsRequest repository (Path filepath) _ _) res =
let isReqInMirror (Mirror mirrorRepo prefix _) =
repository == mirrorRepo && isPrefixOf prefix filepath in
let maybeMirror = find isReqInMirror mirrorConfig in
case maybeMirror of
(DocumentSymbolsRequest repository path _ _) res =
case repoPathToMirror repository path of
Just (Mirror mirror prefix origin) ->
Utils.translateDocumentSymbolListXResult origin mirror prefix Nothing res
_ -> res
Expand Down Expand Up @@ -217,7 +220,7 @@ fetchSymbolsAndAttributesGlean
file mlimit be res1

let be = fromMaybe (gleanBackend, dbInfo) mOtherBackend
res3 <- resolveXlangXrefs env res2 repo be
res3 <- resolveXlangXrefs env path res2 repo be

let res4 = toDocumentSymbolResult res3
let res5 = translateMirroredRepoListXResult req res4
Expand Down Expand Up @@ -548,26 +551,34 @@ fetchDocumentSymbols [email protected]{..} (FileReference scsrepo path)
resolveXlangXrefs
:: Glean.Backend b
=> Glass.Env
-> Path
-> DocumentSymbols
-> RepoName
-> (b, GleanDBInfo)
-> IO DocumentSymbols
resolveXlangXrefs
env@Glass.Env{tracer, sourceControl, repoMapping}
path
docSyms@DocumentSymbols{..}
scsrepo
(gleanBackend, dbInfo) = do
case (unresolvedXrefsXlang, srcFile) of
((ent, _) : _, Just srcFile) -> do
-- we assume all xlang xrefs belong to the same db
-- we pick the xlang dbs based on target lang and
-- repo. Corner case: the document is in a mirror repo,
-- use to origin repo to determine xlang db
let lang = entityLanguage ent
targetRepo = case repoPathToMirror scsrepo path of
Just (Mirror _mirror _prefix origin) -> origin
Nothing -> scsrepo
gleanDBs <- getGleanRepos tracer sourceControl repoMapping dbInfo
scsrepo (Just lang) ChooseLatest Nothing
targetRepo (Just lang) ChooseLatest Nothing
let gleanBe = GleanBackend {gleanDBs, tracer, gleanBackend}
xlangRefs <- backendRunHaxl gleanBe env $ do
xrefsXlang <- withRepo (snd (NonEmpty.head gleanDBs)) $ do
xrefs <- resolveEntitiesRange scsrepo fst unresolvedXrefsXlang
mapM (toReferenceSymbolXlang scsrepo srcFile offsets lang) xrefs
xrefs <- resolveEntitiesRange targetRepo fst unresolvedXrefsXlang
mapM (toReferenceSymbolXlang targetRepo srcFile offsets lang) xrefs
return $ xRefDataToRefEntitySymbol <$> xrefsXlang
return $ docSyms { refs = refs ++ xlangRefs, unresolvedXrefsXlang = [] }
_ -> return docSyms
Expand Down

0 comments on commit 9f4d815

Please sign in to comment.