1
1
import { BehaviorSubject } from 'rxjs'
2
+ import { MessageConnection } from '../../../jsonrpc2/connection'
2
3
import {
3
4
DidCloseTextDocumentNotification ,
4
5
DidOpenTextDocumentNotification ,
5
6
ShowInputRequest ,
6
7
TextDocumentDecoration ,
7
8
TextDocumentPublishDecorationsNotification ,
8
9
TextDocumentPublishDecorationsParams ,
9
- } from '../../protocol'
10
- import { TextDocumentIdentifier } from '../../types/textDocument'
11
- import { Observable , SourcegraphExtensionAPI , Window , Windows } from '../api'
10
+ } from '../../../protocol'
11
+ import { TextDocumentIdentifier } from '../../../types/textDocument'
12
+ import { URI } from '../../../types/uri'
13
+ import { Observable , Window , Windows } from '../api'
12
14
13
15
/**
14
16
* Implements the Sourcegraph extension API's {@link SourcegraphExtensionAPI#windows} value.
@@ -17,7 +19,7 @@ import { Observable, SourcegraphExtensionAPI, Window, Windows } from '../api'
17
19
* @return The {@link SourcegraphExtensionAPI#windows} value.
18
20
*/
19
21
export class ExtWindows extends BehaviorSubject < Window [ ] > implements Windows , Observable < Window [ ] > {
20
- constructor ( private ext : Pick < SourcegraphExtensionAPI < any > , 'rawConnection' > ) {
22
+ constructor ( private rawConnection : MessageConnection ) {
21
23
super ( [
22
24
{
23
25
isActive : true ,
@@ -26,15 +28,17 @@ export class ExtWindows extends BehaviorSubject<Window[]> implements Windows, Ob
26
28
] )
27
29
28
30
// Track last-opened text document.
29
- ext . rawConnection . onNotification ( DidOpenTextDocumentNotification . type , params => {
30
- this . next ( [ { ...this . value [ 0 ] , activeComponent : { isActive : true , resource : params . textDocument . uri } } ] )
31
+ rawConnection . onNotification ( DidOpenTextDocumentNotification . type , params => {
32
+ this . next ( [
33
+ { ...this . value [ 0 ] , activeComponent : { isActive : true , resource : URI . parse ( params . textDocument . uri ) } } ,
34
+ ] )
31
35
} )
32
- ext . rawConnection . onNotification ( DidCloseTextDocumentNotification . type , params => {
36
+ rawConnection . onNotification ( DidCloseTextDocumentNotification . type , params => {
33
37
if (
34
38
this . activeWindow &&
35
39
this . activeWindow . activeComponent &&
36
40
this . activeWindow . activeComponent . resource &&
37
- this . activeWindow . activeComponent . resource === params . textDocument . uri
41
+ this . activeWindow . activeComponent . resource . toString ( ) === params . textDocument . uri
38
42
) {
39
43
this . next ( [ { ...this . value [ 0 ] , activeComponent : null } ] )
40
44
}
@@ -46,11 +50,11 @@ export class ExtWindows extends BehaviorSubject<Window[]> implements Windows, Ob
46
50
}
47
51
48
52
public showInputBox ( message : string , defaultValue ?: string ) : Promise < string | null > {
49
- return this . ext . rawConnection . sendRequest ( ShowInputRequest . type , { message, defaultValue } )
53
+ return this . rawConnection . sendRequest ( ShowInputRequest . type , { message, defaultValue } )
50
54
}
51
55
52
56
public setDecorations ( resource : TextDocumentIdentifier , decorations : TextDocumentDecoration [ ] ) : void {
53
- return this . ext . rawConnection . sendNotification ( TextDocumentPublishDecorationsNotification . type , {
57
+ return this . rawConnection . sendNotification ( TextDocumentPublishDecorationsNotification . type , {
54
58
textDocument : resource ,
55
59
decorations,
56
60
} as TextDocumentPublishDecorationsParams )
0 commit comments