Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 12 additions & 13 deletions src/client/datascience/jupyter/liveshare/serverCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,24 @@ import { IAsyncDisposable, IConfigurationService } from '../../../common/types';
import { INotebookServer, INotebookServerOptions } from '../../types';

export class ServerCache implements IAsyncDisposable {
private cache : Map<string, INotebookServer> = new Map<string, INotebookServer>();
private cache: Map<string, INotebookServer> = new Map<string, INotebookServer>();
private emptyKey = uuid();

constructor(
private configService: IConfigurationService,
private workspace: IWorkspaceService,
private fileSystem: IFileSystem
) {}
) { }

public async get(options?: INotebookServerOptions) : Promise<INotebookServer | undefined> {
public async get(options?: INotebookServerOptions): Promise<INotebookServer | undefined> {
const fixedOptions = await this.generateDefaultOptions(options);
const key = this.generateKey(fixedOptions);
if (this.cache.has(key)) {
return this.cache.get(key);
}
}

public async set(result: INotebookServer, disposeCallback: () => void, options?: INotebookServerOptions) : Promise<void> {
public async set(result: INotebookServer, disposeCallback: () => void, options?: INotebookServerOptions): Promise<void> {
const fixedOptions = await this.generateDefaultOptions(options);
const key = this.generateKey(fixedOptions);

Expand All @@ -52,25 +52,24 @@ export class ServerCache implements IAsyncDisposable {
};
}

public async dispose() : Promise<void> {
// tslint:disable-next-line:no-unused-variable
for (const [k, s] of this.cache) {
public async dispose(): Promise<void> {
for (const [, s] of this.cache) {
await s.dispose();
}
this.cache.clear();
}

public async generateDefaultOptions(options? : INotebookServerOptions) : Promise<INotebookServerOptions> {
public async generateDefaultOptions(options?: INotebookServerOptions): Promise<INotebookServerOptions> {
return {
uri: options ? options.uri : undefined,
useDefaultConfig : options ? options.useDefaultConfig : true, // Default for this is true.
usingDarkTheme : options ? options.usingDarkTheme : undefined,
purpose : options ? options.purpose : uuid(),
workingDir : options && options.workingDir ? options.workingDir : await this.calculateWorkingDirectory()
useDefaultConfig: options ? options.useDefaultConfig : true, // Default for this is true.
usingDarkTheme: options ? options.usingDarkTheme : undefined,
purpose: options ? options.purpose : uuid(),
workingDir: options && options.workingDir ? options.workingDir : await this.calculateWorkingDirectory()
};
}

private generateKey(options?: INotebookServerOptions) : string {
private generateKey(options?: INotebookServerOptions): string {
if (!options) {
return this.emptyKey;
} else {
Expand Down
36 changes: 18 additions & 18 deletions src/client/datascience/liveshare/postOffice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ interface IMessageArgs {
export class PostOffice implements IAsyncDisposable {

private name: string;
private started : Promise<vsls.LiveShare | null>;
private hostServer : vsls.SharedService | null = null;
private guestServer : vsls.SharedServiceProxy | null = null;
private currentRole : vsls.Role = vsls.Role.None;
private started: Promise<vsls.LiveShare | null>;
private hostServer: vsls.SharedService | null = null;
private guestServer: vsls.SharedServiceProxy | null = null;
private currentRole: vsls.Role = vsls.Role.None;
private currentPeerCount: number = 0;
private peerCountChangedEmitter : vscode.EventEmitter<number> = new vscode.EventEmitter<number>();
private commandMap : { [key: string] : { thisArg: any; callback(...args: any[]) : void } } = {};
private peerCountChangedEmitter: vscode.EventEmitter<number> = new vscode.EventEmitter<number>();
private commandMap: { [key: string]: { thisArg: any; callback(...args: any[]): void } } = {};

constructor(
name: string,
Expand All @@ -41,7 +41,7 @@ export class PostOffice implements IAsyncDisposable {
return this.currentPeerCount;
}

public get peerCountChanged() : vscode.Event<number> {
public get peerCountChanged(): vscode.Event<number> {
return this.peerCountChangedEmitter.event;
}

Expand All @@ -57,7 +57,7 @@ export class PostOffice implements IAsyncDisposable {
this.guestServer = null;
}

public async postCommand(command: string, ...args: any[]) : Promise<void> {
public async postCommand(command: string, ...args: any[]): Promise<void> {
// Make sure startup finished
const api = await this.started;
let skipDefault = false;
Expand Down Expand Up @@ -88,7 +88,7 @@ export class PostOffice implements IAsyncDisposable {
}
}

public async registerCallback(command: string, callback: (...args: any[]) => void, thisArg?: any) : Promise<void> {
public async registerCallback(command: string, callback: (...args: any[]) => void, thisArg?: any): Promise<void> {
const api = await this.started;

// For a guest, make sure to register the notification
Expand All @@ -100,11 +100,11 @@ export class PostOffice implements IAsyncDisposable {
this.commandMap[command] = { callback, thisArg };
}

private createBroadcastArgs(command: string, ...args: any[]) : IMessageArgs {
private createBroadcastArgs(command: string, ...args: any[]): IMessageArgs {
return { args: JSON.stringify([command, ...args]) };
}

private translateArgs(api: vsls.LiveShare, command: string, ...args: any[]) : IMessageArgs {
private translateArgs(api: vsls.LiveShare, command: string, ...args: any[]): IMessageArgs {
// Make sure to eliminate all .toJSON functions on our arguments. Otherwise they're stringified incorrectly
for (let a = 0; a <= args.length; a += 1) {
// Eliminate this on only object types (https://stackoverflow.com/questions/8511281/check-if-a-value-is-an-object-in-javascript)
Expand All @@ -130,12 +130,12 @@ export class PostOffice implements IAsyncDisposable {
return { args: JSON.stringify(copyArgs) };
}

private escapeCommandName(command: string) : string {
private escapeCommandName(command: string): string {
// Replace . with $ instead.
return command.replace(/\./g, '$');
}

private unescapeCommandName(command: string) : string {
private unescapeCommandName(command: string): string {
// Turn $ back into .
return command.replace(/\$/g, '.');
}
Expand All @@ -153,7 +153,7 @@ export class PostOffice implements IAsyncDisposable {
}
}

private getCallback(command: string) : ((...args: any[]) => void) | undefined {
private getCallback(command: string): ((...args: any[]) => void) | undefined {
let callback = this.commandMap.hasOwnProperty(command) ? this.commandMap[command].callback : undefined;
if (callback) {
// Bind the this arg if necessary
Expand All @@ -166,7 +166,7 @@ export class PostOffice implements IAsyncDisposable {
return callback;
}

private async startCommandServer() : Promise<vsls.LiveShare | null> {
private async startCommandServer(): Promise<vsls.LiveShare | null> {
const api = await this.liveShareApi.getApi();
if (api !== null) {
api.onDidChangeSession(() => this.onChangeSession(api).ignoreErrors());
Expand All @@ -177,7 +177,7 @@ export class PostOffice implements IAsyncDisposable {
return api;
}

private async onChangeSession(api: vsls.LiveShare) : Promise<void> {
private async onChangeSession(api: vsls.LiveShare): Promise<void> {
// Startup or shutdown our connection to the other side
if (api.session) {
if (this.currentRole !== api.session.role) {
Expand Down Expand Up @@ -209,7 +209,7 @@ export class PostOffice implements IAsyncDisposable {
}
}

private async onChangePeers(api: vsls.LiveShare) : Promise<void> {
private async onChangePeers(api: vsls.LiveShare): Promise<void> {
let newPeerCount = 0;
if (api.session) {
newPeerCount = api.peers.length;
Expand All @@ -226,7 +226,7 @@ export class PostOffice implements IAsyncDisposable {
if (a.args.length > 0) {
const jsonArray = JSON.parse(a.args) as JSONArray;
if (jsonArray !== null && jsonArray.length >= 2) {
const firstArg = jsonArray[0]; // More stupid hygiene problems.
const firstArg = jsonArray[0]!; // More stupid hygiene problems.
const command = firstArg !== null ? firstArg.toString() : '';

// Args need to be translated from guest to host
Expand Down
4 changes: 2 additions & 2 deletions src/client/providers/jediProxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { IS_WINDOWS } from '../common/platform/constants';
import { IPythonExecutionFactory } from '../common/process/types';
import { BANNER_NAME_PROPOSE_LS, IConfigurationService, ILogger, IPythonExtensionBanner, IPythonSettings } from '../common/types';
import { createDeferred, Deferred } from '../common/utils/async';
import { debounce, swallowExceptions } from '../common/utils/decorators';
import { swallowExceptions } from '../common/utils/decorators';
import { StopWatch } from '../common/utils/stopWatch';
import { IEnvironmentVariablesProvider } from '../common/variables/types';
import { IInterpreterService } from '../interpreter/contracts';
Expand Down Expand Up @@ -296,7 +296,7 @@ export class JediProxy implements Disposable {
this.additionalAutoCompletePaths = await this.buildAutoCompletePaths();
this.restartLanguageServer().ignoreErrors();
}
@debounce(1500)
// @debounce(1500)
@swallowExceptions('JediProxy')
private async environmentVariablesChangeHandler() {
const newAutoComletePaths = await this.buildAutoCompletePaths();
Expand Down
6 changes: 3 additions & 3 deletions src/client/unittests/pytest/services/testMessageService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,13 +246,13 @@ export class TestMessageService implements ITestMessageService {
}
// Found the line to process.
parentScopeStartIndex = suiteDefLineIndex;
parentIndentation = indentation;
parentIndentation = indentation!;

// Invert the index to get the unreversed equivalent.
const realIndex = (reversedTestFileLines.length - 1) - suiteDefLineIndex;
const startChar = indentation + classPrefix.length;
const startChar = indentation! + classPrefix.length;
const suiteStartPos = new Position(realIndex, startChar);
const suiteEndPos = new Position(realIndex, (startChar + suiteName.length));
const suiteEndPos = new Position(realIndex, (startChar + suiteName!.length));
const suiteRange = new Range(suiteStartPos, suiteEndPos);
const suiteLocation = new Location(testFileUri, suiteRange);
suiteLocationStackFrameDetails.push({ location: suiteLocation, lineText: testFile.getText(suiteRange) });
Expand Down
2 changes: 1 addition & 1 deletion src/test/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

// tslint:disable:no-console no-require-imports no-var-requires

import * as arch from 'arch';
import * as assert from 'assert';
import * as fs from 'fs-extra';
import * as glob from 'glob';
Expand Down Expand Up @@ -32,6 +31,7 @@ export const rootWorkspaceUri = getWorkspaceRoot();

export const PYTHON_PATH = getPythonPath();

const arch = require('arch');
export const IS_64_BIT = arch() === 'x64';

export enum OSType {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ suite('Module Installer - Invalid Paths', () => {
persistValue.setup(pv => pv.value).returns(() => false);
persistValue.setup(pv => pv.updateValue(TypeMoq.It.isValue(true)));
persistentState.setup(ps =>
ps.createGlobalPersistentState(TypeMoq.It.isAnyString(), TypeMoq.It.isValue(undefined))
ps.createGlobalPersistentState<boolean>(TypeMoq.It.isAnyString(), TypeMoq.It.isValue(undefined))
).returns(() => persistValue.object);
await installer.promptToInstall(product.value, resource);
productPathService.verifyAll();
Expand Down
2 changes: 1 addition & 1 deletion src/test/common/platform/platformService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ suite('PlatformService', () => {

test('is64bit', async () => {
// tslint:disable-next-line:no-require-imports
const arch = require('arch') as typeof import('arch');
const arch = require('arch');

const hostReports64Bit = arch() === 'x64';
const svc = new PlatformService();
Expand Down
3 changes: 3 additions & 0 deletions src/test/common/variables/envVarsProvider.multiroot.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,10 @@ suite('Multiroot Environment Variables Provider', () => {
expect(newVars).to.not.to.have.property('PYTHONPATH', '../workspace5', 'PYTHONPATH value is invalid');
});

// Check https://github.com/Microsoft/vscode-python/issues/4067
test('Custom variables will be refreshed when .env file is created, modified and deleted', async function () {
// tslint:disable-next-line:no-invalid-this
return this.skip();
// tslint:disable-next-line:no-invalid-this
this.timeout(20000);
const env3 = path.join(workspace4Path.fsPath, '.env3');
Expand Down
15 changes: 6 additions & 9 deletions src/test/datascience/notebook.functional.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import { JupyterExecutionFactory } from '../../client/datascience/jupyter/jupyte
import { IRoleBasedObject, RoleBasedFactory } from '../../client/datascience/jupyter/liveshare/roleBasedFactory';
import {
CellState,
ICell,
IConnection,
IJupyterExecution,
IJupyterKernelSpec,
Expand Down Expand Up @@ -207,7 +206,7 @@ suite('Jupyter notebook tests', () => {
// Catch exceptions. Throw a specific assertion if the promise fails
try {
const testDir = path.join(EXTENSION_ROOT_DIR, 'src', 'test', 'datascience');
const server = await jupyterExecution.connectToNotebookServer({ usingDarkTheme, useDefaultConfig, workingDir: testDir, purpose: purpose ? purpose : '1'});
const server = await jupyterExecution.connectToNotebookServer({ usingDarkTheme, useDefaultConfig, workingDir: testDir, purpose: purpose ? purpose : '1' });
if (expectFailure) {
assert.ok(false, `Expected server to not be created`);
}
Expand Down Expand Up @@ -255,7 +254,7 @@ suite('Jupyter notebook tests', () => {
const uri = connString as string;

// We have a connection string here, so try to connect jupyterExecution to the notebook server
const server = await jupyterExecution.connectToNotebookServer({ uri, useDefaultConfig: true, purpose: ''});
const server = await jupyterExecution.connectToNotebookServer({ uri, useDefaultConfig: true, purpose: '' });
if (!server) {
assert.fail('Failed to connect to remote server');
}
Expand Down Expand Up @@ -492,9 +491,7 @@ suite('Jupyter notebook tests', () => {
const finishedPromise = createDeferred();
let error;
const observable = server!.executeObservable(code, 'foo.py', 0, uuid(), false);
let cells: ICell[] = [];
observable.subscribe(c => {
cells = c;
if (c.length > 0 && c[0].state === CellState.error) {
finishedBefore = !interrupted;
finishedPromise.resolve();
Expand Down Expand Up @@ -590,17 +587,17 @@ while keep_going:
await sleep(100);

// Try with something we can interrupt
let interruptResult = await interruptExecute(server, returnable, 1000, 1000);
await interruptExecute(server, returnable, 1000, 1000);

// Try again with something that doesn't return. However it should finish before
// we get to our own sleep. Note: We need the print so that the test knows something happened.
interruptResult = await interruptExecute(server, fourSecondSleep, 7000, 7000);
await interruptExecute(server, fourSecondSleep, 7000, 7000);

// Try again with something that doesn't return. Make sure it times out
interruptResult = await interruptExecute(server, fourSecondSleep, 100, 7000);
await interruptExecute(server, fourSecondSleep, 100, 7000);

// The tough one, somethign that causes a kernel reset.
interruptResult = await interruptExecute(server, kill, 1000, 1000);
await interruptExecute(server, kill, 1000, 1000);
});

testMimeTypes(
Expand Down
2 changes: 1 addition & 1 deletion src/test/linters/lint.args.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ suite('Linting - Arguments', () => {
document.setup(d => d.uri).returns(() => fileUri);

let invoked = false;
(linter as any).run = (args, doc, token) => {
(linter as any).run = (args: any[], doc: any, token: any) => {
expect(args[args.length - 1]).to.equal(fileUri.fsPath);
invoked = true;
return Promise.resolve([]);
Expand Down
2 changes: 1 addition & 1 deletion src/test/linters/lint.multiroot.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ suite('Multiroot Linting', () => {
const errorMessage = mustHaveErrors ? 'No errors returned by linter' : 'Errors returned by linter';
assert.equal(messages.length > 0, mustHaveErrors, errorMessage);
}
async function enableDisableSetting(workspaceFolder, configTarget: ConfigurationTarget, setting: string, value: boolean): Promise<void> {
async function enableDisableSetting(workspaceFolder: string, configTarget: ConfigurationTarget, setting: string, value: boolean): Promise<void> {
const config = ioc.serviceContainer.get<IConfigurationService>(IConfigurationService);
await config.updateSetting(setting, value, Uri.file(workspaceFolder), configTarget);
}
Expand Down
Loading