1
- import { BehaviorSubject , Observable , Unsubscribable } from 'rxjs'
2
- import uuidv4 from 'uuid/v4'
1
+ import { BehaviorSubject , Observable } from 'rxjs'
3
2
import { TextDocumentIdentifier } from 'vscode-languageserver-types'
4
3
import { ProvideTextDocumentDecorationSignature } from '../../environment/providers/decoration'
5
4
import { FeatureProviderRegistry } from '../../environment/providers/registry'
6
5
import { ClientCapabilities } from '../../protocol'
7
6
import { TextDocumentDecoration , TextDocumentPublishDecorationsNotification } from '../../protocol/decoration'
8
7
import { Client } from '../client'
9
- import { ensure , Feature } from './common'
8
+ import { ensure , StaticFeature } from './common'
10
9
11
10
/**
12
11
* Support for text document decorations published by the server (textDocument/publishDecorations notifications
13
12
* from the server).
14
13
*/
15
- export class TextDocumentDecorationFeature extends Feature < undefined > {
14
+ export class TextDocumentDecorationFeature implements StaticFeature {
16
15
/** Map of document URI to its decorations (last published by the server). */
17
16
private decorations = new Map < string , BehaviorSubject < TextDocumentDecoration [ ] | null > > ( )
18
17
19
18
constructor (
20
- client : Client ,
19
+ private client : Client ,
21
20
private registry : FeatureProviderRegistry < undefined , ProvideTextDocumentDecorationSignature >
22
21
) {
23
- super ( client )
24
- this . register ( this . messages , { id : uuidv4 ( ) , registerOptions : undefined } )
22
+ this . registry . registerProvider (
23
+ undefined ,
24
+ ( textDocument : TextDocumentIdentifier ) : Observable < TextDocumentDecoration [ ] | null > =>
25
+ this . getDecorationsSubject ( textDocument )
26
+ )
25
27
}
26
28
27
29
public readonly messages = TextDocumentPublishDecorationsNotification . type
@@ -31,24 +33,21 @@ export class TextDocumentDecorationFeature extends Feature<undefined> {
31
33
}
32
34
33
35
public initialize ( ) : void {
36
+ // TODO(sqs): no way to unregister this
34
37
this . client . onNotification ( TextDocumentPublishDecorationsNotification . type , params => {
35
38
this . getDecorationsSubject ( params . textDocument , params . decorations )
36
39
} )
37
40
}
38
41
39
- protected registerProvider ( ) : Unsubscribable {
40
- return this . registry . registerProvider (
41
- undefined ,
42
- ( textDocument : TextDocumentIdentifier ) : Observable < TextDocumentDecoration [ ] | null > =>
43
- this . getDecorationsSubject ( textDocument )
44
- )
42
+ public deinitialize ( ) : void {
43
+ // Clear decorations;
44
+ for ( const subject of Object . values ( this . decorations ) ) {
45
+ subject . next ( null )
46
+ }
45
47
}
46
48
47
- protected validateRegistrationOptions ( data : any ) : undefined {
48
- if ( data ) {
49
- throw new Error ( 'TextDocumentDecorationFeature registration options should be undefined' )
50
- }
51
- return data
49
+ protected validateRegistrationOptions ( _data : any ) : undefined {
50
+ return
52
51
}
53
52
54
53
private getDecorationsSubject (
0 commit comments