How to use the @sourcegraph/codeintellify.findPositionsFromEvents function in @sourcegraph/codeintellify

To help you get started, we’ve selected a few @sourcegraph/codeintellify examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github sourcegraph / sourcegraph / packages / webapp / src / repo / blob / Blob.tsx View on Github external
fetchHover: position => getHover(this.getLSPTextDocumentPositionParams(position), this.props),
            fetchJumpURL: position => getJumpURL(this.getLSPTextDocumentPositionParams(position), this.props),
        })
        this.subscriptions.add(hoverifier)

        const resolveContext = () => ({
            repoPath: this.props.repoPath,
            rev: this.props.rev,
            commitID: this.props.commitID,
            filePath: this.props.filePath,
        })
        this.subscriptions.add(
            hoverifier.hoverify({
                positionEvents: this.codeViewElements.pipe(
                    filter(isDefined),
                    findPositionsFromEvents(domFunctions)
                ),
                positionJumps: locationPositions.pipe(
                    withLatestFrom(this.codeViewElements, this.blobElements),
                    map(([position, codeView, scrollElement]) => ({
                        position,
                        // locationPositions is derived from componentUpdates,
                        // so these elements are guaranteed to have been rendered.
                        codeView: codeView!,
                        scrollElement: scrollElement!,
                    }))
                ),
                resolveContext,
                dom: domFunctions,
            })
        )
        this.subscriptions.add(
github sourcegraph / sourcegraph / packages / webapp / src / search / input / CodeIntellifyBlob.tsx View on Github external
map(({ hoverOverlayElement, codeIntellifyBlobElement }) => ({
                    hoverOverlayElement,
                    relativeElement: codeIntellifyBlobElement.closest(this.props.parentElement) as HTMLElement | null,
                })),
                // Can't reposition HoverOverlay or file weren't rendered
                filter(propertyIsDefined('relativeElement')),
                filter(propertyIsDefined('hoverOverlayElement'))
            ),
            fetchHover: hoveredToken => getHover(this.getLSPTextDocumentPositionParams(hoveredToken), this.props),
            fetchJumpURL: hoveredToken => getJumpURL(this.getLSPTextDocumentPositionParams(hoveredToken), this.props),
        })

        this.subscriptions.add(hoverifier)
        const positionEvents = this.codeViewElements.pipe(
            filter(isDefined),
            findPositionsFromEvents(domFunctions)
        )

        const targets = positionEvents.pipe(map(({ event: { target } }) => target))

        targets.subscribe(target => (this.target = target))

        this.subscriptions.add(
            hoverifier.hoverify({
                positionEvents,
                resolveContext: () => ({
                    repoPath: REPO_PATH,
                    commitID: COMMIT_ID,
                    rev: REV || '',
                    filePath: FILE_PATH,
                }),
                dom: domFunctions,
github sourcegraph / sourcegraph / web / src / repo / blob / Blob.tsx View on Github external
// After componentDidUpdate, the blob element is guaranteed to have been rendered
                map(([, hoverOverlayElement, blobElement]) => ({ hoverOverlayElement, relativeElement: blobElement! })),
                // Can't reposition HoverOverlay if it wasn't rendered
                filter(propertyIsDefined('hoverOverlayElement'))
            ),
            getHover: position => getHover(this.getLSPTextDocumentPositionParams(position), this.props),
            getActions: context => getHoverActions(this.props, context),
            pinningEnabled: !singleClickGoToDefinition,
        })
        this.subscriptions.add(hoverifier)

        this.subscriptions.add(
            hoverifier.hoverify({
                positionEvents: this.codeViewElements.pipe(
                    filter(isDefined),
                    findPositionsFromEvents({ domFunctions })
                ),
                positionJumps: locationPositions.pipe(
                    withLatestFrom(this.codeViewElements, this.blobElements),
                    map(([position, codeView, scrollElement]) => ({
                        position,
                        // locationPositions is derived from componentUpdates,
                        // so these elements are guaranteed to have been rendered.
                        codeView: codeView!,
                        scrollElement: scrollElement!,
                    }))
                ),
                resolveContext: () => ({
                    repoName: this.props.repoName,
                    rev: this.props.rev,
                    commitID: this.props.commitID,
                    filePath: this.props.filePath,
github sourcegraph / sourcegraph / web / src / search / input / CodeIntellifyBlob.tsx View on Github external
map(({ hoverOverlayElement, codeIntellifyBlobElement }) => ({
                    hoverOverlayElement,
                    relativeElement: codeIntellifyBlobElement.closest(this.props.parentElement) as HTMLElement | null,
                })),
                // Can't reposition HoverOverlay or file weren't rendered
                filter(propertyIsDefined('relativeElement')),
                filter(propertyIsDefined('hoverOverlayElement'))
            ),
            getHover: hoveredToken => getHover(this.getLSPTextDocumentPositionParams(hoveredToken), this.props),
            getActions: context => getHoverActions(this.props, context),
        })

        this.subscriptions.add(hoverifier)
        const positionEvents = this.codeViewElements.pipe(
            filter(isDefined),
            findPositionsFromEvents(domFunctions)
        )

        const targets = positionEvents.pipe(map(({ event: { target } }) => target))

        targets.subscribe(target => (this.target = target))

        this.subscriptions.add(
            hoverifier.hoverify({
                positionEvents,
                resolveContext: () => ({
                    repoName: REPO_NAME,
                    commitID: COMMIT_ID,
                    rev: REV || '',
                    filePath: FILE_PATH,
                }),
                dom: domFunctions,
github sourcegraph / sourcegraph / packages / webapp / src / repo / compare / FileDiffHunks.tsx View on Github external
constructor(props: Props) {
        super(props)
        this.state = {
            hoverOverlayIsFixed: false,
            clickedGoToDefinition: false,
            mouseIsMoving: false,
        }

        this.subscriptions.add(
            this.props.hoverifier.hoverify({
                dom: diffDomFunctions,
                positionEvents: this.codeElements.pipe(
                    filter(isDefined),
                    findPositionsFromEvents(diffDomFunctions)
                ),
                positionJumps: NEVER, // TODO support diff URLs
                resolveContext: hoveredToken => {
                    // if part is undefined, it doesn't matter whether we chose head or base, the line stayed the same
                    const { repoPath, rev, filePath, commitID } = this.props[hoveredToken.part || 'head']
                    // If a hover or go-to-definition was invoked on this part, we know the file path must exist
                    return { repoPath, filePath: filePath!, rev, commitID }
                },
            })
        )
    }
github sourcegraph / sourcegraph / web / src / components / diff / FileDiffHunks.tsx View on Github external
constructor(props: FileHunksProps) {
        super(props)
        this.state = {
            decorations: { head: new Map(), base: new Map() },
        }

        if (this.props.extensionInfo) {
            this.subscriptions.add(
                this.props.extensionInfo.hoverifier.hoverify({
                    dom: diffDomFunctions,
                    positionEvents: this.codeElements.pipe(
                        filter(isDefined),
                        findPositionsFromEvents({ domFunctions: diffDomFunctions })
                    ),
                    positionJumps: NEVER, // TODO support diff URLs
                    resolveContext: hoveredToken => {
                        // if part is undefined, it doesn't matter whether we chose head or base, the line stayed the same
                        const { repoName, rev, filePath, commitID } = this.props.extensionInfo![
                            hoveredToken.part || 'head'
                        ]
                        // If a hover or go-to-definition was invoked on this part, we know the file path must exist
                        return { repoName, filePath: filePath!, rev, commitID }
                    },
                })
            )
        }

        // Listen to decorations from extensions and group them by line
        this.subscriptions.add(
github sourcegraph / sourcegraph / browser / src / libs / code_intelligence / code_intelligence.tsx View on Github external
nativeTooltipsEnabled.subscribe(useNativeTooltips => {
                    hoverSubscription.unsubscribe()
                    if (!useNativeTooltips) {
                        hoverSubscription = hoverifier.hoverify({
                            dom: domFunctions,
                            positionEvents: of(element).pipe(
                                findPositionsFromEvents({
                                    domFunctions,
                                    tokenize: codeHost.codeViewsRequireTokenization !== false,
                                })
                            ),
                            resolveContext,
                            adjustPosition,
                            scrollBoundaries: codeViewEvent.getScrollBoundaries
                                ? codeViewEvent.getScrollBoundaries(codeViewEvent.element)
                                : [],
                        })
                    }
                })
            )
github sourcegraph / browser-extensions / src / libs / code_intelligence / code_intelligence.tsx View on Github external
}

                        documentsSubject.next(documents)
                    }

                    const resolveContext: ContextResolver = ({ part }) => ({
                        repoPath: part === 'base' ? info.baseRepoPath || info.repoPath : info.repoPath,
                        commitID: part === 'base' ? info.baseCommitID! : info.commitID,
                        filePath: part === 'base' ? info.baseFilePath || info.filePath : info.filePath,
                        rev: part === 'base' ? info.baseRev || info.baseCommitID! : info.rev || info.commitID,
                    })

                    subscriptions.add(
                        hoverifier.hoverify({
                            dom,
                            positionEvents: of(codeView).pipe(findPositionsFromEvents(dom)),
                            resolveContext,
                            adjustPosition,
                        })
                    )

                    codeView.classList.add('sg-mounted')

                    if (!getToolbarMount) {
                        return
                    }

                    const mount = getToolbarMount(codeView)

                    render(
github sourcegraph / sourcegraph / client / browser / src / libs / code_intelligence / code_intelligence.tsx View on Github external
extensionsController.services.model.model.next({ roots, visibleViewComponents })
                    }

                    const resolveContext: ContextResolver = ({
                        part,
                    }) => ({
                        repoPath: part === 'base' ? info.baseRepoPath || info.repoPath : info.repoPath,
                        commitID: part === 'base' ? info.baseCommitID! : info.commitID,
                        filePath: part === 'base' ? info.baseFilePath || info.filePath : info.filePath,
                        rev: part === 'base' ? info.baseRev || info.baseCommitID! : info.rev || info.commitID,
                    })

                    subscriptions.add(
                        hoverifier.hoverify({
                            dom,
                            positionEvents: of(codeView).pipe(findPositionsFromEvents(dom)),
                            resolveContext,
                            adjustPosition,
                        })
                    )

                    codeView.classList.add('sg-mounted')

                    if (!getToolbarMount) {
                        return
                    }

                    const mount = getToolbarMount(codeView)

                    render(