-
Notifications
You must be signed in to change notification settings - Fork 78
refactor: clean up #512
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: clean up #512
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,11 +43,11 @@ export default class LanguageServerController { | |
|
||
// The debug options for the server | ||
// --inspect=6009: runs the server in Node's Inspector mode | ||
// so VS Code can attach to the server for debugging | ||
// so VS Code can attach to the server for debugging. | ||
const debugOptions = { execArgv: ['--nolazy', '--inspect=6009'] }; | ||
|
||
// If the extension is launched in debug mode then the debug server options are used | ||
// Otherwise the run options are used | ||
// If the extension is launched in debug mode then the debug server options are used. | ||
// Otherwise the run options are used. | ||
const serverOptions: ServerOptions = { | ||
run: { module: serverModule, transport: TransportKind.ipc }, | ||
debug: { | ||
|
@@ -57,15 +57,15 @@ export default class LanguageServerController { | |
}, | ||
}; | ||
|
||
// Options to control the language client | ||
// Options to control the language client. | ||
const clientOptions: LanguageClientOptions = { | ||
// Register the server for mongodb documents | ||
// Register the language server for mongodb documents. | ||
documentSelector: [ | ||
{ scheme: 'untitled', language: 'javascript' }, | ||
{ scheme: 'file', language: 'javascript' }, | ||
{ pattern: '**/*.mongodb.js' }, | ||
{ pattern: '**/*.mongodb' }, | ||
], | ||
synchronize: { | ||
// Notify the server about file changes in the workspace | ||
// Notify the server about file changes in the workspace. | ||
fileEvents: workspace.createFileSystemWatcher('**/*'), | ||
}, | ||
outputChannel: vscode.window.createOutputChannel( | ||
|
@@ -78,7 +78,7 @@ export default class LanguageServerController { | |
clientOptions, | ||
}); | ||
|
||
// Create the language server client | ||
// Create the language server client. | ||
this._client = new LanguageClient( | ||
'mongodbLanguageServer', | ||
'MongoDB Language Server', | ||
|
@@ -88,6 +88,9 @@ export default class LanguageServerController { | |
} | ||
|
||
async startLanguageServer(): Promise<void> { | ||
// Start the client. This will also launch the server. | ||
await this._client.start(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I do not see a difference in behavior between having or skipping this step. But to be on the safer side let's have it as it is in vscode examples. |
||
|
||
// Push the disposable client to the context's subscriptions so that the | ||
// client can be deactivated on extension deactivation. | ||
if (!this._context.subscriptions.includes(this._client)) { | ||
|
@@ -115,9 +118,13 @@ export default class LanguageServerController { | |
); | ||
} | ||
|
||
deactivate(): void { | ||
// Stop the language server | ||
void this._client.stop(); | ||
deactivate(): Thenable<void> | undefined { | ||
if (!this._client) { | ||
return undefined; | ||
} | ||
|
||
// Stop the language server. | ||
return this._client.stop(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also aligement with vscode examples. |
||
} | ||
|
||
async evaluate( | ||
|
@@ -126,12 +133,12 @@ export default class LanguageServerController { | |
this._isExecutingInProgress = true; | ||
|
||
// Instantiate a new CancellationTokenSource object | ||
// that generates a cancellation token for each run of a playground | ||
// that generates a cancellation token for each run of a playground. | ||
this._source = new CancellationTokenSource(); | ||
|
||
// Send a request with a cancellation token | ||
// to the language server server to execute scripts from a playground | ||
// and return results to the playground controller when ready | ||
// to the language server instance to execute scripts from a playground | ||
// and return results to the playground controller when ready. | ||
const result: ShellEvaluateResult = await this._client.sendRequest( | ||
ServerCommands.EXECUTE_CODE_FROM_PLAYGROUND, | ||
playgroundExecuteParameters, | ||
|
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Register language server only for playgrounds.