Skip to content

Commit 117ea80

Browse files
committed
add prettier, setup line matching for all expected match cases
1 parent 23aaaee commit 117ea80

File tree

4 files changed

+5709
-15
lines changed

4 files changed

+5709
-15
lines changed

package.json

+13-4
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,20 @@
22
"$schema": "https://raw.githubusercontent.com/sourcegraph/sourcegraph/master/shared/src/schema/extension.schema.json",
33
"name": "sourcegraph-sentry",
44
"description": "Sourcegraph Sentry extension renders \"View logs on Sentry\" links next to error handling code.",
5-
"publisher": "vanesa",
5+
"publisher": "Sourcegraph",
66
"activationEvents": [
77
"*"
88
],
99
"wip": true,
10-
"categories": [],
11-
"tags": [],
10+
"categories": [
11+
"External services"
12+
],
13+
"tags": [
14+
"sentry",
15+
"error tracking",
16+
"errors",
17+
"logs"
18+
],
1219
"contributes": {
1320
"actions": [],
1421
"menus": {
@@ -22,7 +29,7 @@
2229
"type": "git",
2330
"url": "https://github.com/sourcegraph/sourcegraph-sentry.git"
2431
},
25-
"license": "UNLICENSED",
32+
"license": "Apache-2.0",
2633
"main": "dist/sourcegraph-sentry.js",
2734
"scripts": {
2835
"tslint": "tslint -p tsconfig.json './src/**/*.ts'",
@@ -41,11 +48,13 @@
4148
"last 1 Safari versions"
4249
],
4350
"devDependencies": {
51+
"@sourcegraph/prettierrc": "^2.2.0",
4452
"@sourcegraph/tsconfig": "^4.0.0",
4553
"@sourcegraph/tslint-config": "^12.3.1",
4654
"lnfs-cli": "^2.1.0",
4755
"mkdirp": "^0.5.1",
4856
"parcel-bundler": "^1.12.0",
57+
"rxjs": "^6.4.0",
4958
"sourcegraph": "^23.0.0",
5059
"tslint": "^5.13.1",
5160
"typescript": "^3.3.3333"

prettier.config.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = require('@sourcegraph/prettierrc')

src/sourcegraph-sentry.ts

+43-11
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,48 @@
1+
import { from } from 'rxjs'
2+
import { filter, switchMap } from 'rxjs/operators'
13
import * as sourcegraph from 'sourcegraph'
24

3-
export function activate(ctx: sourcegraph.ExtensionContext): void {
4-
ctx.subscriptions.add(
5-
sourcegraph.languages.registerHoverProvider(['*'], {
6-
provideHover: () => ({
7-
contents: {
8-
value: 'Hello world from sourcegraph-sentry! 🎉🎉🎉',
9-
kind: sourcegraph.MarkupKind.Markdown
10-
}
11-
}),
12-
})
13-
)
5+
const CODE_PATTERNS = [
6+
/throw new Error+\([\'\"]([^\'\"]+)[\'\"]\)/gi,
7+
/console\.[^\'\"]+\([\'\"]([^\'\"]+)[\'\"]\)/gi,
8+
/log\.[^\'\"]+\([\'\"]([^\'\"]+)[\'\"]\)/gi,
9+
]
10+
11+
const DECORATION_TYPE = sourcegraph.app.createDecorationType()
12+
13+
function decorateEditor(editor: sourcegraph.CodeEditor): void {
14+
const decorations: sourcegraph.TextDocumentDecoration[] = []
15+
for (const [i, line] of editor.document.text!.split('\n').entries()) {
16+
for (const pattern of CODE_PATTERNS) {
17+
const match = line.match(pattern)
18+
if (match) {
19+
decorations.push({
20+
range: new sourcegraph.Range(i, 0, i, 0),
21+
isWholeLine: true,
22+
after: {
23+
backgroundColor: '#e03e2f',
24+
color: 'rgba(255, 255, 255, 0.8)',
25+
contentText: ' View logs in Sentry » ',
26+
linkURL: 'testUrl',
27+
},
28+
})
29+
}
30+
pattern.lastIndex = 0 // reset
31+
}
32+
}
33+
editor.setDecorations(DECORATION_TYPE, decorations)
34+
}
35+
36+
export function activate(context: sourcegraph.ExtensionContext): void {
37+
if (sourcegraph.app.activeWindowChanges) {
38+
const activeEditor = from(sourcegraph.app.activeWindowChanges).pipe(
39+
filter((window): window is sourcegraph.Window => window !== undefined),
40+
switchMap(window => window.activeViewComponentChanges),
41+
filter((editor): editor is sourcegraph.CodeEditor => editor !== undefined)
42+
)
43+
// When the active editor changes, publish new decorations.
44+
context.subscriptions.add(activeEditor.subscribe(decorateEditor))
45+
}
1446
}
1547

1648
// Sourcegraph extension documentation: https://docs.sourcegraph.com/extensions/authoring

0 commit comments

Comments
 (0)