-
Notifications
You must be signed in to change notification settings - Fork 62
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
chore: add language server logs VSCODE-447, VSCODE-448, VSCODE-449 #563
Changes from all commits
9df8e20
655f92a
e14f762
0d260a0
b37b3a9
2cee9e9
210c207
70d19fe
ad70d0c
597cdc7
8d01e04
bbfc900
0a1cd0c
9b93e49
ec9a236
3309922
c136bcb
541c290
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -152,7 +152,7 @@ export default class PlaygroundController { | |
this._connectionController.addEventListener( | ||
DataServiceEventTypes.ACTIVE_CONNECTION_CHANGED, | ||
() => { | ||
void this._connectToServiceProvider(); | ||
void this._activeConnectionChanged(); | ||
} | ||
); | ||
|
||
|
@@ -163,22 +163,26 @@ export default class PlaygroundController { | |
this._playgroundResultViewColumn = editor.viewColumn; | ||
this._playgroundResultTextDocument = editor?.document; | ||
} | ||
const isPlaygroundEditor = isPlayground(editor?.document.uri); | ||
|
||
void vscode.commands.executeCommand( | ||
'setContext', | ||
'mdb.isPlayground', | ||
isPlayground(editor?.document.uri) | ||
isPlaygroundEditor | ||
); | ||
|
||
if (editor?.document.languageId !== 'Log') { | ||
if (isPlaygroundEditor) { | ||
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. It might be that vscode chnages log names and we set logs as active playground editors. |
||
this._activeTextEditor = editor; | ||
this._activeConnectionCodeLensProvider.setActiveTextEditor( | ||
this._activeTextEditor | ||
); | ||
this._playgroundSelectedCodeActionProvider.setActiveTextEditor( | ||
this._activeTextEditor | ||
); | ||
log.info('Active editor path', editor?.document.uri?.path); | ||
log.info('Active editor', { | ||
documentPath: editor?.document.uri?.path, | ||
documentLanguageId: editor?.document.languageId, | ||
}); | ||
} | ||
}; | ||
|
||
|
@@ -245,35 +249,24 @@ export default class PlaygroundController { | |
); | ||
} | ||
|
||
async _connectToServiceProvider(): Promise<void> { | ||
// Disconnect if already connected. | ||
await this._languageServerController.disconnectFromServiceProvider(); | ||
|
||
async _activeConnectionChanged(): Promise<void> { | ||
const dataService = this._connectionController.getActiveDataService(); | ||
const connectionId = this._connectionController.getActiveConnectionId(); | ||
let mongoClientOption; | ||
|
||
if (!dataService || !connectionId) { | ||
this._activeConnectionCodeLensProvider.refresh(); | ||
|
||
return; | ||
} | ||
|
||
const mongoClientOption = | ||
this._connectionController.getMongoClientConnectionOptions(); | ||
|
||
if (!mongoClientOption) { | ||
this._activeConnectionCodeLensProvider.refresh(); | ||
this._activeConnectionCodeLensProvider.refresh(); | ||
|
||
return; | ||
if (dataService && connectionId) { | ||
mongoClientOption = | ||
this._connectionController.getMongoClientConnectionOptions(); | ||
} | ||
|
||
await this._languageServerController.connectToServiceProvider({ | ||
// The connectionId is null when disconnecting. | ||
await this._languageServerController.activeConnectionChanged({ | ||
connectionId, | ||
connectionString: mongoClientOption.url, | ||
connectionOptions: mongoClientOption.options, | ||
connectionString: mongoClientOption?.url, | ||
connectionOptions: mongoClientOption?.options, | ||
}); | ||
|
||
this._activeConnectionCodeLensProvider.refresh(); | ||
} | ||
|
||
async _createPlaygroundFileWithContent( | ||
|
@@ -420,36 +413,28 @@ export default class PlaygroundController { | |
|
||
this._statusView.showMessage('Getting results...'); | ||
|
||
let result: ShellEvaluateResult; | ||
try { | ||
// Send a request to the language server to execute scripts from a playground. | ||
const result: ShellEvaluateResult = | ||
await this._languageServerController.evaluate({ | ||
codeToEvaluate, | ||
connectionId, | ||
}); | ||
|
||
this._statusView.hideMessage(); | ||
this._telemetryService.trackPlaygroundCodeExecuted( | ||
result, | ||
this._isPartialRun, | ||
result ? false : true | ||
); | ||
|
||
return result; | ||
} catch (err: any) { | ||
// We re-initialize the language server when we encounter an error. | ||
// This happens when the language server worker runs out of memory, can't be revitalized, and restarts. | ||
if (err?.code === -32097) { | ||
Anemy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
void vscode.window.showErrorMessage( | ||
'An error occurred when running the playground. This can occur when the playground runner runs out of memory.' | ||
); | ||
result = await this._languageServerController.evaluate({ | ||
codeToEvaluate, | ||
connectionId, | ||
}); | ||
} catch (error) { | ||
const msg = | ||
'An internal error has occurred. The playground services have been restored. This can occur when the playground runner runs out of memory.'; | ||
log.error(msg, error); | ||
void vscode.window.showErrorMessage(msg); | ||
} | ||
|
||
await this._languageServerController.startLanguageServer(); | ||
void this._connectToServiceProvider(); | ||
} | ||
this._statusView.hideMessage(); | ||
this._telemetryService.trackPlaygroundCodeExecuted( | ||
result, | ||
this._isPartialRun, | ||
result ? false : true | ||
); | ||
|
||
throw err; | ||
} | ||
return result; | ||
} | ||
|
||
_getAllText(): string { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,10 +5,6 @@ import ConnectionController, { | |
} from '../connectionController'; | ||
import ExplorerTreeController from './explorerTreeController'; | ||
|
||
import { createLogger } from '../logging'; | ||
|
||
const log = createLogger('explorer controller'); | ||
|
||
export default class ExplorerController { | ||
private _connectionController: ConnectionController; | ||
private _treeController: ExplorerTreeController; | ||
|
@@ -38,14 +34,12 @@ export default class ExplorerController { | |
}; | ||
|
||
activateConnectionsTreeView(): void { | ||
log.info('Activating explorer controller...'); | ||
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. Such logs turned out to be distracting and not helpful for debugging, so removing them. |
||
// Listen for a change in connections to occur before we create the tree | ||
// so that we show the `viewsWelcome` before any connections are added. | ||
this._connectionController.addEventListener( | ||
DataServiceEventTypes.CONNECTIONS_DID_CHANGE, | ||
this.createTreeView | ||
); | ||
log.info('Explorer controller activated'); | ||
} | ||
|
||
deactivate(): void { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,8 @@ import * as vscode from 'vscode'; | |
import { ext } from './extensionConstants'; | ||
import { createKeytar } from './utils/keytar'; | ||
import { createLogger } from './logging'; | ||
// eslint-disable-next-line @typescript-eslint/no-var-requires | ||
const { version } = require('../package.json'); | ||
|
||
const log = createLogger('extension'); | ||
|
||
|
@@ -27,28 +29,50 @@ let mdbExtension: MDBExtensionController; | |
export async function activate( | ||
context: vscode.ExtensionContext | ||
): Promise<void> { | ||
log.info('Activating extension...'); | ||
ext.context = context; | ||
let hasKeytar = false; | ||
|
||
try { | ||
ext.keytarModule = createKeytar(); | ||
hasKeytar = true; | ||
} catch (err) { | ||
// Couldn't load keytar, proceed without storing & loading connections. | ||
} | ||
|
||
const defaultConnectionSavingLocation = vscode.workspace | ||
.getConfiguration('mdb.connectionSaving') | ||
.get('defaultConnectionSavingLocation'); | ||
|
||
log.info('Activating extension...', { | ||
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'm thinking a test for this log might be a very useful one for debugging the environment. Not needed for this pr if we don't want to put the time in now, just a thought. 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. What would you test here? Do we have tests for logs already somewhere in compass? |
||
id: context.extension.id, | ||
version: version, | ||
mode: vscode.ExtensionMode[context.extensionMode], | ||
kind: vscode.ExtensionKind[context.extension.extensionKind], | ||
extensionPath: context.extensionPath, | ||
logPath: context.logUri.path, | ||
workspaceStoragePath: context.storageUri?.path, | ||
globalStoragePath: context.globalStorageUri.path, | ||
defaultConnectionSavingLocation, | ||
hasKeytar, | ||
buildInfo: { | ||
nodeVersion: process.version, | ||
runtimePlatform: process.platform, | ||
runtimeArch: process.arch, | ||
}, | ||
}); | ||
alenakhineika marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
mdbExtension = new MDBExtensionController(context, { | ||
shouldTrackTelemetry: true, | ||
}); | ||
await mdbExtension.activate(); | ||
|
||
// Add our extension to a list of disposables for when we are deactivated. | ||
context.subscriptions.push(mdbExtension); | ||
|
||
log.info('Extension activated'); | ||
} | ||
|
||
// Called when our extension is deactivated. | ||
export async function deactivate(): Promise<void> { | ||
log.info('Deactivating extension...'); | ||
if (mdbExtension) { | ||
await mdbExtension.deactivate(); | ||
} | ||
|
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.
Adding the connection name as well might help debugging as it can be hard to infer which connection the connectionId belongs to.
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.
We don't pass the connection name anywhere outside the connection controller, not sure we can use it to match connectivity issues here and for example in LS. But I added a name to the explorer logs, so we can find the info what was expanded:
https://github.com/mongodb-js/vscode/pull/563/files#diff-06a415e2a54193ec0955688552bf1cb4813ac5868fc9392083f3c37f8f65a8c4R67-R69