Showing 3 of 12 files from the diff.

@@ -38,7 +38,7 @@
Loading
38 38
    selections: Selection[],
39 39
    now: number,
40 40
    sourcegraph: typeof import('sourcegraph')
41 -
) => {
41 +
): TextDocumentDecoration[] => {
42 42
    const decorations: TextDocumentDecoration[] = []
43 43
    for (const hunk of hunks) {
44 44
        // Hunk start and end lines are 1-indexed, but selection lines are zero-indexed
@@ -60,8 +60,11 @@
Loading
60 60
    return decorations
61 61
}
62 62
63 -
export const getAllBlameDecorations = (hunks: Hunk[], now: number, sourcegraph: typeof import('sourcegraph')) =>
64 -
    hunks.map(hunk => getDecorationFromHunk(hunk, now, hunk.startLine - 1, sourcegraph))
63 +
export const getAllBlameDecorations = (
64 +
    hunks: Hunk[],
65 +
    now: number,
66 +
    sourcegraph: typeof import('sourcegraph')
67 +
): TextDocumentDecoration[] => hunks.map(hunk => getDecorationFromHunk(hunk, now, hunk.startLine - 1, sourcegraph))
65 68
66 69
const queryBlameHunks = memoizeAsync(
67 70
    async ({ uri, sourcegraph }: { uri: string; sourcegraph: typeof import('sourcegraph') }): Promise<Hunk[]> => {
@@ -139,9 +142,8 @@
Loading
139 142
    const hunks = await queryHunks({ uri, sourcegraph })
140 143
    if (selections !== null && decorations === 'line') {
141 144
        return getBlameDecorationsForSelections(hunks, selections, now, sourcegraph)
142 -
    } else {
143 -
        return getAllBlameDecorations(hunks, now, sourcegraph)
144 145
    }
146 +
    return getAllBlameDecorations(hunks, now, sourcegraph)
145 147
}
146 148
147 149
export interface Hunk {
@@ -164,9 +166,9 @@
Loading
164 166
    }
165 167
}
166 168
167 -
function truncate(s: string, max: number, omission = '…'): string {
168 -
    if (s.length <= max) {
169 -
        return s
169 +
function truncate(string: string, max: number, omission = '…'): string {
170 +
    if (string.length <= max) {
171 +
        return string
170 172
    }
171 -
    return `${s.slice(0, max)}${omission}`
173 +
    return `${string.slice(0, max)}${omission}`
172 174
}

@@ -11,7 +11,7 @@
Loading
11 11
    ['git.blame.decorateWholeFile']?: boolean
12 12
}
13 13
14 -
const decorationType = sourcegraph.app.createDecorationType && sourcegraph.app.createDecorationType()
14 +
const decorationType = sourcegraph.app?.createDecorationType()
15 15
16 16
export function activate(context: sourcegraph.ExtensionContext): void {
17 17
    // TODO(lguychard) sourcegraph.configuration is currently not rxjs-compatible.
@@ -21,33 +21,21 @@
Loading
21 21
22 22
    // Backcompat: Set 'git.blame.decorations' based on previous settings values
23 23
    ;(async () => {
24 -
        try {
25 -
            const settings = sourcegraph.configuration.get<Settings>().value
26 -
            const initialDecorations = settings['git.blame.decorations']
27 -
            if (!initialDecorations) {
28 -
                if (settings['git.blame.lineDecorations'] === false) {
29 -
                    await sourcegraph.commands.executeCommand('updateConfiguration', ['git.blame.decorations'], 'none')
30 -
                } else if (settings['git.blame.lineDecorations'] === true) {
31 -
                    if (settings['git.blame.decorateWholeFile']) {
32 -
                        await sourcegraph.commands.executeCommand(
33 -
                            'updateConfiguration',
34 -
                            ['git.blame.decorations'],
35 -
                            'file'
36 -
                        )
37 -
                    } else {
38 -
                        await sourcegraph.commands.executeCommand(
39 -
                            'updateConfiguration',
40 -
                            ['git.blame.decorations'],
41 -
                            'line'
42 -
                        )
43 -
                    }
24 +
        const settings = sourcegraph.configuration.get<Settings>().value
25 +
        const initialDecorations = settings['git.blame.decorations']
26 +
        if (!initialDecorations) {
27 +
            if (settings['git.blame.lineDecorations'] === false) {
28 +
                await sourcegraph.commands.executeCommand('updateConfiguration', ['git.blame.decorations'], 'none')
29 +
            } else if (settings['git.blame.lineDecorations'] === true) {
30 +
                if (settings['git.blame.decorateWholeFile']) {
31 +
                    await sourcegraph.commands.executeCommand('updateConfiguration', ['git.blame.decorations'], 'file')
44 32
                } else {
45 -
                    // Default to 'line'
46 33
                    await sourcegraph.commands.executeCommand('updateConfiguration', ['git.blame.decorations'], 'line')
47 34
                }
35 +
            } else {
36 +
                // Default to 'line'
37 +
                await sourcegraph.commands.executeCommand('updateConfiguration', ['git.blame.decorations'], 'line')
48 38
            }
49 -
        } catch {
50 -
            // noop
51 39
        }
52 40
    })().catch(() => {
53 41
        // noop
@@ -62,19 +50,24 @@
Loading
62 50
        )
63 51
        // When the configuration or current file changes, publish new decorations.
64 52
        context.subscriptions.add(
65 -
            combineLatest(configurationChanges, selectionChanges).subscribe(([, { editor, selections }]) =>
66 -
                decorate(editor, selections)
67 -
            )
53 +
            combineLatest(configurationChanges, selectionChanges).subscribe(([, { editor, selections }]) => {
54 +
                decorate(editor, selections).catch(() => {
55 +
                    // noop
56 +
                })
57 +
            })
68 58
        )
69 59
    } else {
70 60
        // Backcompat: the extension host does not support activeWindowChanges or CodeEditor.selectionsChanges.
71 61
        // When configuration changes or onDidOpenTextDocument fires, add decorations for all blame hunks.
72 -
        const activeEditor = () => sourcegraph.app.activeWindow && sourcegraph.app.activeWindow.activeViewComponent
62 +
        const activeEditor = (): sourcegraph.CodeEditor | sourcegraph.DirectoryViewer | undefined =>
63 +
            sourcegraph.app.activeWindow?.activeViewComponent
73 64
        context.subscriptions.add(
74 -
            combineLatest(configurationChanges, from(sourcegraph.workspace.openedTextDocuments)).subscribe(async () => {
65 +
            combineLatest(configurationChanges, from(sourcegraph.workspace.openedTextDocuments)).subscribe(() => {
75 66
                const editor = activeEditor()
76 67
                if (editor && editor.type === 'CodeEditor') {
77 -
                    await decorate(editor, null)
68 +
                    decorate(editor, null).catch(() => {
69 +
                        // noop
70 +
                    })
78 71
                }
79 72
            })
80 73
        )
@@ -95,8 +88,8 @@
Loading
95 88
                    sourcegraph,
96 89
                })
97 90
            )
98 -
        } catch (err) {
99 -
            console.error('Decoration error:', err)
91 +
        } catch (error) {
92 +
            console.error('Decoration error:', error)
100 93
        }
101 94
    }
102 95
}

@@ -6,19 +6,19 @@
Loading
6 6
 * function
7 7
 */
8 8
export function memoizeAsync<P, T>(
9 -
    func: (params: P) => Promise<T>,
10 -
    toKey: (params: P) => string
11 -
): (params: P) => Promise<T> {
9 +
    func: (parameters: P) => Promise<T>,
10 +
    toKey: (parameters: P) => string
11 +
): (parameters: P) => Promise<T> {
12 12
    const cache = new Map<string, Promise<T>>()
13 -
    return (params: P) => {
14 -
        const key = toKey(params)
13 +
    return (parameters: P) => {
14 +
        const key = toKey(parameters)
15 15
        const hit = cache.get(key)
16 16
        if (hit) {
17 17
            return hit
18 18
        }
19 -
        const p = func(params)
20 -
        p.then(null, () => cache.delete(key))
21 -
        cache.set(key, p)
22 -
        return p
19 +
        const promise = func(parameters)
20 +
        promise.then(null, () => cache.delete(key))
21 +
        cache.set(key, promise)
22 +
        return promise
23 23
    }
24 24
}
Files Coverage
src 0.00%
Project Totals (4 files) 0.00%
1143.1
10=0
TRAVIS_OS_NAME=linux

No yaml found.

Create your codecov.yml to customize your Codecov experience

Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file. The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files. The size and color of each slice is representing the number of statements and the coverage, respectively.
Grid
Each block represents a single file in the project. The size and color of each block is represented by the number of statements and the coverage, respectively.
Loading