Skip to content

Commit 8051124

Browse files
committed
clearn up
1 parent eaf2f4c commit 8051124

20 files changed

Lines changed: 48 additions & 83 deletions

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
.DS_Store
22
out
33
node_modules
4-
*.pyc
4+
*.pyc
5+
.vscode/settings.json

src/client/common/configSettings.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,20 @@ export interface IAutoCompeteSettings {
5555
extraPaths: string[];
5656
}
5757
export class PythonSettings implements IPythonSettings {
58+
private static pythonSettings: PythonSettings = new PythonSettings();
5859
constructor() {
60+
if (PythonSettings.pythonSettings) {
61+
throw new Error("Singleton class, Use getInstance method");
62+
}
5963
vscode.workspace.onDidChangeConfiguration(() => {
6064
this.initializeSettings();
6165
});
6266

6367
this.initializeSettings();
6468
}
69+
public static getInstance(): PythonSettings {
70+
return PythonSettings.pythonSettings;
71+
}
6572
private initializeSettings() {
6673
var pythonSettings = vscode.workspace.getConfiguration("python");
6774
this.pythonPath = pythonSettings.get<string>("pythonPath");

src/client/common/logger.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,10 @@ import * as vscode from 'vscode';
22
import * as settings from './configSettings'
33

44
let outChannel: vscode.OutputChannel;
5-
let pythonSettings: settings.IPythonSettings;
65

76
class Logger {
87
static initializeChannel() {
9-
if (pythonSettings) return;
10-
pythonSettings = new settings.PythonSettings();
11-
if (pythonSettings.devOptions.indexOf("DEBUG") >= 0) {
8+
if (settings.PythonSettings.getInstance().devOptions.indexOf("DEBUG") >= 0) {
129
outChannel = vscode.window.createOutputChannel('PythonExtLog');
1310
}
1411
}

src/client/debugger/DebugServers/LocalDebugServer.ts

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,6 @@ export class LocalDebugServer extends BaseDebugServer {
2727
var that = this;
2828
this.debugSocketServer = net.createServer(c => { //'connection' listener
2929
var connected = false;
30-
c.on('end', (ex) => {
31-
//var msg = "Debugger client disconneced, " + ex;
32-
//that.debugSession.sendEvent(new OutputEvent(msg + "\n", "stderr"));
33-
//console.log(msg);
34-
});
3530
c.on("data", (buffer: Buffer) => {
3631
if (!connected) {
3732
connected = true;
@@ -46,12 +41,6 @@ export class LocalDebugServer extends BaseDebugServer {
4641
var msg = "Debugger client closed, " + d;
4742
that.emit("detach", d);
4843
});
49-
c.on("error", d=> {
50-
// var msg = "Debugger client error, " + d;
51-
// that.sendEvent(new OutputEvent(msg + "\n", "Python"));
52-
// console.log(msg);
53-
// // that.onDetachDebugger();
54-
});
5544
c.on("timeout", d=> {
5645
var msg = "Debugger client timedout, " + d;
5746
that.debugSession.sendEvent(new OutputEvent(msg + "\n", "stderr"));

src/client/debugger/PythonProcessCallbackHandler.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -285,9 +285,6 @@ export class PythonProcessCallbackHandler extends EventEmitter {
285285
this.process.PendingExecuteCommands.delete(execId);
286286
}
287287
cmd.PromiseReject(exceptionText);
288-
//console.log(`ExecuteText Exception ${execId}`);
289-
} else {
290-
//console.error("Received execution result with unknown execution ID " + execId);
291288
}
292289
this.idDispenser.Free(execId);
293290
}
@@ -300,8 +297,6 @@ export class PythonProcessCallbackHandler extends EventEmitter {
300297
var cmd: IExecutionCommand = null;
301298
if (this.process.PendingExecuteCommands.has(execId)) {
302299
cmd = this.process.PendingExecuteCommands.get(execId);
303-
} else {
304-
//console.error("Received execution result with unknown execution ID " + execId);
305300
}
306301

307302
if (cmd === null) {
@@ -338,8 +333,6 @@ export class PythonProcessCallbackHandler extends EventEmitter {
338333
var cmd: IChildEnumCommand = null;
339334
if (this.process.PendingChildEnumCommands.has(execId)) {
340335
cmd = this.process.PendingChildEnumCommands.get(execId);
341-
} else {
342-
//console.error("Received enum children result with unknown execution ID " + execId);
343336
}
344337

345338
var childrenCount = this.stream.ReadInt32();

src/client/extension.ts

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
'use strict';
22

3-
// The module 'vscode' contains the VS Code extensibility API
4-
// Import the module and reference it with the alias vscode in your code below
53
import * as vscode from 'vscode';
64
import {PythonCompletionItemProvider} from './providers/completionProvider';
75
import {PythonHoverProvider} from './providers/hoverProvider';
@@ -17,18 +15,14 @@ import * as path from 'path';
1715
import * as settings from './common/configSettings'
1816
import {activateUnitTestProvider} from './providers/testProvider';
1917

20-
// import {PythonSignatureHelpProvider} from './providers/signatureProvider';
21-
2218
const PYTHON: vscode.DocumentFilter = { language: 'python', scheme: 'file' }
2319
let unitTestOutChannel: vscode.OutputChannel;
2420
let formatOutChannel: vscode.OutputChannel;
2521
let lintingOutChannel: vscode.OutputChannel;
2622

27-
// this method is called when your extension is activated
28-
// your extension is activated the very first time the command is executed
2923
export function activate(context: vscode.ExtensionContext) {
3024
var rootDir = context.asAbsolutePath(".");
31-
var pythonSettings = new settings.PythonSettings();
25+
var pythonSettings = settings.PythonSettings.getInstance();
3226
unitTestOutChannel = vscode.window.createOutputChannel(pythonSettings.unitTest.outputWindow);
3327
unitTestOutChannel.clear();
3428
formatOutChannel = unitTestOutChannel;
@@ -42,7 +36,6 @@ export function activate(context: vscode.ExtensionContext) {
4236
lintingOutChannel.clear();
4337
}
4438

45-
4639
sortImports.activate(context);
4740
activateUnitTestProvider(context, pythonSettings, unitTestOutChannel);
4841
activateFormatOnSaveProvider(PYTHON, context, pythonSettings, formatOutChannel);
@@ -63,10 +56,9 @@ export function activate(context: vscode.ExtensionContext) {
6356
context.subscriptions.push(vscode.languages.registerReferenceProvider(PYTHON, new PythonReferenceProvider(context)));
6457
context.subscriptions.push(vscode.languages.registerCompletionItemProvider(PYTHON, new PythonCompletionItemProvider(context), '.'));
6558
context.subscriptions.push(vscode.languages.registerDocumentSymbolProvider(PYTHON, new PythonSymbolProvider(context)));
66-
// context.subscriptions.push(vscode.languages.registerSignatureHelpProvider(PYTHON, new PythonSignatureHelpProvider(context), '('));
6759

68-
context.subscriptions.push(vscode.languages.registerDocumentFormattingEditProvider(PYTHON, new PythonFormattingEditProvider(context, pythonSettings, formatOutChannel)));
69-
context.subscriptions.push(new LintProvider(context, pythonSettings, lintingOutChannel));
60+
context.subscriptions.push(vscode.languages.registerDocumentFormattingEditProvider(PYTHON, new PythonFormattingEditProvider(context, formatOutChannel)));
61+
context.subscriptions.push(new LintProvider(context, lintingOutChannel));
7062
}
7163

7264
// this method is called when your extension is deactivated

src/client/formatters/autoPep8Formatter.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,10 @@
77
import * as vscode from 'vscode';
88
import * as path from 'path';
99
import {BaseFormatter} from './baseFormatter';
10-
import * as settings from './../common/configSettings';
1110

1211
export class AutoPep8Formatter extends BaseFormatter {
13-
private pythonSettings: settings.IPythonSettings;
14-
constructor(settings: settings.IPythonSettings, outputChannel:vscode.OutputChannel) {
12+
constructor(outputChannel:vscode.OutputChannel) {
1513
super("autopep8", outputChannel);
16-
this.pythonSettings = settings;
1714
}
1815

1916
public formatDocument(document: vscode.TextDocument, options: vscode.FormattingOptions, token: vscode.CancellationToken): Thenable<vscode.TextEdit[]> {

src/client/formatters/baseFormatter.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,20 @@ import * as vscode from 'vscode';
88
import * as path from 'path';
99
import * as fs from 'fs';
1010
import {sendCommand} from './../common/childProc';
11+
import * as settings from './../common/configSettings';
1112

1213
export abstract class BaseFormatter {
1314
public Id: string;
1415
protected outputChannel: vscode.OutputChannel;
16+
protected pythonSettings: settings.IPythonSettings;
1517

1618
constructor(id: string, outputChannel: vscode.OutputChannel) {
1719
this.Id = id;
1820
this.outputChannel = outputChannel;
21+
this.pythonSettings = settings.PythonSettings.getInstance();
1922
}
20-
public formatDocument(document: vscode.TextDocument, options: vscode.FormattingOptions, token: vscode.CancellationToken): Thenable<vscode.TextEdit[]> {
21-
return Promise.resolve([]);
22-
}
23+
24+
public abstract formatDocument(document: vscode.TextDocument, options: vscode.FormattingOptions, token: vscode.CancellationToken): Thenable<vscode.TextEdit[]>;
2325

2426
protected provideDocumentFormattingEdits(document: vscode.TextDocument, options: vscode.FormattingOptions, token: vscode.CancellationToken, cmdLine: string): Thenable<vscode.TextEdit[]> {
2527
var fileDir = path.dirname(document.uri.fsPath);
@@ -45,7 +47,7 @@ export abstract class BaseFormatter {
4547
var txtEdit = new vscode.TextEdit(range, formattedText);
4648
resolve([txtEdit]);
4749

48-
}, errorMsg => {
50+
}).catch(errorMsg => {
4951
vscode.window.showErrorMessage(`There was an error in formatting the document. View the Python output window for details.`);
5052
this.outputChannel.appendLine(errorMsg);
5153
return resolve([]);

src/client/formatters/yapfFormatter.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,8 @@ import {BaseFormatter} from './baseFormatter';
1010
import * as settings from './../common/configSettings';
1111

1212
export class YapfFormatter extends BaseFormatter {
13-
private pythonSettings: settings.IPythonSettings;
14-
constructor(settings: settings.IPythonSettings, outputChannel: vscode.OutputChannel) {
13+
constructor(outputChannel: vscode.OutputChannel) {
1514
super("yapf", outputChannel);
16-
this.pythonSettings = settings;
1715
}
1816

1917
public formatDocument(document: vscode.TextDocument, options: vscode.FormattingOptions, token: vscode.CancellationToken): Thenable<vscode.TextEdit[]> {

src/client/linters/baseLinter.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,13 @@ export abstract class BaseLinter {
5252
public Id: string;
5353
protected pythonSettings: settings.IPythonSettings;
5454
protected outputChannel: OutputChannel;
55-
constructor(id: string, pythonSettings: settings.IPythonSettings, outputChannel: OutputChannel) {
55+
constructor(id: string, outputChannel: OutputChannel) {
5656
this.Id = id;
57-
this.pythonSettings = pythonSettings;
57+
this.pythonSettings = settings.PythonSettings.getInstance();
5858
this.outputChannel = outputChannel;
5959
}
6060

61-
public runLinter(filePath: string, txtDocumentLines: string[]): Promise<ILintMessage[]> {
62-
return Promise.resolve([]);
63-
}
61+
public abstract runLinter(filePath: string, txtDocumentLines: string[]): Promise<ILintMessage[]>;
6462

6563
protected run(commandLine: string, filePath: string, txtDocumentLines: string[], cwd: string, regEx: string = REGEX): Promise<ILintMessage[]> {
6664
var outputChannel = this.outputChannel;

0 commit comments

Comments
 (0)