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

Commit 36da4ea

Browse files
committed
feat: support themable decorations from extensions
Respect the theme overrides from an extension for its decorations.
1 parent c7409d3 commit 36da4ea

File tree

3 files changed

+22
-5
lines changed

3 files changed

+22
-5
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@
138138
"reactstrap": "^5.0.0-beta.2",
139139
"rxjs": "^6.3.2",
140140
"socket.io-client": "^2.1.1",
141-
"sourcegraph": "^18.0.0",
141+
"sourcegraph": "^18.3.0",
142142
"string-score": "^1.0.1",
143143
"textarea-caret": "^3.1.0",
144144
"ts-key-enum": "^2.0.0",

src/libs/code_intelligence/extensions.tsx

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ import { Disposable } from 'vscode-languageserver'
2323

2424
import { DOMFunctions } from '@sourcegraph/codeintellify'
2525
import * as H from 'history'
26+
import {
27+
decorationAttachmentStyleForTheme,
28+
decorationStyleForTheme,
29+
} from 'sourcegraph/module/client/providers/decoration'
2630
import { isErrorLike } from '../../shared/backend/errors'
2731
import { createExtensionsContextController, createMessageTransports } from '../../shared/backend/extensions'
2832
import { GlobalDebug } from '../../shared/components/GlobalDebug'
@@ -141,6 +145,8 @@ const mergeDisposables = (...disposables: Disposable[]): Disposable => ({
141145
},
142146
})
143147

148+
const IS_LIGHT_THEME = true // assume all code hosts have a light theme (correct for now)
149+
144150
/**
145151
* Applies a decoration to a code view. This doesn't work with diff views yet.
146152
*/
@@ -162,8 +168,9 @@ export const applyDecoration = (
162168
throw new Error(`Unable to find code element for line ${lineNumber}`)
163169
}
164170

165-
if (decoration.backgroundColor) {
166-
codeElement.style.backgroundColor = decoration.backgroundColor
171+
const style = decorationStyleForTheme(decoration, IS_LIGHT_THEME)
172+
if (style.backgroundColor) {
173+
codeElement.style.backgroundColor = style.backgroundColor
167174
disposables.push({
168175
dispose: () => {
169176
codeElement.style.backgroundColor = null
@@ -172,6 +179,8 @@ export const applyDecoration = (
172179
}
173180

174181
if (decoration.after) {
182+
const style = decorationAttachmentStyleForTheme(decoration.after, IS_LIGHT_THEME)
183+
175184
const linkTo = (url: string) => (e: HTMLElement): HTMLElement => {
176185
const link = document.createElement('a')
177186
link.className = 'sourcegraph-extension-element'
@@ -184,14 +193,14 @@ export const applyDecoration = (
184193
// Avoid leaking referrer URLs (which contain repository and path names, etc.) to external sites.
185194
link.setAttribute('rel', 'noreferrer noopener')
186195

187-
link.style.color = decoration.after!.color || null
196+
link.style.color = style.color || null
188197
link.appendChild(e)
189198
return link
190199
}
191200

192201
const after = document.createElement('span')
193202
after.className = 'sourcegraph-extension-element'
194-
after.style.backgroundColor = decoration.after.backgroundColor || null
203+
after.style.backgroundColor = style.backgroundColor || null
195204
after.textContent = decoration.after.contentText || null
196205
after.title = decoration.after.hoverMessage || ''
197206

yarn.lock

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14149,6 +14149,14 @@ sourcegraph@^18.0.0:
1414914149
minimatch "^3.0.4"
1415014150
rxjs "^6.3.2"
1415114151

14152+
sourcegraph@^18.3.0:
14153+
version "18.3.0"
14154+
resolved "https://registry.yarnpkg.com/sourcegraph/-/sourcegraph-18.3.0.tgz#d624b042aabf5aa5c90cefad59cc05f697ae448c"
14155+
integrity sha512-jTbfpcNwfSU63rU6RcpEg8NYGdqR3UyF8SlEnxe6Wg79lUa3Mocq3djTYgnf8SGVovdcHXGZQYWaLGeALgvsxw==
14156+
dependencies:
14157+
minimatch "^3.0.4"
14158+
rxjs "^6.3.2"
14159+
1415214160
spawn-error-forwarder@~1.0.0:
1415314161
version "1.0.0"
1415414162
resolved "https://registry.yarnpkg.com/spawn-error-forwarder/-/spawn-error-forwarder-1.0.0.tgz#1afd94738e999b0346d7b9fc373be55e07577029"

0 commit comments

Comments
 (0)