Skip to content

Commit

Permalink
Display survey only when dealing with Jupyter Notebooks (#5248)
Browse files Browse the repository at this point in the history
  • Loading branch information
DonJayamanne authored Mar 23, 2021
1 parent 416f922 commit 94e89d2
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 5 deletions.
Empty file added news/2 Fixes/5181.md
Empty file.
11 changes: 10 additions & 1 deletion src/client/datascience/dataScienceSurveyBanner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import * as localize from '../common/utils/localize';
import { noop } from '../common/utils/misc';
import { MillisecondsInADay } from '../constants';
import { InteractiveWindowMessages, IReExecuteCells } from './interactive-common/interactiveWindowTypes';
import { isJupyterNotebook } from './notebook/helpers/helpers';
import { KernelState, KernelStateEventArgs } from './notebookExtensibility';
import { IInteractiveWindowListener, INotebookEditorProvider, INotebookExtensibility } from './types';

Expand Down Expand Up @@ -169,7 +170,15 @@ export class DataScienceSurveyBanner implements IJupyterExtensionBanner, IExtens
}

public async activate() {
this.vscodeNotebook.onDidOpenNotebookDocument(this.openedNotebook, this, this.disposables);
this.vscodeNotebook.onDidOpenNotebookDocument(
(e) => {
if (isJupyterNotebook(e)) {
this.openedNotebook().catch(noop);
}
},
this,
this.disposables
);
this.notebookExtensibility.onKernelStateChange(this.kernelStateChanged, this, this.disposables);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { IConfigurationService, IDisposableRegistry, Resource } from '../../comm
import { swallowExceptions } from '../../common/utils/decorators';
import { isUntitledFile } from '../../common/utils/misc';
import { isPythonKernelConnection } from '../jupyter/kernels/helpers';
import { getNotebookMetadata, isJupyterKernel, isPythonNotebook } from '../notebook/helpers/helpers';
import { getNotebookMetadata, isJupyterKernel, isJupyterNotebook, isPythonNotebook } from '../notebook/helpers/helpers';
import {
IInteractiveWindowProvider,
INotebookCreationTracker,
Expand Down Expand Up @@ -88,7 +88,7 @@ export class KernelDaemonPreWarmer {
// Handle opening of native documents
private async onDidOpenNotebookDocument(doc: NotebookDocument): Promise<void> {
// It could be anything, lets not make any assumptions.
if (isUntitledFile(doc.uri)) {
if (isUntitledFile(doc.uri) || !isJupyterNotebook(doc)) {
return;
}
const kernel = this.vscodeNotebook.notebookEditors.find((item) => item.document === doc)?.kernel;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { swallowExceptions } from '../../common/utils/decorators';
import { translateKernelLanguageToMonaco } from '../common';
import { getLanguageInNotebookMetadata } from '../jupyter/kernels/helpers';
import { IJupyterKernelSpec } from '../types';
import { getNotebookMetadata } from './helpers/helpers';
import { getNotebookMetadata, isJupyterNotebook } from './helpers/helpers';

export const LastSavedNotebookCellLanguage = 'DATASCIENCE.LAST_SAVED_CELL_LANGUAGE';
/**
Expand Down Expand Up @@ -54,6 +54,9 @@ export class NotebookCellLanguageService implements IExtensionSingleActivationSe
}
@swallowExceptions('Saving last saved cell language')
private async onDidSaveNotebookDocument(doc: NotebookDocument) {
if (!isJupyterNotebook(doc)) {
return;
}
const language = this.getLanguageOfFirstCodeCell(doc);
if (language && language !== this.lastSavedNotebookCellLanguage) {
await this.globalMemento.update(LastSavedNotebookCellLanguage, language);
Expand Down
4 changes: 4 additions & 0 deletions src/client/datascience/notebook/notebookEditorProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,10 @@ export class NotebookEditorProvider implements INotebookEditorProvider {
this._onDidChangeActiveNotebookEditor.fire(undefined);
return;
}
if (!isJupyterNotebook(editor.document)) {
this._onDidChangeActiveNotebookEditor.fire(undefined);
return;
}
if (this.trackedVSCodeNotebookEditors.has(editor)) {
const ourEditor = this.editors.find((item) => item.file.toString() === editor.document.uri.toString());
this._onDidChangeActiveNotebookEditor.fire(ourEditor);
Expand Down
3 changes: 2 additions & 1 deletion src/client/datascience/notebook/remoteSwitcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { noop } from '../../common/utils/misc';
import { Commands, Settings } from '../constants';
import { JupyterServerSelector } from '../jupyter/serverSelector';
import { IJupyterServerUriStorage } from '../types';
import { isJupyterNotebook } from './helpers/helpers';

@injectable()
export class RemoteSwitcher implements IExtensionSingleActivationService {
Expand Down Expand Up @@ -46,7 +47,7 @@ export class RemoteSwitcher implements IExtensionSingleActivationService {
await this.serverSelector.selectJupyterURI(true, 'nativeNotebookToolbar');
}
private async updateStatusBar() {
if (!this.notebook.activeNotebookEditor) {
if (!this.notebook.activeNotebookEditor || !isJupyterNotebook(this.notebook.activeNotebookEditor.document)) {
this.statusBarItem.hide();
return;
}
Expand Down

0 comments on commit 94e89d2

Please sign in to comment.