Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 92b87de

Browse files
committed
removed old cold related to linting on text change #134
1 parent 5bd5272 commit 92b87de

File tree

1 file changed

+28
-46
lines changed

1 file changed

+28
-46
lines changed

src/client/providers/lintProvider.ts

Lines changed: 28 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,36 @@
1-
'use strict';
2-
3-
import * as vscode from 'vscode';
4-
import * as path from 'path';
5-
import * as linter from '../linters/baseLinter';
6-
import * as prospector from './../linters/prospector';
7-
import * as pylint from './../linters/pylint';
8-
import * as pep8 from './../linters/pep8Linter';
9-
import * as flake8 from './../linters/flake8';
10-
import * as pydocstyle from './../linters/pydocstyle';
11-
import * as settings from '../common/configSettings';
1+
"use strict";
2+
3+
import * as vscode from "vscode";
4+
import * as path from "path";
5+
import * as linter from "../linters/baseLinter";
6+
import * as prospector from "./../linters/prospector";
7+
import * as pylint from "./../linters/pylint";
8+
import * as pep8 from "./../linters/pep8Linter";
9+
import * as flake8 from "./../linters/flake8";
10+
import * as pydocstyle from "./../linters/pydocstyle";
11+
import * as settings from "../common/configSettings";
1212
import * as telemetryHelper from "../common/telemetry";
1313
import * as telemetryContracts from "../common/telemetryContracts";
1414

15-
const FILE_PROTOCOL = "file:///"
16-
17-
function uriToPath(pathValue: string): string {
18-
if (pathValue.startsWith(FILE_PROTOCOL)) {
19-
pathValue = pathValue.substring(FILE_PROTOCOL.length);
20-
}
21-
22-
return path.normalize(decodeURIComponent(pathValue));
23-
}
24-
2515
const lintSeverityToVSSeverity = new Map<linter.LintMessageSeverity, vscode.DiagnosticSeverity>();
2616
lintSeverityToVSSeverity.set(linter.LintMessageSeverity.Error, vscode.DiagnosticSeverity.Error)
2717
lintSeverityToVSSeverity.set(linter.LintMessageSeverity.Hint, vscode.DiagnosticSeverity.Hint)
2818
lintSeverityToVSSeverity.set(linter.LintMessageSeverity.Information, vscode.DiagnosticSeverity.Information)
2919
lintSeverityToVSSeverity.set(linter.LintMessageSeverity.Warning, vscode.DiagnosticSeverity.Warning)
3020

3121
function createDiagnostics(message: linter.ILintMessage, txtDocumentLines: string[]): vscode.Diagnostic {
32-
var sourceLine = txtDocumentLines[message.line - 1];
33-
var sourceStart = sourceLine.substring(message.column - 1);
34-
var endCol = txtDocumentLines[message.line - 1].length;
22+
let sourceLine = txtDocumentLines[message.line - 1];
23+
let sourceStart = sourceLine.substring(message.column - 1);
24+
let endCol = txtDocumentLines[message.line - 1].length;
3525

36-
//try to get the first word from the startig position
26+
// try to get the first word from the startig position
3727
if (message.possibleWord === "string" && message.possibleWord.length > 0) {
3828
endCol = message.column + message.possibleWord.length;
3929
}
4030

41-
var range = new vscode.Range(new vscode.Position(message.line - 1, message.column), new vscode.Position(message.line - 1, endCol));
31+
let range = new vscode.Range(new vscode.Position(message.line - 1, message.column), new vscode.Position(message.line - 1, endCol));
4232

43-
var severity = lintSeverityToVSSeverity.get(message.severity);
33+
let severity = lintSeverityToVSSeverity.get(message.severity);
4434
return new vscode.Diagnostic(range, message.code + ":" + message.message, severity);
4535
}
4636

@@ -63,23 +53,15 @@ export class LintProvider extends vscode.Disposable {
6353

6454
private initialize() {
6555
this.diagnosticCollection = vscode.languages.createDiagnosticCollection("python");
66-
var disposables = [];
56+
let disposables = [];
6757

6858
this.linters.push(new prospector.Linter(this.outputChannel));
6959
this.linters.push(new pylint.Linter(this.outputChannel));
7060
this.linters.push(new pep8.Linter(this.outputChannel));
7161
this.linters.push(new flake8.Linter(this.outputChannel));
7262
this.linters.push(new pydocstyle.Linter(this.outputChannel));
7363

74-
var disposable = vscode.workspace.onDidChangeTextDocument((e) => {
75-
if (e.document.languageId !== "python" || !this.settings.linting.enabled || !this.settings.linting.lintOnTextChange) {
76-
return;
77-
}
78-
this.lintDocument(e.document.uri, e.document.getText().split(/\r?\n/g), 1000);
79-
});
80-
this.context.subscriptions.push(disposable);
81-
82-
disposable = vscode.workspace.onDidSaveTextDocument((e) => {
64+
let disposable = vscode.workspace.onDidSaveTextDocument((e) => {
8365
if (e.languageId !== "python" || !this.settings.linting.enabled || !this.settings.linting.lintOnSave) {
8466
return;
8567
}
@@ -90,8 +72,8 @@ export class LintProvider extends vscode.Disposable {
9072

9173
private lastTimeout: number;
9274
private lintDocument(documentUri: vscode.Uri, documentLines: string[], delay: number): void {
93-
//Since this is a hack, lets wait for 2 seconds before linting
94-
//Give user to continue typing before we waste CPU time
75+
// Since this is a hack, lets wait for 2 seconds before linting
76+
// Give user to continue typing before we waste CPU time
9577
if (this.lastTimeout) {
9678
clearTimeout(this.lastTimeout);
9779
this.lastTimeout = 0;
@@ -108,15 +90,15 @@ export class LintProvider extends vscode.Disposable {
10890
this.pendingLintings.delete(documentUri.fsPath);
10991
}
11092

111-
var cancelToken = new vscode.CancellationTokenSource();
93+
let cancelToken = new vscode.CancellationTokenSource();
11294
cancelToken.token.onCancellationRequested(() => {
11395
if (this.pendingLintings.has(documentUri.fsPath)) {
11496
this.pendingLintings.delete(documentUri.fsPath);
11597
}
11698
});
11799

118100
this.pendingLintings.set(documentUri.fsPath, cancelToken);
119-
var promises = this.linters.map(linter => {
101+
let promises = this.linters.map(linter => {
120102
if (!linter.isEnabled()) {
121103
return Promise.resolve([]);
122104
}
@@ -133,15 +115,15 @@ export class LintProvider extends vscode.Disposable {
133115
return;
134116
}
135117

136-
//Flatten the array
137-
var consolidatedMessages: linter.ILintMessage[] = [];
118+
// Flatten the array
119+
let consolidatedMessages: linter.ILintMessage[] = [];
138120
msgs.forEach(lintMessages => consolidatedMessages = consolidatedMessages.concat(lintMessages));
139121

140-
//Limit the number of messages to the max value
122+
// Limit the number of messages to the max value
141123
consolidatedMessages = consolidatedMessages.filter((value, index) => index <= this.settings.linting.maxNumberOfProblems);
142124

143-
//Build the message and suffix the message with the name of the linter used
144-
var messages = [];
125+
// Build the message and suffix the message with the name of the linter used
126+
let messages = [];
145127
consolidatedMessages.forEach(d => {
146128
d.message = `${d.message} (${d.provider})`;
147129
messages.push(createDiagnostics(d, documentLines));

0 commit comments

Comments
 (0)