@@ -3,7 +3,6 @@ import { PythonType as PythonType, DataTypeContainer, getDataTypeContainer } fro
33import { TypeSearch , VariableSearchResult } from "./typeSearch" ;
44import { TypingHintProvider } from "./typingHintProvider" ;
55import { WorkspaceSearcher } from "./workspaceSearcher" ;
6- import { TypeHint , labelFor } from "./typeHint" ;
76import { TypeHintSettings } from "./settings" ;
87
98/**
@@ -21,7 +20,7 @@ export class TypeHintProvider {
2120 PythonType . Float
2221 ] ;
2322 private typeContainer : DataTypeContainer = getDataTypeContainer ( ) ;
24- private typesIncludedInResult : { [ key : string ] : string } = { } ;
23+ private typeNamesIncludedInResult : string [ ] = [ ] ;
2524 private doc : TextDocument ;
2625 private settings : TypeHintSettings ;
2726
@@ -41,8 +40,8 @@ export class TypeHintProvider {
4140 * @param param The parameter name.
4241 * @returns An array of type hints, ordered by estimation accuracy.
4342 */
44- public async getTypeHints ( param : string ) : Promise < TypeHint [ ] > {
45- const typeHints : TypeHint [ ] = [ ] ;
43+ public async getTypeHints ( param : string ) : Promise < string [ ] > {
44+ const typeHints : string [ ] = [ ] ;
4645 const documentText = this . doc . getText ( ) ;
4746
4847 const typingHintProvider = new TypingHintProvider ( documentText , this . typeContainer ) ;
@@ -114,7 +113,7 @@ export class TypeHintProvider {
114113 return null ;
115114 }
116115
117- private typeGuessFor ( param : string , typeHints : TypeHint [ ] ) : string | null {
116+ private typeGuessFor ( param : string , typeHints : string [ ] ) : string | null {
118117 const typeGuesses : { [ key : string ] : string } = {
119118 "string" : PythonType . String ,
120119 "text" : PythonType . String ,
@@ -132,18 +131,37 @@ export class TypeHintProvider {
132131 }
133132 return null ;
134133 }
134+
135+
136+ private add ( typeName : string , typeHints : string [ ] ) {
137+ typeName = typeName . trim ( ) ;
138+ if ( this . typeNotIncluded ( typeName ) ) {
139+ typeHints . push ( typeName ) ;
140+ this . typeNamesIncludedInResult . push ( typeName ) ;
141+ }
142+ }
143+
144+ private typeNotIncluded ( type : string ) : boolean {
145+ return ! this . typeNamesIncludedInResult . includes ( type ) ;
146+ }
147+
148+ private tryAdd ( type : string | null , typeHints : string [ ] ) {
149+ if ( type ) {
150+ this . add ( type , typeHints ) ;
151+ }
152+ }
135153
136154 private tryAddTypingHints (
137155 typingFound : boolean ,
138156 searchResult : VariableSearchResult | null ,
139157 typingHintProvider : TypingHintProvider ,
140- typeHints : TypeHint [ ]
158+ typeHints : string [ ]
141159 ) {
142160 if ( typingFound ) {
143- const hints : TypeHint [ ] | null = typingHintProvider . getTypingHints ( searchResult ) ;
161+ const hints : string [ ] | null = typingHintProvider . getTypingHints ( searchResult ) ;
144162 if ( hints ) {
145163 for ( const hint of hints ) {
146- this . addTypeHint ( hint , typeHints ) ;
164+ this . add ( hint , typeHints ) ;
147165 }
148166 }
149167 }
@@ -153,37 +171,13 @@ export class TypeHintProvider {
153171 typingFound : boolean ,
154172 typeName : string ,
155173 typingHintProvider : TypingHintProvider ,
156- typeHints : TypeHint [ ]
174+ typeHints : string [ ]
157175 ) {
158176 if ( typingFound ) {
159177 const typingHint = typingHintProvider . getTypingHint ( typeName ) ;
160178 if ( typingHint ) {
161- this . addTypeHint ( typingHint , typeHints ) ;
179+ this . add ( typingHint , typeHints ) ;
162180 }
163181 }
164182 }
165-
166- private typeNotIncluded ( type : string ) : boolean {
167- return ! ( type in this . typesIncludedInResult ) ;
168- }
169-
170- private add ( type : string , typeHints : TypeHint [ ] ) {
171- if ( this . typeNotIncluded ( type ) ) {
172- typeHints . push ( { label : labelFor ( type ) } ) ;
173- this . typesIncludedInResult [ type ] = type ;
174- }
175- }
176-
177- private addTypeHint ( hint : TypeHint , typeHints : TypeHint [ ] ) {
178- if ( this . typeNotIncluded ( hint . label ) ) {
179- typeHints . push ( hint ) ;
180- this . typesIncludedInResult [ hint . label ] = hint . label ;
181- }
182- }
183-
184- private tryAdd ( type : string | null , typeHints : TypeHint [ ] ) {
185- if ( type ) {
186- this . add ( type , typeHints ) ;
187- }
188- }
189183}
0 commit comments