1
1
import * as path from 'path' ;
2
2
import * as vscode from 'vscode' ;
3
- import { CancellationToken , OutputChannel , TextDocument , Uri } from 'vscode ' ;
3
+ import { IWorkspaceService } from '../common/application/types ' ;
4
4
import '../common/extensions' ;
5
5
import { IPythonToolExecutionService } from '../common/process/types' ;
6
- import { ExecutionInfo , ILogger , Product } from '../common/types' ;
7
6
import { IConfigurationService , IPythonSettings } from '../common/types' ;
7
+ import { ExecutionInfo , ILogger , Product } from '../common/types' ;
8
8
import { IServiceContainer } from '../ioc/types' ;
9
9
import { ErrorHandler } from './errorHandlers/errorHandler' ;
10
10
import { ILinter , ILinterInfo , ILinterManager , ILintMessage , LintMessageSeverity } from './types' ;
@@ -38,25 +38,27 @@ export abstract class BaseLinter implements ILinter {
38
38
private errorHandler : ErrorHandler ;
39
39
private _pythonSettings : IPythonSettings ;
40
40
private _info : ILinterInfo ;
41
+ private workspace : IWorkspaceService ;
41
42
42
43
protected get pythonSettings ( ) : IPythonSettings {
43
44
return this . _pythonSettings ;
44
45
}
45
46
46
47
constructor ( product : Product ,
47
- protected readonly outputChannel : OutputChannel ,
48
+ protected readonly outputChannel : vscode . OutputChannel ,
48
49
protected readonly serviceContainer : IServiceContainer ,
49
50
protected readonly columnOffset = 0 ) {
50
51
this . _info = serviceContainer . get < ILinterManager > ( ILinterManager ) . getLinterInfo ( product ) ;
51
52
this . errorHandler = new ErrorHandler ( this . info . product , outputChannel , serviceContainer ) ;
52
53
this . configService = serviceContainer . get < IConfigurationService > ( IConfigurationService ) ;
54
+ this . workspace = serviceContainer . get < IWorkspaceService > ( IWorkspaceService ) ;
53
55
}
54
56
55
57
public get info ( ) : ILinterInfo {
56
58
return this . _info ;
57
59
}
58
60
59
- public isLinterExecutableSpecified ( resource : Uri ) {
61
+ public isLinterExecutableSpecified ( resource : vscode . Uri ) {
60
62
const executablePath = this . info . pathName ( resource ) ;
61
63
return path . basename ( executablePath ) . length > 0 && path . basename ( executablePath ) !== executablePath ;
62
64
}
@@ -66,7 +68,7 @@ export abstract class BaseLinter implements ILinter {
66
68
}
67
69
68
70
protected getWorkspaceRootPath ( document : vscode . TextDocument ) : string {
69
- const workspaceFolder = vscode . workspace . getWorkspaceFolder ( document . uri ) ;
71
+ const workspaceFolder = this . workspace . getWorkspaceFolder ( document . uri ) ;
70
72
const workspaceRootPath = ( workspaceFolder && typeof workspaceFolder . uri . fsPath === 'string' ) ? workspaceFolder . uri . fsPath : undefined ;
71
73
return typeof workspaceRootPath === 'string' ? workspaceRootPath : __dirname ;
72
74
}
@@ -107,7 +109,7 @@ export abstract class BaseLinter implements ILinter {
107
109
const cwd = this . getWorkspaceRootPath ( document ) ;
108
110
const pythonToolsExecutionService = this . serviceContainer . get < IPythonToolExecutionService > ( IPythonToolExecutionService ) ;
109
111
try {
110
- const result = await pythonToolsExecutionService . exec ( executionInfo , { cwd, token : cancellation , mergeStdOutErr : true } , document . uri ) ;
112
+ const result = await pythonToolsExecutionService . exec ( executionInfo , { cwd, token : cancellation , mergeStdOutErr : true } , document . uri ) ;
111
113
this . displayLinterResultHeader ( result . stdout ) ;
112
114
return await this . parseMessages ( result . stdout , document , cancellation , regEx ) ;
113
115
} catch ( error ) {
@@ -116,12 +118,12 @@ export abstract class BaseLinter implements ILinter {
116
118
}
117
119
}
118
120
119
- protected async parseMessages ( output : string , document : TextDocument , token : CancellationToken , regEx : string ) {
121
+ protected async parseMessages ( output : string , document : vscode . TextDocument , token : vscode . CancellationToken , regEx : string ) {
120
122
const outputLines = output . splitLines ( { removeEmptyEntries : false , trim : false } ) ;
121
123
return this . parseLines ( outputLines , regEx ) ;
122
124
}
123
125
124
- protected handleError ( error : Error , resource : Uri , execInfo : ExecutionInfo ) {
126
+ protected handleError ( error : Error , resource : vscode . Uri , execInfo : ExecutionInfo ) {
125
127
this . errorHandler . handleError ( error , resource , execInfo )
126
128
. catch ( this . logger . logError . bind ( this , 'Error in errorHandler.handleError' ) ) ;
127
129
}
0 commit comments