1- import { AmbiguousIdentifierContext , FunctionDeclarationContext , ProcedureDeclarationContext , PropertyGetDeclarationContext , PropertySetDeclarationContext , SubroutineDeclarationContext } from '../../antlr/out/vbaParser' ;
1+ import { AmbiguousIdentifierContext , EnumDeclarationContext , EnumMemberContext , FunctionDeclarationContext , ProcedureDeclarationContext , PropertyGetDeclarationContext , PropertySetDeclarationContext , SubroutineDeclarationContext } from '../../antlr/out/vbaParser' ;
22
33import { TextDocument } from 'vscode-languageserver-textdocument' ;
44
5- import { BaseContextSyntaxElement , BaseSyntaxElement , HasSemanticToken , HasSymbolInformation , ScopeElement } from './base' ;
5+ import { BaseContextSyntaxElement , HasSemanticToken , HasSymbolInformation , IdentifiableSyntaxElement } from './base' ;
66import { SemanticTokenModifiers , SemanticTokenTypes , SymbolInformation , SymbolKind } from 'vscode-languageserver' ;
7- import { FoldableElement } from './special' ;
7+ import { ScopeElement } from './special' ;
88import { SymbolInformationFactory } from '../../capabilities/symbolInformation' ;
99import '../../extensions/parserExtensions' ;
1010import { VbaClassDocument , VbaModuleDocument } from '../document' ;
@@ -16,9 +16,8 @@ export class IdentifierElement extends BaseContextSyntaxElement {
1616 }
1717}
1818
19- export abstract class DeclarationElement extends FoldableElement implements ScopeElement {
19+ export abstract class DeclarationElement extends ScopeElement {
2020 abstract identifier : IdentifierElement ;
21- abstract declaredNames : Map < string , BaseSyntaxElement > ;
2221
2322 constructor ( context : ProcedureDeclarationContext , document : TextDocument ) {
2423 super ( context , document ) ;
@@ -40,11 +39,13 @@ export abstract class DeclarationElement extends FoldableElement implements Scop
4039 }
4140
4241 const propertyDeclaration = new PropertyDeclarationElement ( context , document . textDocument ) ;
43- const predeclaredElement = document . currentScopeElement ?. declaredNames . get ( propertyDeclaration . identifier . text ) ;
44- if ( predeclaredElement && isPropertyDeclarationElement ( predeclaredElement ) ) {
45- predeclaredElement . addPropertyDeclaration ( context , document . textDocument ) ;
46- return predeclaredElement ;
47- }
42+ const predeclaredElements = document . currentScopeElement ?. declaredNames . get ( propertyDeclaration . identifier . text ) ;
43+ predeclaredElements ?. forEach ( predeclaredElement => {
44+ if ( predeclaredElement && isPropertyDeclarationElement ( predeclaredElement ) ) {
45+ predeclaredElement . addPropertyDeclaration ( context , document . textDocument ) ;
46+ return predeclaredElement ;
47+ }
48+ } ) ;
4849 return propertyDeclaration ;
4950 }
5051
@@ -53,7 +54,6 @@ export abstract class DeclarationElement extends FoldableElement implements Scop
5354export class SubDeclarationElement extends DeclarationElement implements HasSymbolInformation {
5455 identifier : IdentifierElement ;
5556 symbolInformation : SymbolInformation ;
56- declaredNames : Map < string , BaseSyntaxElement > = new Map ( ) ;
5757
5858 constructor ( context : ProcedureDeclarationContext , document : TextDocument , methodContext : SubroutineDeclarationContext ) {
5959 super ( context , document ) ;
@@ -72,7 +72,6 @@ export class SubDeclarationElement extends DeclarationElement implements HasSymb
7272export class FunctionDeclarationElement extends DeclarationElement implements HasSymbolInformation {
7373 identifier : IdentifierElement ;
7474 symbolInformation : SymbolInformation ;
75- declaredNames : Map < string , BaseSyntaxElement > = new Map ( ) ;
7675
7776 constructor ( context : ProcedureDeclarationContext , document : TextDocument , methodContext : FunctionDeclarationContext ) {
7877 super ( context , document ) ;
@@ -93,7 +92,6 @@ export class PropertyDeclarationElement extends DeclarationElement implements Ha
9392 getDeclarations : PropertyGetDeclarationElement [ ] = [ ] ;
9493 letDeclarations : PropertyLetDeclarationElement [ ] = [ ] ;
9594 setDeclarations : PropertyLetDeclarationElement [ ] = [ ] ;
96- declaredNames : Map < string , BaseSyntaxElement > = new Map ( ) ;
9795
9896 constructor ( context : ProcedureDeclarationContext , document : TextDocument ) {
9997 super ( context , document ) ;
@@ -126,7 +124,6 @@ export class PropertyDeclarationElement extends DeclarationElement implements Ha
126124
127125class PropertyGetDeclarationElement extends DeclarationElement {
128126 identifier : IdentifierElement ;
129- declaredNames : Map < string , BaseSyntaxElement > = new Map ( ) ;
130127
131128 constructor ( context : ProcedureDeclarationContext , document : TextDocument , getContext : PropertyGetDeclarationContext ) {
132129 super ( context , document ) ;
@@ -136,7 +133,6 @@ class PropertyGetDeclarationElement extends DeclarationElement {
136133
137134class PropertyLetDeclarationElement extends DeclarationElement {
138135 identifier : IdentifierElement ;
139- declaredNames : Map < string , BaseSyntaxElement > = new Map ( ) ;
140136
141137 constructor ( context : ProcedureDeclarationContext , document : TextDocument , setContext : PropertySetDeclarationContext ) {
142138 super ( context , document ) ;
@@ -146,18 +142,71 @@ class PropertyLetDeclarationElement extends DeclarationElement {
146142
147143class PropertySetDeclarationElement extends DeclarationElement {
148144 identifier : IdentifierElement ;
149- declaredNames : Map < string , BaseSyntaxElement > = new Map ( ) ;
150145
151146 constructor ( context : ProcedureDeclarationContext , document : TextDocument , setContext : PropertySetDeclarationContext ) {
152147 super ( context , document ) ;
153148 this . identifier = new IdentifierElement ( setContext . subroutineName ( ) ! . ambiguousIdentifier ( ) ! , document ) ;
154149 }
155150}
156151
157- function isPropertyDeclarationElement ( element : BaseSyntaxElement ) : element is PropertyDeclarationElement {
152+ function isPropertyDeclarationElement ( element : IdentifiableSyntaxElement ) : element is PropertyDeclarationElement {
158153 return 'getDeclarations' in element ;
159154}
160155
156+ abstract class BaseEnumDeclarationElement extends ScopeElement implements HasSemanticToken , HasSymbolInformation {
157+ identifier : IdentifierElement ;
158+ tokenModifiers : SemanticTokenModifiers [ ] = [ ] ;
159+ declaredNames : Map < string , EnumMemberDeclarationElement [ ] > = new Map ( ) ;
160+
161+ abstract tokenType : SemanticTokenTypes ;
162+ abstract symbolInformation : SymbolInformation ;
163+
164+ get name ( ) : string {
165+ return this . identifier . text ;
166+ }
167+
168+ constructor ( context : EnumDeclarationContext | EnumMemberContext , document : TextDocument ) {
169+ super ( context , document ) ;
170+ this . identifier = new IdentifierElement ( context . untypedName ( ) . ambiguousIdentifier ( ) ! , document ) ;
171+ }
172+
173+ }
174+
175+ export class EnumDeclarationElement extends BaseEnumDeclarationElement implements ScopeElement {
176+ tokenType : SemanticTokenTypes ;
177+
178+ constructor ( context : EnumDeclarationContext , document : TextDocument ) {
179+ super ( context , document ) ;
180+ this . tokenType = SemanticTokenTypes . enum ;
181+ this . identifier = new IdentifierElement ( context . untypedName ( ) . ambiguousIdentifier ( ) ! , document ) ;
182+ context . enumMemberList ( ) . enumElement ( ) . forEach ( enumElementContext =>
183+ this . _pushDeclaredName ( new EnumMemberDeclarationElement ( enumElementContext . enumMember ( ) ! , document ) )
184+ ) ;
185+ }
186+
187+ get symbolInformation ( ) : SymbolInformation {
188+ return SymbolInformationFactory . create (
189+ this , SymbolKind . Enum
190+ ) ;
191+ }
192+ }
193+
194+ class EnumMemberDeclarationElement extends BaseEnumDeclarationElement {
195+ tokenType : SemanticTokenTypes ;
196+
197+ constructor ( context : EnumMemberContext , document : TextDocument ) {
198+ super ( context , document ) ;
199+ this . tokenType = SemanticTokenTypes . enumMember ;
200+ this . identifier = new IdentifierElement ( context . untypedName ( ) . ambiguousIdentifier ( ) ! , document ) ;
201+ }
202+
203+ get symbolInformation ( ) : SymbolInformation {
204+ return SymbolInformationFactory . create (
205+ this , SymbolKind . EnumMember
206+ ) ;
207+ }
208+ }
209+
161210
162211// abstract class BaseEnumElement extends FoldableElement implements HasSemanticToken, HasSymbolInformation {
163212// identifier: IdentifierElement;
0 commit comments