forked from DonJayamanne/pythonVSCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathextension.ts
More file actions
76 lines (69 loc) · 4.36 KB
/
extension.ts
File metadata and controls
76 lines (69 loc) · 4.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
"use strict";
import * as vscode from "vscode";
import {PythonCompletionItemProvider} from "./providers/completionProvider";
import {PythonHoverProvider} from "./providers/hoverProvider";
import {PythonDefinitionProvider} from "./providers/definitionProvider";
import {PythonReferenceProvider} from "./providers/referenceProvider";
import {PythonRenameProvider} from "./providers/renameProvider";
import {PythonFormattingEditProvider} from "./providers/formatProvider";
import * as sortImports from "./sortImports";
import {LintProvider} from "./providers/lintProvider";
import {PythonSymbolProvider} from "./providers/symbolProvider";
import {PythonSignatureProvider} from "./providers/signatureProvider";
import {activateFormatOnSaveProvider} from "./providers/formatOnSaveProvider";
import * as path from "path";
import * as settings from "./common/configSettings";
import {activateUnitTestProvider} from "./providers/testProvider";
import * as telemetryHelper from "./common/telemetry";
import * as telemetryContracts from "./common/telemetryContracts";
const PYTHON: vscode.DocumentFilter = { language: "python", scheme: "file" };
let unitTestOutChannel: vscode.OutputChannel;
let formatOutChannel: vscode.OutputChannel;
let lintingOutChannel: vscode.OutputChannel;
export function activate(context: vscode.ExtensionContext) {
let rootDir = context.asAbsolutePath(".");
let pythonSettings = settings.PythonSettings.getInstance();
telemetryHelper.sendTelemetryEvent(telemetryContracts.EVENT_LOAD, {
CodeComplete_Has_ExtraPaths: pythonSettings.autoComplete.extraPaths.length > 0 ? "true" : "false",
Format_Has_Custom_Python_Path: pythonSettings.pythonPath.length !== "python".length ? "true" : "false"
});
unitTestOutChannel = vscode.window.createOutputChannel(pythonSettings.unitTest.outputWindow);
unitTestOutChannel.clear();
formatOutChannel = unitTestOutChannel;
lintingOutChannel = unitTestOutChannel;
if (pythonSettings.unitTest.outputWindow !== pythonSettings.formatting.outputWindow) {
formatOutChannel = vscode.window.createOutputChannel(pythonSettings.formatting.outputWindow);
formatOutChannel.clear();
}
if (pythonSettings.unitTest.outputWindow !== pythonSettings.linting.outputWindow) {
lintingOutChannel = vscode.window.createOutputChannel(pythonSettings.linting.outputWindow);
lintingOutChannel.clear();
}
sortImports.activate(context, formatOutChannel);
activateUnitTestProvider(context, pythonSettings, unitTestOutChannel);
context.subscriptions.push(activateFormatOnSaveProvider(PYTHON, pythonSettings, formatOutChannel, vscode.workspace.rootPath));
// Enable indentAction
vscode.languages.setLanguageConfiguration(PYTHON.language, {
onEnterRules: [
{
beforeText: /^\s*(?:def|class|for|if|elif|else|while|try|with|finally).*?:\s*$/,
action: { indentAction: vscode.IndentAction.Indent }
}
]
});
let renameProvider = new PythonRenameProvider(context);
context.subscriptions.push(vscode.languages.registerRenameProvider(PYTHON, renameProvider));
context.subscriptions.push(vscode.languages.registerHoverProvider(PYTHON, new PythonHoverProvider(context)));
context.subscriptions.push(vscode.languages.registerDefinitionProvider(PYTHON, new PythonDefinitionProvider(context)));
context.subscriptions.push(vscode.languages.registerReferenceProvider(PYTHON, new PythonReferenceProvider(context)));
context.subscriptions.push(vscode.languages.registerCompletionItemProvider(PYTHON, new PythonCompletionItemProvider(context), "."));
context.subscriptions.push(vscode.languages.registerDocumentSymbolProvider(PYTHON, new PythonSymbolProvider(context, renameProvider.JediProxy)));
if (pythonSettings.devOptions.indexOf("DISABLE_SIGNATURE") === -1) {
context.subscriptions.push(vscode.languages.registerSignatureHelpProvider(PYTHON, new PythonSignatureProvider(context, renameProvider.JediProxy), "(", ","));
}
context.subscriptions.push(vscode.languages.registerDocumentFormattingEditProvider(PYTHON, new PythonFormattingEditProvider(context, formatOutChannel, pythonSettings, vscode.workspace.rootPath)));
context.subscriptions.push(new LintProvider(context, lintingOutChannel, vscode.workspace.rootPath));
}
// this method is called when your extension is deactivated
export function deactivate() {
}