@@ -11,7 +11,7 @@ import {
11
11
Range
12
12
} from "vscode" ;
13
13
import { TypeHintProvider } from "./typeHintProvider" ;
14
- import { paramHintTrigger , returnHintTrigger , PythonType , anyClassOrFunctionName } from "./python" ;
14
+ import { paramHintTrigger , returnHintTrigger , PythonType , simpleIdentifier } from "./python" ;
15
15
import { TypeHintSettings } from "./settings" ;
16
16
17
17
@@ -63,39 +63,39 @@ export class ParamHintCompletionProvider extends CompletionProvider implements C
63
63
const precedingText = line . text . substring ( 0 , pos . character - 1 ) . trim ( ) ;
64
64
65
65
if ( this . shouldProvideItems ( precedingText , pos , doc ) ) {
66
- const param : string = this . findParam ( precedingText ) ;
66
+ const param = this . getParam ( precedingText ) ;
67
67
const provider = new TypeHintProvider ( doc , this . settings ) ;
68
68
69
- if ( param . length > 0 ) {
69
+ if ( param ) {
70
70
try {
71
71
this . pushEstimationsToItems ( await provider . getTypeHints ( param ) , items ) ;
72
72
} catch ( error ) {
73
- }
73
+ }
74
+ this . pushTypesToItems ( provider . getRemainingTypes ( ) , items ) ;
75
+ return Promise . resolve ( new CompletionList ( items , false ) ) ;
74
76
}
75
- this . pushTypesToItems ( provider . getRemainingTypes ( ) , items ) ;
76
- return Promise . resolve ( new CompletionList ( items , false ) ) ;
77
77
}
78
78
}
79
79
return Promise . resolve ( null ) ;
80
80
}
81
81
82
82
/**
83
- * Finds the parameter which is about to be type hinted.
83
+ * Returns the parameter which is about to be type hinted.
84
84
*
85
85
* @param precedingText The text before the active position.
86
- * @returns The parameter.
87
86
*/
88
- private findParam ( precedingText : string ) : string {
87
+ private getParam ( precedingText : string ) : string | null {
89
88
let param = "" ;
90
89
91
90
let i = precedingText . length - 1 ;
92
91
let last = precedingText [ i ] ;
93
- while ( last !== "," && last !== "(" && i >= 0 ) {
92
+ while ( last !== "," && last !== "(" && last !== "*" && i >= 0 ) {
94
93
param = precedingText [ i ] + param ;
95
94
i -- ;
96
95
last = precedingText [ i ] ;
97
96
}
98
- return param . trim ( ) ;
97
+ param = param . trim ( ) ;
98
+ return ! param || / [ ) , ! : ? / \\ { } . + / = ( ) ' " & % ¤ | < > $ ^ ~ ¨ - ] / . test ( param ) ? null : param ;
99
99
}
100
100
101
101
private pushEstimationsToItems ( typeHints : string [ ] , items : CompletionItem [ ] ) {
@@ -116,32 +116,21 @@ export class ParamHintCompletionProvider extends CompletionProvider implements C
116
116
117
117
private shouldProvideItems ( precedingText : string , activePos : Position , doc : TextDocument ) : boolean {
118
118
119
- if ( activePos . character > 0 && ! this . isInvalid ( precedingText ) ) {
120
- let provide = new RegExp ( "^[ \t]*def" , "m" ) . test ( precedingText ) ;
119
+ if ( activePos . character > 0 && ! / # / . test ( precedingText ) ) {
120
+ let provide = new RegExp ( "^[ \t]*def\\( " , "m" ) . test ( precedingText ) ;
121
121
122
122
if ( ! provide ) {
123
123
const nLinesToCheck = activePos . line > 4 ? 4 : activePos . line ;
124
124
const range = new Range ( doc . lineAt ( activePos . line - nLinesToCheck ) . range . start , activePos ) ;
125
125
provide = new RegExp (
126
- `^[ \t]*def(?![\s\S]+(\\):|-> *${ anyClassOrFunctionName } :))` ,
126
+ `^[ \t]*def(?![\s\S]+(\\):|-> *${ simpleIdentifier } :))` ,
127
127
"m"
128
128
) . test ( doc . getText ( range ) ) ;
129
129
}
130
130
return provide ;
131
131
}
132
132
return false ;
133
133
}
134
-
135
- /**
136
- * The text is invalid if it is a comment, dict,
137
- * the end of the function definition or preceding a ':' within a string.
138
- */
139
- private isInvalid ( precedingText : string ) : boolean {
140
- if ( precedingText ) {
141
- return new RegExp ( `#|\\)$|['"][^'",]*$|{ *[a-zA-Z0-9.+*/\\(\\)-]+$` ) . test ( precedingText ) ;
142
- }
143
- return true ;
144
- }
145
134
}
146
135
147
136
/**
0 commit comments