1
- import * as sourcegraph from 'sourcegraph'
2
1
import { distanceInWordsToNow } from 'date-fns'
2
+ import * as sourcegraph from 'sourcegraph'
3
3
import { resolveSettings , Settings } from './settings'
4
4
import { fetchDiscussionThreads } from './shared/api'
5
+ import { resolveURI } from './uri'
5
6
6
7
const decorationType = sourcegraph . app . createDecorationType && sourcegraph . app . createDecorationType ( )
7
8
@@ -16,7 +17,7 @@ export function activate(): void {
16
17
return
17
18
}
18
19
19
- const u = new ( global as any ) . URL ( editor . document . uri )
20
+ const u = new URL ( editor . document . uri )
20
21
const uri = {
21
22
repositoryName : u . pathname . slice ( 2 ) ,
22
23
revision : u . search . slice ( 1 ) ,
@@ -30,8 +31,8 @@ export function activate(): void {
30
31
relativeRev : uri . revision ,
31
32
} )
32
33
33
- let decorations : sourcegraph . TextDocumentDecoration [ ] = [ ]
34
- threads . nodes . forEach ( thread => {
34
+ const decorations : sourcegraph . TextDocumentDecoration [ ] = [ ]
35
+ for ( const thread of threads . nodes ) {
35
36
const settings = resolveSettings ( sourcegraph . configuration . get < Settings > ( ) . value )
36
37
if ( ! settings [ 'discussions.decorations.inline' ] ) {
37
38
return
@@ -40,7 +41,7 @@ export function activate(): void {
40
41
if ( thread . target . __typename !== 'DiscussionThreadTargetRepo' ) {
41
42
return
42
43
}
43
- var target = thread . target as SourcegraphGQL . IDiscussionThreadTargetRepo
44
+ const target : SourcegraphGQL . IDiscussionThreadTargetRepo = thread . target
44
45
if ( target . relativePath !== uri . filePath ) {
45
46
// TODO(slimsag): shouldn't the discussions API return threads created in different files and moved here, too? lol :facepalm:
46
47
return // comment has since moved to a different file.
@@ -57,8 +58,8 @@ export function activate(): void {
57
58
) } ago`
58
59
59
60
// TODO(slimsag): color scheme detection was impossible when this was written, see https://github.com/sourcegraph/sourcegraph/issues/732
60
- const color = ( global as any ) . location . host === 'github.com' ? 'black' : '#0366d6' // #3b4d6e
61
- const backgroundColor = ( global as any ) . location . host === 'github.com' ? 'white' : 'rgba(28, 126, 214, 0.3)' // #151c28
61
+ const color = window . location . host === 'github.com' ? 'black' : '#0366d6' // #3b4d6e
62
+ const backgroundColor = window . location . host === 'github.com' ? 'white' : 'rgba(28, 126, 214, 0.3)' // #151c28
62
63
63
64
decorations . push ( {
64
65
range : new sourcegraph . Range (
@@ -74,16 +75,16 @@ export function activate(): void {
74
75
after : {
75
76
contentText : ' 💬 ' + describeThread ( shortTitle ) ,
76
77
linkURL : thread . inlineURL
77
- ? ( global as any ) . location . host
78
+ ? window . location . host
78
79
? thread . inlineURL . slice ( thread . inlineURL . lastIndexOf ( '#' ) )
79
80
: thread . inlineURL
80
81
: undefined ,
81
82
hoverMessage : ' ' + describeThread ( thread . title ) ,
82
- color : color ,
83
+ color,
83
84
} ,
84
- backgroundColor : backgroundColor ,
85
+ backgroundColor,
85
86
} )
86
- } )
87
+ }
87
88
88
89
try {
89
90
editor . setDecorations ( decorationType , decorations )
0 commit comments