some 💄 and a tricky todo

This commit is contained in:
Johannes Rieken
2021-04-22 19:28:31 +02:00
parent f68a7e7778
commit ab9a916272

View File

@@ -4,7 +4,7 @@
*--------------------------------------------------------------------------------------------*/
import { flatten, isNonEmptyArray } from 'vs/base/common/arrays';
import { runWhenIdle } from 'vs/base/common/async';
import { disposableTimeout } from 'vs/base/common/async';
import { Emitter, Event } from 'vs/base/common/event';
import { combinedDisposable, DisposableStore, IDisposable, MutableDisposable } from 'vs/base/common/lifecycle';
import { URI, UriComponents } from 'vs/base/common/uri';
@@ -191,21 +191,23 @@ export class MainThreadNotebookKernels implements MainThreadNotebookKernelsShape
}(data, this._modeService);
const registration = this._notebookKernelService.registerKernel(kernel);
let idleHandle = new MutableDisposable();
let timeoutHandle = new MutableDisposable();
const listener = this._notebookKernelService.onDidChangeNotebookKernelBinding(e => {
idleHandle.value = runWhenIdle(() => {
// todo@jrieken this is smelly... the onDidChangeNotebookKernelBinding event
// can happen in the same tick as notebook creation. We cannot send an IPC
// messages immediately because the ext host hasn't received the "new notebook"
// message yet. It requires some onWillAddNotebook or onDidCreateNotebook event
// to make sure that ext-host-sync'ing is first
timeoutHandle.value = disposableTimeout(() => {
if (e.oldKernel === kernel.id) {
this._proxy.$acceptSelection(handle, e.notebook, false);
} else if (e.newKernel === kernel.id) {
this._proxy.$acceptSelection(handle, e.notebook, true);
}
}, 100);
}, 0);
});
this._kernels.set(handle, [kernel, combinedDisposable(listener, registration, idleHandle)]);
this._kernels.set(handle, [kernel, combinedDisposable(listener, registration, timeoutHandle)]);
}
$updateKernel(handle: number, data: Partial<INotebookKernelDto2>): void {