1
1
import * as vscode from 'vscode' ;
2
- import { EJSON } from 'bson' ;
3
2
import EXTENSION_COMMANDS from '../commands' ;
4
- import type { DocCodeLensesInfo } from '../utils/types' ;
5
- import type { OutputItem } from '../utils/types ' ;
3
+ import type { OutputItem , ResultCodeLensInfo } from '../utils/types' ;
4
+ import ConnectionController from '../connectionController ' ;
6
5
7
6
export default class EditDocumentCodeLensProvider
8
7
implements vscode . CodeLensProvider {
9
8
_onDidChangeCodeLenses : vscode . EventEmitter < void > = new vscode . EventEmitter < void > ( ) ;
10
9
_codeLenses : vscode . CodeLens [ ] = [ ] ;
11
- _codeLensesInfo : DocCodeLensesInfo ;
10
+ _codeLensesInfo : ResultCodeLensInfo [ ] ;
11
+ _connectionController : ConnectionController ;
12
12
13
13
readonly onDidChangeCodeLenses : vscode . Event < void > = this
14
14
. _onDidChangeCodeLenses . event ;
15
15
16
- constructor ( ) {
16
+ constructor ( connectionController : ConnectionController ) {
17
+ this . _connectionController = connectionController ;
17
18
this . _codeLensesInfo = [ ] ;
18
19
19
20
vscode . workspace . onDidChangeConfiguration ( ( ) => {
@@ -22,16 +23,15 @@ implements vscode.CodeLensProvider {
22
23
}
23
24
24
25
updateCodeLensesPosition ( playgroundResult : OutputItem ) : void {
25
- if ( ! playgroundResult ) {
26
+ if ( ! playgroundResult || ! playgroundResult . content ) {
26
27
this . _codeLensesInfo = [ ] ;
27
28
28
29
return ;
29
30
}
30
31
31
- const content = playgroundResult . content ;
32
- const namespace = playgroundResult . namespace ;
33
- const type = playgroundResult . type ;
34
- const codeLensesInfo : DocCodeLensesInfo = [ ] ;
32
+ const { content, namespace, type } = playgroundResult ;
33
+ const connectionId = this . _connectionController . getActiveConnectionId ( ) ;
34
+ const codeLensesInfo : ResultCodeLensInfo [ ] = [ ] ;
35
35
36
36
// Show code lenses only for the list of documents or a single document
37
37
// that are returned by the find() method.
@@ -44,7 +44,12 @@ implements vscode.CodeLensProvider {
44
44
// We need _id and namespace for code lenses
45
45
// to be able to save the editable document.
46
46
if ( item !== null && item . _id && namespace ) {
47
- codeLensesInfo . push ( { line, documentId : item . _id , namespace } ) ;
47
+ codeLensesInfo . push ( {
48
+ line,
49
+ documentId : item . _id ,
50
+ namespace,
51
+ connectionId
52
+ } ) ;
48
53
// To calculate the position of the next open curly bracket,
49
54
// we stringify the object and use a regular expression
50
55
// so we can count the number of lines.
@@ -54,7 +59,12 @@ implements vscode.CodeLensProvider {
54
59
} else if ( type === 'Document' && content . _id && namespace ) {
55
60
// When the playground result is the single document,
56
61
// show the single code lense after {.
57
- codeLensesInfo . push ( { line : 1 , documentId : content . _id , namespace } ) ;
62
+ codeLensesInfo . push ( {
63
+ line : 1 ,
64
+ documentId : content . _id ,
65
+ namespace,
66
+ connectionId
67
+ } ) ;
58
68
}
59
69
60
70
this . _codeLensesInfo = codeLensesInfo ;
@@ -71,16 +81,11 @@ implements vscode.CodeLensProvider {
71
81
const command : {
72
82
title : string ;
73
83
command : EXTENSION_COMMANDS ;
74
- arguments : {
75
- documentId : EJSON . SerializableTypes ;
76
- namespace : string ;
77
- } [ ] ;
84
+ arguments : ResultCodeLensInfo [ ] ;
78
85
} = {
79
86
title : 'Edit Document' ,
80
87
command : EXTENSION_COMMANDS . MDB_OPEN_MONGODB_DOCUMENT_FROM_PLAYGROUND ,
81
- arguments : [
82
- { documentId : item . documentId , namespace : item . namespace }
83
- ]
88
+ arguments : [ item ]
84
89
} ;
85
90
86
91
this . _codeLenses . push ( new vscode . CodeLens ( range , command ) ) ;
0 commit comments