@@ -6,10 +6,9 @@ import { traceError, traceInfo } from '.';
6
6
import { Commands , PVSC_EXTENSION_ID } from '../common/constants' ;
7
7
import { showErrorMessage } from '../common/vscodeApis/windowApis' ;
8
8
import { getConfiguration , getWorkspaceFolders } from '../common/vscodeApis/workspaceApis' ;
9
- import { Common } from '../common/utils/localize' ;
10
- import { executeCommand } from '../common/vscodeApis/commandApis' ;
11
9
12
- export function logAndNotifyOnFormatterSetting ( ) : void {
10
+ function logOnLegacyFormatterSetting ( ) : boolean {
11
+ let usesLegacyFormatter = false ;
13
12
getWorkspaceFolders ( ) ?. forEach ( async ( workspace ) => {
14
13
let config = getConfiguration ( 'editor' , { uri : workspace . uri , languageId : 'python' } ) ;
15
14
if ( ! config ) {
@@ -21,22 +20,86 @@ export function logAndNotifyOnFormatterSetting(): void {
21
20
const formatter = config . get < string > ( 'defaultFormatter' , '' ) ;
22
21
traceInfo ( `Default formatter is set to ${ formatter } for workspace ${ workspace . uri . fsPath } ` ) ;
23
22
if ( formatter === PVSC_EXTENSION_ID ) {
23
+ usesLegacyFormatter = true ;
24
24
traceError ( 'Formatting features have been moved to separate formatter extensions.' ) ;
25
+ traceError ( 'See here for more information: https://code.visualstudio.com/docs/python/formatting' ) ;
25
26
traceError ( 'Please install the formatter extension you prefer and set it as the default formatter.' ) ;
26
27
traceError ( 'For `autopep8` use: https://marketplace.visualstudio.com/items?itemName=ms-python.autopep8' ) ;
27
28
traceError (
28
29
'For `black` use: https://marketplace.visualstudio.com/items?itemName=ms-python.black-formatter' ,
29
30
) ;
30
31
traceError ( 'For `yapf` use: https://marketplace.visualstudio.com/items?itemName=eeyore.yapf' ) ;
31
- const response = await showErrorMessage (
32
- l10n . t (
33
- 'Formatting features have been moved to separate formatter extensions. Please install the formatter extension you prefer and set it as the default formatter.' ,
34
- ) ,
35
- Common . showLogs ,
36
- ) ;
37
- if ( response === Common . showLogs ) {
38
- executeCommand ( Commands . ViewOutput ) ;
32
+ }
33
+ } ) ;
34
+ return usesLegacyFormatter ;
35
+ }
36
+
37
+ function logOnLegacyLinterSetting ( ) : boolean {
38
+ let usesLegacyLinter = false ;
39
+ getWorkspaceFolders ( ) ?. forEach ( async ( workspace ) => {
40
+ let config = getConfiguration ( 'python' , { uri : workspace . uri , languageId : 'python' } ) ;
41
+ if ( ! config ) {
42
+ config = getConfiguration ( 'python' , workspace . uri ) ;
43
+ if ( ! config ) {
44
+ traceError ( 'Unable to get editor configuration' ) ;
39
45
}
40
46
}
47
+
48
+ const linters : string [ ] = [
49
+ 'pylint' ,
50
+ 'flake8' ,
51
+ 'mypy' ,
52
+ 'pydocstyle' ,
53
+ 'pylama' ,
54
+ 'pycodestyle' ,
55
+ 'bandit' ,
56
+ 'prospector' ,
57
+ ] ;
58
+
59
+ linters . forEach ( ( linter ) => {
60
+ const linterEnabled = config . get < boolean > ( `linting.${ linter } Enabled` , false ) ;
61
+ if ( linterEnabled ) {
62
+ usesLegacyLinter = true ;
63
+ traceError ( 'Linting features have been moved to separate linter extensions.' ) ;
64
+ traceError ( 'See here for more information: https://code.visualstudio.com/docs/python/linting' ) ;
65
+ if ( linter === 'pylint' || linter === 'flake8' ) {
66
+ traceError (
67
+ `Please install "${ linter } " extension: https://marketplace.visualstudio.com/items?itemName=ms-python.${ linter } ` ,
68
+ ) ;
69
+ } else if ( linter === 'mypy' ) {
70
+ traceError (
71
+ `Please install "${ linter } " extension: https://marketplace.visualstudio.com/items?itemName=ms-python.mypy-type-checker` ,
72
+ ) ;
73
+ } else if ( [ 'pydocstyle' , 'pylama' , 'pycodestyle' , 'bandit' ] . includes ( linter ) ) {
74
+ traceError (
75
+ `selected linter "${ linter } " may be supported by extensions like "Ruff", which include several linter rules: https://marketplace.visualstudio.com/items?itemName=charliermarsh.ruff` ,
76
+ ) ;
77
+ }
78
+ }
79
+ } ) ;
41
80
} ) ;
81
+
82
+ return usesLegacyLinter ;
83
+ }
84
+
85
+ let _isShown = false ;
86
+ async function notifyLegacySettings ( ) : Promise < void > {
87
+ if ( _isShown ) {
88
+ return ;
89
+ }
90
+ _isShown = true ;
91
+ showErrorMessage (
92
+ l10n . t (
93
+ `Formatting and linting features have been deprecated from the Python extension. Please install a linter or a formatter extension. [Open logs](command:${ Commands . ViewOutput } ) for more information.` ,
94
+ ) ,
95
+ ) ;
96
+ }
97
+
98
+ export function logAndNotifyOnLegacySettings ( ) : void {
99
+ const usesLegacyFormatter = logOnLegacyFormatterSetting ( ) ;
100
+ const usesLegacyLinter = logOnLegacyLinterSetting ( ) ;
101
+
102
+ if ( usesLegacyFormatter || usesLegacyLinter ) {
103
+ setImmediate ( ( ) => notifyLegacySettings ( ) . ignoreErrors ( ) ) ;
104
+ }
42
105
}
0 commit comments