11// Core
2- import { Range , SemanticTokenTypes } from 'vscode-languageserver' ;
32import { TextDocument } from 'vscode-languageserver-textdocument' ;
43
54// Antlr
6- import { ParserRuleContext } from 'antlr4ng' ;
75import { CompilerConditionalBlockContext , CompilerDefaultBlockContext , CompilerIfBlockContext } from '../../antlr/out/vbapreParser' ;
86
97// Project
10- import { SemanticTokenCapability } from '../../capabilities/capabilities' ;
11- import { BaseContextSyntaxElement , HasSemanticTokenCapability } from '../elements/base' ;
8+ import { DiagnosticCapability } from '../../capabilities/capabilities' ;
9+ import { BaseContextSyntaxElement } from '../elements/base' ;
10+ import { UnreachableCodeDiagnostic } from '../../capabilities/diagnostics' ;
1211
1312
1413export class CompilerLogicalBlock extends BaseContextSyntaxElement < CompilerIfBlockContext > {
@@ -29,6 +28,7 @@ export class CompilerLogicalBlock extends BaseContextSyntaxElement<CompilerIfBlo
2928 resolved = true ;
3029 continue ;
3130 }
31+ block . deactivate ( ) ;
3232 this . inactiveBlocks . push ( block ) ;
3333 }
3434 }
@@ -47,31 +47,6 @@ class CompilerConditionBlock extends BaseContextSyntaxElement<CompilerConditiona
4747 return this . context . rule . compilerBlockContent ( ) ?. getText ( ) . split ( '\n' ) ?? [ ] ;
4848 }
4949
50- get linesToComments ( ) : GenericCommentElement [ ] {
51- const rowX = this . context . range . start . line ;
52- const rowY = this . context . range . end . line ;
53-
54- // Iterate the rows -- test what happens when you get to the end of the document.
55- // May require a try catch where the default offset is the character count of the document.
56- const result : GenericCommentElement [ ] = [ ] ;
57- for ( let i = rowX ; i < rowY ; i ++ ) {
58- const posX = this . context . document . offsetAt ( { line : i , character : 0 } ) ;
59- const posY = this . context . document . offsetAt ( { line : i + 1 , character : 0 } ) - 1 ;
60-
61- const lineRange = Range . create (
62- this . context . document . positionAt ( posX ) ,
63- this . context . document . positionAt ( posY )
64- ) ;
65- result . push ( new GenericCommentElement (
66- this . context . rule ,
67- this . context . document ,
68- lineRange )
69- ) ;
70- }
71-
72- return result ;
73- }
74-
7550 get conditionResult ( ) : boolean {
7651 // Default "Else" block is always true.
7752 const ctx = this . context . rule ;
@@ -90,6 +65,11 @@ class CompilerConditionBlock extends BaseContextSyntaxElement<CompilerConditiona
9065 return result ;
9166 }
9267
68+ deactivate ( ) : void {
69+ this . diagnosticCapability = new DiagnosticCapability ( this ) ;
70+ this . diagnosticCapability . diagnostics . push ( new UnreachableCodeDiagnostic ( this . context . range ) )
71+ }
72+
9373 /** Transpiles a VBA expression into Typescript. */
9474 private transpileVbaToTypescript ( exp : string ) : string {
9575 // Convert the environment constant to boolean.
@@ -118,14 +98,3 @@ class CompilerConditionBlock extends BaseContextSyntaxElement<CompilerConditiona
11898 return result ;
11999 }
120100}
121-
122-
123- export class GenericCommentElement extends BaseContextSyntaxElement < ParserRuleContext > implements HasSemanticTokenCapability {
124- semanticTokenCapability : SemanticTokenCapability ;
125-
126- constructor ( ctx : ParserRuleContext , doc : TextDocument , range ?: Range ) {
127- super ( ctx , doc ) ;
128- const textLen = range ? doc . offsetAt ( range . end ) - doc . offsetAt ( range . start ) + 1 : undefined ;
129- this . semanticTokenCapability = new SemanticTokenCapability ( this , SemanticTokenTypes . comment , [ ] , range , textLen )
130- }
131- }
0 commit comments