Skip to content
This repository was archived by the owner on Jan 22, 2019. It is now read-only.

Commit 893768e

Browse files
author
Stephen Gutekanst
committed
fix: do not display code intelligence hovers on Sourcegraph Extension…
…line decorations Prior to this change, hovering over text/links provided by a Sourcegraph Extension would trigger the display of the hover 'loading' indicator. On most files, it goes away quickly (just a flicker), but on some it displays an error: ![image](https://user-images.githubusercontent.com/3173176/45585161-caaff580-b894-11e8-8b3f-10347f2aa438.png) After this change, we no longer attempt to display hovers etc. on the DOM elements which Sourcegraph Extensions provide. Fixes sourcegraph/sourcegraph-extension-api#67
1 parent 288706e commit 893768e

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

src/libs/code_intelligence/code_intelligence.tsx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,19 @@ function handleCodeHost(codeHost: CodeHost): Subscription {
365365
const toURIWithPath = (ctx: AbsoluteRepoFile) =>
366366
`git://${ctx.repoPath}?${ctx.commitID}#${ctx.filePath}`
367367

368+
const originalDOM = dom
369+
dom = {
370+
...dom,
371+
// If any parent element has the sourcegraph-extension-element
372+
// class then that element does not have any code. We
373+
// must check for "any parent element" because extensions
374+
// create their DOM changes before the blob is tokenized
375+
// into multiple elements.
376+
getCodeElementFromTarget: (target: HTMLElement): HTMLElement | null =>
377+
target.closest('.sourcegraph-extension-element') !== null
378+
? null
379+
: originalDOM.getCodeElementFromTarget(target),
380+
}
368381
if (extensionsController) {
369382
const { content, baseContent } = getContentOfCodeView(codeView, { isDiff, getLineRanges, dom })
370383

src/libs/code_intelligence/extensions.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,13 +174,15 @@ export const applyDecoration = (
174174
if (decoration.after) {
175175
const linkTo = (url: string) => (e: HTMLElement): HTMLElement => {
176176
const link = document.createElement('a')
177+
link.className = 'sourcegraph-extension-element'
177178
link.setAttribute('href', url)
178179
link.style.color = decoration.after!.color || null
179180
link.appendChild(e)
180181
return link
181182
}
182183

183184
const after = document.createElement('span')
185+
after.className = 'sourcegraph-extension-element'
184186
after.style.backgroundColor = decoration.after.backgroundColor || null
185187
after.textContent = decoration.after.contentText || null
186188

0 commit comments

Comments
 (0)