@@ -2,6 +2,7 @@ import { Range } from 'vscode-languageserver-types';
2
2
import { ParseTreeWalker } from '../analyzer/parseTreeWalker' ;
3
3
import { isDunderName , isUnderscoreOnlyName } from '../analyzer/symbolNameUtils' ;
4
4
import {
5
+ ClassType ,
5
6
FunctionType ,
6
7
Type ,
7
8
getTypeAliasInfo ,
@@ -15,6 +16,7 @@ import { ProgramView } from '../common/extensibility';
15
16
import { limitOverloadBasedOnCall } from '../languageService/tooltipUtils' ;
16
17
import {
17
18
CallNode ,
19
+ ClassNode ,
18
20
FunctionNode ,
19
21
NameNode ,
20
22
ParamCategory ,
@@ -28,6 +30,7 @@ import { convertRangeToTextRange } from '../common/positionUtils';
28
30
import { Uri } from '../common/uri/uri' ;
29
31
import { ParseFileResults } from '../parser/parser' ;
30
32
import { InlayHintSettings } from '../common/languageServerInterface' ;
33
+ import { transformTypeForEnumMember } from './enums' ;
31
34
32
35
export type TypeInlayHintsItemType = {
33
36
inlayHintType : 'variable' | 'functionReturn' | 'parameter' ;
@@ -93,6 +96,7 @@ export class TypeInlayHintsWalker extends ParseTreeWalker {
93
96
featureItems : TypeInlayHintsItemType [ ] = [ ] ;
94
97
parseResults ?: ParseFileResults ;
95
98
private _range : TextRange | undefined ;
99
+ private _variablesThatShouldntHaveInlayHints = new Set < ParseNode > ( ) ;
96
100
97
101
constructor (
98
102
private readonly _program : ProgramView ,
@@ -110,6 +114,26 @@ export class TypeInlayHintsWalker extends ParseTreeWalker {
110
114
}
111
115
}
112
116
117
+ override visitClass ( node : ClassNode ) : boolean {
118
+ const evaluator = this . _program . evaluator ;
119
+ if ( evaluator ) {
120
+ const classType = evaluator . getTypeOfClass ( node ) ?. classType ;
121
+ // prevent inlay hints from appearing on enum members
122
+ if ( classType && ClassType . isEnumClass ( classType ) ) {
123
+ ClassType . getSymbolTable ( classType ) . forEach ( ( symbol , name ) => {
124
+ const symbolType = transformTypeForEnumMember ( evaluator , classType , name , true ) ;
125
+ if ( symbolType ) {
126
+ const nameNode = symbol . getDeclarations ( ) [ 0 ] ?. node ;
127
+ if ( nameNode ) {
128
+ this . _variablesThatShouldntHaveInlayHints . add ( nameNode ) ;
129
+ }
130
+ }
131
+ } ) ;
132
+ }
133
+ }
134
+ return super . visitClass ( node ) ;
135
+ }
136
+
113
137
override visitName ( node : NameNode ) : boolean {
114
138
if (
115
139
this . _settings . variableTypes &&
@@ -125,7 +149,8 @@ export class TypeInlayHintsWalker extends ParseTreeWalker {
125
149
! ( isClass ( type ) && isLiteralType ( type ) ) &&
126
150
! isTypeVar ( type ) &&
127
151
// !isFunction(type) &&
128
- ! isParamSpec ( type )
152
+ ! isParamSpec ( type ) &&
153
+ ! this . _variablesThatShouldntHaveInlayHints . has ( node )
129
154
) {
130
155
this . featureItems . push ( {
131
156
inlayHintType : 'variable' ,
0 commit comments