@@ -13,6 +13,7 @@ import {
1313import { TextDocument } from 'vscode-languageserver-textdocument' ;
1414
1515import MongoDBService from './mongoDBService' ;
16+
1617import { ServerCommands } from './serverCommands' ;
1718import {
1819 PlaygroundEvaluateParams ,
@@ -27,7 +28,7 @@ const connection: Connection = createConnection(ProposedFeatures.all);
2728// The text document manager supports full document sync only.
2829const documents : TextDocuments < TextDocument > = new TextDocuments ( TextDocument ) ;
2930
30- // MongoDB Playground Service Manager .
31+ // MongoDB language service .
3132const mongoDBService = new MongoDBService ( connection ) ;
3233
3334let hasConfigurationCapability = false ;
@@ -61,7 +62,7 @@ connection.onInitialize((params: InitializeParams) => {
6162 } ,
6263 } ,
6364 } ,
64- // Tell the client that the server supports code completion
65+ // Tell the client that the server supports code completion.
6566 completionProvider : {
6667 resolveProvider : true ,
6768 triggerCharacters : [ '.' ] ,
@@ -91,7 +92,7 @@ connection.onInitialized(() => {
9192 // }
9293} ) ;
9394
94- // The example settings
95+ // The example settings.
9596interface ExampleSettings {
9697 maxNumberOfProblems : number ;
9798}
@@ -118,8 +119,6 @@ connection.onDidChangeConfiguration((/* change */) => {
118119
119120// Only keep settings for open documents.
120121documents . onDidClose ( ( e ) => {
121- // connection.console.log(`documents.onDidClose: ${JSON.stringify(e)}`);
122-
123122 documentSettings . delete ( e . document . uri ) ;
124123} ) ;
125124
@@ -152,19 +151,21 @@ connection.onDidChangeWatchedFiles((/* _change */) => {
152151 // );
153152} ) ;
154153
155- // Execute the entire playground script .
154+ // Execute a playground.
156155connection . onRequest (
157156 ServerCommands . EXECUTE_CODE_FROM_PLAYGROUND ,
158157 ( evaluateParams : PlaygroundEvaluateParams , token ) => {
159158 return mongoDBService . evaluate ( evaluateParams , token ) ;
160159 }
161160) ;
162161
162+ // Pass the extension path to the MongoDB service.
163163connection . onRequest ( ServerCommands . SET_EXTENSION_PATH , ( extensionPath ) => {
164- return mongoDBService . setExtensionPath ( extensionPath ) ;
164+ mongoDBService . setExtensionPath ( extensionPath ) ;
165165} ) ;
166166
167- // Connect to CliServiceProvider to enable shell completions.
167+ // Connect the MongoDB language service to CliServiceProvider
168+ // using the current connection of the client.
168169connection . onRequest ( ServerCommands . CONNECT_TO_SERVICE_PROVIDER , ( params ) => {
169170 return mongoDBService . connectToServiceProvider ( params ) ;
170171} ) ;
@@ -183,21 +184,23 @@ connection.onRequest(
183184 }
184185) ;
185186
187+ // Identify if the playground selection is an array or object.
186188connection . onRequest (
187189 ServerCommands . GET_EXPORT_TO_LANGUAGE_MODE ,
188190 ( params : PlaygroundTextAndSelection ) => {
189191 return mongoDBService . getExportToLanguageMode ( params ) ;
190192 }
191193) ;
192194
195+ // Find the current namespace for a playground selection.
193196connection . onRequest (
194197 ServerCommands . GET_NAMESPACE_FOR_SELECTION ,
195198 ( params : PlaygroundTextAndSelection ) => {
196199 return mongoDBService . getNamespaceForSelection ( params ) ;
197200 }
198201) ;
199202
200- // This handler provides the list of the completion items.
203+ // Provide MongoDB completion items.
201204connection . onCompletion ( ( params : TextDocumentPositionParams ) => {
202205 const textFromEditor = documents . get ( params . textDocument . uri ) ?. getText ( ) ;
203206
@@ -258,6 +261,7 @@ connection.onDidOpenTextDocument((/* params */) => {
258261 // params.textDocument.text the initial full content of the document.
259262 // connection.console.log(`${params.textDocument.uri} opened.`);
260263} ) ;
264+
261265connection . onDidChangeTextDocument ( ( /* params */ ) => {
262266 // The content of a text document did change in VSCode.
263267 // params.textDocument.uri uniquely identifies the document.
@@ -268,6 +272,7 @@ connection.onDidChangeTextDocument((/* params */) => {
268272 // )}`
269273 // );
270274} ) ;
275+
271276connection . onDidCloseTextDocument ( ( /* params */ ) => {
272277 // A text document got closed in VSCode.
273278 // params.textDocument.uri uniquely identifies the document.
0 commit comments