Skip to content

Commit 1470e8a

Browse files
committed
fix #542
1 parent 27ce816 commit 1470e8a

21 files changed

+61
-42
lines changed

src/client/common/configSettings.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -106,25 +106,26 @@ export interface JupyterSettings {
106106

107107
const IS_TEST_EXECUTION = process.env['PYTHON_DONJAYAMANNE_TEST'] === '1';
108108

109-
const systemVariables: SystemVariables = new SystemVariables();
110109
export class PythonSettings extends EventEmitter implements IPythonSettings {
111110
private static pythonSettings: PythonSettings = new PythonSettings();
111+
private disposables: vscode.Disposable[] = [];
112112
constructor() {
113113
super();
114114
if (PythonSettings.pythonSettings) {
115115
throw new Error('Singleton class, Use getInstance method');
116116
}
117-
vscode.workspace.onDidChangeConfiguration(() => {
117+
this.disposables.push(vscode.workspace.onDidChangeConfiguration(() => {
118118
this.initializeSettings();
119-
});
120-
119+
}));
120+
121121
this.initializeSettings();
122122
}
123123
public static getInstance(): PythonSettings {
124124
return PythonSettings.pythonSettings;
125125
}
126126
private initializeSettings() {
127-
const workspaceRoot = IS_TEST_EXECUTION ? __dirname : vscode.workspace.rootPath;
127+
const systemVariables: SystemVariables = new SystemVariables();
128+
const workspaceRoot = (IS_TEST_EXECUTION || typeof vscode.workspace.rootPath !== 'string') ? __dirname : vscode.workspace.rootPath;
128129
let pythonSettings = vscode.workspace.getConfiguration('python');
129130
this.pythonPath = systemVariables.resolveAny(pythonSettings.get<string>('pythonPath'));
130131
this.pythonPath = getAbsolutePath(this.pythonPath, IS_TEST_EXECUTION ? __dirname : workspaceRoot);
@@ -225,7 +226,7 @@ export class PythonSettings extends EventEmitter implements IPythonSettings {
225226
exclusionPatterns: [],
226227
rebuildOnFileSave: true,
227228
rebuildOnStart: true,
228-
tagFilePath: path.join(vscode.workspace.rootPath, "tags")
229+
tagFilePath: path.join(workspaceRoot, "tags")
229230
};
230231

231232
let unitTestSettings = systemVariables.resolveAny(pythonSettings.get<IUnitTestSettings>('unitTest'));
@@ -238,7 +239,6 @@ export class PythonSettings extends EventEmitter implements IPythonSettings {
238239
this.unitTest = { nosetestArgs: [], pyTestArgs: [], unittestArgs: [] } as IUnitTestSettings;
239240
}
240241
}
241-
this.emit('change');
242242

243243
// Support for travis
244244
this.unitTest = this.unitTest ? this.unitTest : {
@@ -278,6 +278,8 @@ export class PythonSettings extends EventEmitter implements IPythonSettings {
278278
this.jupyter = this.jupyter ? this.jupyter : {
279279
appendResults: true, defaultKernel: '', startupCode: []
280280
};
281+
282+
this.emit('change');
281283
}
282284

283285
public pythonPath: string;

src/client/common/systemVariables.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ export class SystemVariables extends AbstractSystemVariables {
137137

138138
constructor() {
139139
super();
140-
this._workspaceRoot = vscode.workspace.rootPath;
140+
this._workspaceRoot = typeof vscode.workspace.rootPath === 'string' ? vscode.workspace.rootPath : __dirname;;
141141
this._workspaceRootFolderName = Path.basename(this._workspaceRoot);
142142
Object.keys(process.env).forEach(key => {
143143
this[`env.${key}`] = process.env[key];

src/client/extension.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export function activate(context: vscode.ExtensionContext) {
5555
context.subscriptions.push(...activateExecInTerminalProvider());
5656
context.subscriptions.push(activateUpdateSparkLibraryProvider());
5757
activateSimplePythonRefactorProvider(context, formatOutChannel);
58-
context.subscriptions.push(activateFormatOnSaveProvider(PYTHON, settings.PythonSettings.getInstance(), formatOutChannel, vscode.workspace.rootPath));
58+
context.subscriptions.push(activateFormatOnSaveProvider(PYTHON, settings.PythonSettings.getInstance(), formatOutChannel));
5959

6060
// Enable indentAction
6161
vscode.languages.setLanguageConfiguration(PYTHON.language, {
@@ -84,17 +84,17 @@ export function activate(context: vscode.ExtensionContext) {
8484
if (pythonSettings.devOptions.indexOf('DISABLE_SIGNATURE') === -1) {
8585
context.subscriptions.push(vscode.languages.registerSignatureHelpProvider(PYTHON, new PythonSignatureProvider(context, jediProx), '(', ','));
8686
}
87-
const formatProvider = new PythonFormattingEditProvider(context, formatOutChannel, pythonSettings, vscode.workspace.rootPath);
87+
const formatProvider = new PythonFormattingEditProvider(context, formatOutChannel, pythonSettings);
8888
context.subscriptions.push(vscode.languages.registerDocumentFormattingEditProvider(PYTHON, formatProvider));
8989
context.subscriptions.push(vscode.languages.registerDocumentRangeFormattingEditProvider(PYTHON, formatProvider));
9090

9191

92-
jupMain = new jup.Jupyter(lintingOutChannel, vscode.workspace.rootPath);
92+
jupMain = new jup.Jupyter(lintingOutChannel);
9393
const documentHasJupyterCodeCells = jupMain.hasCodeCells.bind(jupMain);
9494
jupMain.activate();
9595
context.subscriptions.push(jupMain);
9696

97-
context.subscriptions.push(new LintProvider(context, lintingOutChannel, vscode.workspace.rootPath, documentHasJupyterCodeCells));
97+
context.subscriptions.push(new LintProvider(context, lintingOutChannel, documentHasJupyterCodeCells));
9898
tests.activate(context, unitTestOutChannel);
9999

100100
context.subscriptions.push(new WorkspaceSymbols(lintingOutChannel));

src/client/formatters/autoPep8Formatter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import * as settings from '../common/configSettings';
66
import { Product } from '../common/installer';
77

88
export class AutoPep8Formatter extends BaseFormatter {
9-
constructor(protected outputChannel: vscode.OutputChannel, protected pythonSettings: settings.IPythonSettings, protected workspaceRootPath: string) {
9+
constructor(outputChannel: vscode.OutputChannel, pythonSettings: settings.IPythonSettings, workspaceRootPath?: string) {
1010
super('autopep8', Product.autopep8, outputChannel, pythonSettings, workspaceRootPath);
1111
}
1212

src/client/formatters/baseFormatter.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { Installer, Product } from '../common/installer';
1010

1111
export abstract class BaseFormatter {
1212
private installer: Installer;
13-
constructor(public Id: string, private product: Product, protected outputChannel: vscode.OutputChannel, protected pythonSettings: settings.IPythonSettings, protected workspaceRootPath: string) {
13+
constructor(public Id: string, private product: Product, protected outputChannel: vscode.OutputChannel, protected pythonSettings: settings.IPythonSettings, protected workspaceRootPath?: string) {
1414
this.installer = new Installer();
1515
}
1616

@@ -29,7 +29,8 @@ export abstract class BaseFormatter {
2929
if (token && token.isCancellationRequested) {
3030
return [filePath, ''];
3131
}
32-
return Promise.all<string>([Promise.resolve(filePath), execPythonFile(command, args.concat([filePath]), this.workspaceRootPath)]);
32+
const workspaceRoot = this.workspaceRootPath ? this.workspaceRootPath : vscode.workspace.rootPath;
33+
return Promise.all<string>([Promise.resolve(filePath), execPythonFile(command, args.concat([filePath]), workspaceRoot)]);
3334
}).then(data => {
3435
// Delete the temporary file created
3536
if (tmpFileCreated) {

src/client/formatters/yapfFormatter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import * as settings from './../common/configSettings';
66
import { Product } from '../common/installer';
77

88
export class YapfFormatter extends BaseFormatter {
9-
constructor(protected outputChannel: vscode.OutputChannel, protected pythonSettings: settings.IPythonSettings, protected workspaceRootPath: string) {
9+
constructor(outputChannel: vscode.OutputChannel, pythonSettings: settings.IPythonSettings, workspaceRootPath?: string) {
1010
super('yapf', Product.yapf, outputChannel, pythonSettings, workspaceRootPath);
1111
}
1212

src/client/jupyter/main.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export class Jupyter extends vscode.Disposable {
2828
private codeLensProvider: JupyterCodeLensProvider;
2929
private lastUsedPythonPath: string;
3030
private codeHelper: CodeHelper;
31-
constructor(private outputChannel: vscode.OutputChannel, private rootPath: string) {
31+
constructor(private outputChannel: vscode.OutputChannel) {
3232
super(() => { });
3333
this.disposables = [];
3434
this.registerCommands();
@@ -49,7 +49,7 @@ export class Jupyter extends vscode.Disposable {
4949
this.disposables.forEach(d => d.dispose());
5050
}
5151
private createKernelManager() {
52-
const jupyterClient = new main.JupyterClientAdapter(this.outputChannel, this.rootPath);
52+
const jupyterClient = new main.JupyterClientAdapter(this.outputChannel, vscode.workspace.rootPath);
5353
this.kernelManager = new KernelManagerImpl(this.outputChannel, jupyterClient);
5454

5555
// This happend when user changes it from status bar

src/client/linters/baseLinter.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,14 @@ export abstract class BaseLinter {
5252
public Id: string;
5353
private installer: Installer;
5454
protected pythonSettings: settings.IPythonSettings;
55-
constructor(id: string, private product: Product, protected outputChannel: OutputChannel, protected workspaceRootPath: string) {
55+
private _workspaceRootPath: string;
56+
protected get workspaceRootPath(): string {
57+
return typeof this._workspaceRootPath === 'string' ? this._workspaceRootPath : vscode.workspace.rootPath;
58+
}
59+
constructor(id: string, private product: Product, protected outputChannel: OutputChannel, workspaceRootPath: string) {
5660
this.Id = id;
5761
this.installer = new Installer();
62+
this._workspaceRootPath = workspaceRootPath;
5863
this.pythonSettings = settings.PythonSettings.getInstance();
5964
}
6065
public abstract isEnabled(): Boolean;

src/client/linters/flake8.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {OutputChannel} from 'vscode';
55
import { Product } from '../common/installer';
66

77
export class Linter extends baseLinter.BaseLinter {
8-
constructor(outputChannel: OutputChannel, workspaceRootPath: string) {
8+
constructor(outputChannel: OutputChannel, workspaceRootPath?: string) {
99
super('flake8', Product.flake8, outputChannel, workspaceRootPath);
1010
}
1111

src/client/linters/mypy.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { Product } from '../common/installer';
77
const REGEX = '(?<file>.py):(?<line>\\d+): (?<type>\\w+): (?<message>.*)\\r?(\\n|$)';
88

99
export class Linter extends baseLinter.BaseLinter {
10-
constructor(outputChannel: OutputChannel, workspaceRootPath: string) {
10+
constructor(outputChannel: OutputChannel, workspaceRootPath?: string) {
1111
super('mypy', Product.mypy, outputChannel, workspaceRootPath);
1212
}
1313
private parseMessagesSeverity(category: string): baseLinter.LintMessageSeverity {

0 commit comments

Comments
 (0)