11import { TextDocument } from 'vscode-languageserver-textdocument' ;
2- import { SymbolInformation , SymbolKind } from 'vscode-languageserver' ;
3- import { AttributeStmtContext , ModuleContext } from '../../antlr/out/vbaParser' ;
2+ import { Diagnostic , SymbolInformation , SymbolKind } from 'vscode-languageserver' ;
3+ import { AttributeStmtContext , ModuleContext , ModuleHeaderContext , ModuleOptionContext } from '../../antlr/out/vbaParser' ;
44
5- import { BaseContextSyntaxElement , HasAttribute , HasSymbolInformation } from './base' ;
5+ import { BaseContextSyntaxElement , HasAttribute , HasDiagnosticCapability , HasSymbolInformation } from './base' ;
66import { SymbolInformationFactory } from '../../capabilities/symbolInformation' ;
7+ import { MissingOptionExplicitDiagnostic } from '../../capabilities/diagnostics' ;
78
89
9- export class ModuleElement extends BaseContextSyntaxElement implements HasSymbolInformation , HasAttribute {
10+ export class ModuleElement extends BaseContextSyntaxElement implements HasSymbolInformation , HasAttribute , HasDiagnosticCapability {
1011 private _hasName = false ;
1112 private _name : string ;
1213 symbolKind : SymbolKind ;
14+ diagnostics : Diagnostic [ ] = [ ] ;
1315
1416 constructor ( context : ModuleContext , document : TextDocument , symbolKind : SymbolKind ) {
1517 super ( context , document ) ;
@@ -27,6 +29,32 @@ export class ModuleElement extends BaseContextSyntaxElement implements HasSymbol
2729 ) ;
2830 }
2931
32+ evaluateDiagnostics ( ) : void {
33+ const optionExplicitDiagnotic = this . _getOptionExplicitDiagnostic ( ) ;
34+ if ( optionExplicitDiagnotic ) {
35+ this . diagnostics . push ( optionExplicitDiagnotic ) ;
36+ }
37+ }
38+
39+ private _getOptionExplicitDiagnostic ( ) : Diagnostic | undefined {
40+ let optionExplicitFound = false ;
41+ const context = this . context as ModuleContext ;
42+ const declarations = context . moduleHeader ( ) . moduleDeclarations ( ) ?. moduleDeclarationsElement ( ) ;
43+
44+ if ( declarations ) {
45+ for ( const declaration of declarations ) {
46+ if ( ( declaration . moduleOption ( ) ?. text ?? '' ) === 'Option Explicit' ) {
47+ optionExplicitFound = true ;
48+ break ;
49+ }
50+ }
51+ }
52+
53+ return optionExplicitFound ? undefined : new MissingOptionExplicitDiagnostic (
54+ ( new ModuelHeaderElement ( context . moduleHeader ( ) , this . document ) ) . range
55+ ) ;
56+ }
57+
3058 processAttribute ( context : AttributeStmtContext ) : void {
3159 if ( this . _hasName ) {
3260 return ;
@@ -42,3 +70,9 @@ export class ModuleElement extends BaseContextSyntaxElement implements HasSymbol
4270 }
4371 }
4472}
73+
74+ class ModuelHeaderElement extends BaseContextSyntaxElement {
75+ constructor ( context : ModuleHeaderContext , document : TextDocument ) {
76+ super ( context , document ) ;
77+ }
78+ }
0 commit comments