Skip to content

Commit b6dc2c4

Browse files
committed
Upgrade to antlr4ng. Everything is broken!
1 parent 29eb283 commit b6dc2c4

File tree

11 files changed

+535
-292
lines changed

11 files changed

+535
-292
lines changed

server/src/capabilities/semanticTokens.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export class SemanticToken {
4949
element,
5050
element.identifier.range.start.line,
5151
element.identifier.range.start.character,
52-
element.identifier.context.text.length,
52+
element.identifier.context.getText().length,
5353
element.tokenType,
5454
element.tokenModifiers
5555
);

server/src/extensions/parserExtensions.ts

Lines changed: 34 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { Range, SymbolKind } from 'vscode-languageserver';
2-
import { BaseTypeContext, ComplexTypeContext } from '../antlr/out/vbaParser';
32
import { TextDocument } from 'vscode-languageserver-textdocument';
43
// import { ParserRuleContext } from 'antlr4ts';
54

@@ -21,44 +20,44 @@ import { TextDocument } from 'vscode-languageserver-textdocument';
2120
// };
2221

2322

24-
declare module '../antlr/out/vbaParser' {
25-
export interface BaseTypeContext {
26-
toSymbolKind(): SymbolKind;
27-
}
23+
// declare module '../antlr/out/vbaParser' {
24+
// export interface BaseTypeContext {
25+
// toSymbolKind(): SymbolKind;
26+
// }
2827

29-
export interface ComplexTypeContext {
30-
toSymbolKind(): SymbolKind;
31-
}
32-
}
28+
// export interface ComplexTypeContext {
29+
// toSymbolKind(): SymbolKind;
30+
// }
31+
// }
3332

34-
BaseTypeContext.prototype.toSymbolKind = function (): SymbolKind {
35-
return toSymbolKind(this);
36-
};
33+
// BaseTypeContext.prototype.toSymbolKind = function (): SymbolKind {
34+
// return toSymbolKind(this);
35+
// };
3736

38-
ComplexTypeContext.prototype.toSymbolKind = function (): SymbolKind {
39-
return toSymbolKind(this);
40-
};
37+
// ComplexTypeContext.prototype.toSymbolKind = function (): SymbolKind {
38+
// return toSymbolKind(this);
39+
// };
4140

42-
function toSymbolKind(context: BaseTypeContext | ComplexTypeContext): SymbolKind {
43-
switch (context.text.toLocaleLowerCase()) {
44-
case 'boolean':
45-
return SymbolKind.Boolean;
46-
case 'byte':
47-
case 'string':
48-
return SymbolKind.String;
49-
case 'double':
50-
case 'currency':
51-
case 'integer':
52-
case 'long':
53-
case 'longPtr':
54-
case 'longLong':
55-
return SymbolKind.Number;
56-
case 'object':
57-
return SymbolKind.Object;
58-
default:
59-
return SymbolKind.Class;
60-
}
61-
}
41+
// function toSymbolKind(context: BaseTypeContext | ComplexTypeContext): SymbolKind {
42+
// switch (context.text.toLocaleLowerCase()) {
43+
// case 'boolean':
44+
// return SymbolKind.Boolean;
45+
// case 'byte':
46+
// case 'string':
47+
// return SymbolKind.String;
48+
// case 'double':
49+
// case 'currency':
50+
// case 'integer':
51+
// case 'long':
52+
// case 'longPtr':
53+
// case 'longLong':
54+
// return SymbolKind.Number;
55+
// case 'object':
56+
// return SymbolKind.Object;
57+
// default:
58+
// return SymbolKind.Class;
59+
// }
60+
// }
6261

6362
/**
6463
* const File: 1;

server/src/project/document.ts

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { CancellationToken, Diagnostic, LSPErrorCodes, PublishDiagnosticsParams, ResponseError, SemanticTokens, SymbolInformation, SymbolKind } from 'vscode-languageserver';
22
import { Workspace } from './workspace';
33
import { FoldableElement } from './elements/special';
4-
import { BaseSyntaxElement, HasAttribute, HasDiagnosticCapability, HasSemanticToken, HasSymbolInformation } from './elements/base';
4+
import { BaseSyntaxElement, HasDiagnosticCapability, HasSemanticToken, HasSymbolInformation, ScopeElement } from './elements/base';
55
import { Range, TextDocument } from 'vscode-languageserver-textdocument';
66
import { SyntaxParser } from './parser/vbaSyntaxParser';
77
import { FoldingRange } from '../capabilities/folding';
@@ -10,18 +10,18 @@ import { sleep } from '../utils/helpers';
1010

1111

1212
export abstract class BaseProjectDocument {
13+
readonly name: string;
1314
readonly workspace: Workspace;
1415
readonly textDocument: TextDocument;
15-
readonly name: string;
1616

17+
protected _hasDiagnosticElements: HasDiagnosticCapability[] = [];
1718
protected _unhandledNamedElements: [] = [];
1819
protected _publicScopeDeclarations: Map<string, any> = new Map();
1920
protected _documentScopeDeclarations: Map<string, Map<string, any>> = new Map();
20-
protected _hasDiagnosticElements: HasDiagnosticCapability[] = [];
2121

2222
protected _diagnostics: Diagnostic[] = [];
23-
protected _elementParents: BaseSyntaxElement[] = [];
24-
protected _attributeElements: HasAttribute[] = [];
23+
protected _elementParents: ScopeElement[] = [];
24+
// protected _attributeElements: HasAttribute[] = [];
2525
protected _foldableElements: FoldingRange[] = [];
2626
protected _symbolInformations: SymbolInformation[] = [];
2727
protected _semanticTokens: SemanticTokensManager = new SemanticTokensManager();
@@ -33,10 +33,14 @@ export abstract class BaseProjectDocument {
3333
return this._isBusy;
3434
}
3535

36-
get activeAttributeElement() {
37-
return this._attributeElements?.at(-1);
36+
get currentScopeElement() {
37+
return this._elementParents[-1];
3838
}
3939

40+
// get activeAttributeElement() {
41+
// return this._attributeElements?.at(-1);
42+
// }
43+
4044
constructor(workspace: Workspace, name: string, document: TextDocument) {
4145
this.textDocument = document;
4246
this.workspace = workspace;
@@ -121,10 +125,10 @@ export abstract class BaseProjectDocument {
121125
* @param element the element to register.
122126
* @returns nothing of interest.
123127
*/
124-
registerAttributeElement = (element: HasAttribute) => {
125-
this._attributeElements.push(element);
126-
return this;
127-
};
128+
// registerAttributeElement = (element: HasAttribute) => {
129+
// this._attributeElements.push(element);
130+
// return this;
131+
// };
128132

129133
/**
130134
* Pops an element from the attribute elements stack.
@@ -133,9 +137,9 @@ export abstract class BaseProjectDocument {
133137
* @param element the element to register.
134138
* @returns the element at the end of the stack.
135139
*/
136-
deregisterAttributeElement = () => {
137-
return this._attributeElements.pop();
138-
};
140+
// deregisterAttributeElement = () => {
141+
// return this._attributeElements.pop();
142+
// };
139143

140144
registerFoldableElement = (element: FoldableElement) => {
141145
this._foldableElements.push(new FoldingRange(element));
@@ -153,7 +157,7 @@ export abstract class BaseProjectDocument {
153157
* @param element the element to register.
154158
* @returns this for chaining.
155159
*/
156-
registerScopedElement(element: BaseSyntaxElement) {
160+
registerScopedElement(element: ScopeElement) {
157161
this._elementParents.push(element);
158162
return this;
159163
}

server/src/project/elements/base.ts

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
import { ParserRuleContext } from 'antlr4ts';
1+
import { ParserRuleContext } from 'antlr4ng';
22
import { Diagnostic, Range, SemanticTokenModifiers, SemanticTokenTypes, SymbolInformation, SymbolKind } from 'vscode-languageserver';
33
import { Position, TextDocument } from 'vscode-languageserver-textdocument';
44
import { FoldingRangeKind } from '../../capabilities/folding';
55
import { IdentifierElement } from './memory';
6-
import { AttributeStmtContext } from '../../antlr/out/vbaParser';
76
import '../../extensions/parserExtensions';
87

98
export interface ContextOptionalSyntaxElement {
@@ -26,10 +25,6 @@ export interface HasDiagnosticCapability {
2625
evaluateDiagnostics(): void;
2726
}
2827

29-
export interface HasAttribute {
30-
processAttribute(context: AttributeStmtContext): void;
31-
}
32-
3328
export interface NamedSyntaxElement extends SyntaxElement {
3429
get name(): string;
3530
}
@@ -58,14 +53,18 @@ export interface FoldingRangeElement {
5853
foldingRangeKind?: FoldingRangeKind;
5954
}
6055

56+
export interface ScopeElement {
57+
declaredNames: Map<string, BaseSyntaxElement>;
58+
}
59+
6160
export abstract class BaseSyntaxElement implements ContextOptionalSyntaxElement {
6261
protected document: TextDocument;
6362

6463
range?: Range;
6564
parent?: ContextOptionalSyntaxElement;
6665
context?: ParserRuleContext;
6766

68-
get text(): string { return this.context?.text ?? ''; }
67+
get text(): string { return this.context?.getText() ?? ''; }
6968
get uri(): string { return this.document.uri; }
7069

7170
constructor(context: ParserRuleContext | undefined, document: TextDocument) {
@@ -91,8 +90,8 @@ export abstract class BaseSyntaxElement implements ContextOptionalSyntaxElement
9190
return;
9291
}
9392

94-
const startIndex = this.context.start.startIndex;
95-
const stopIndex = this.context.stop?.stopIndex ?? startIndex;
93+
const startIndex = this.context?.start?.start ?? 0;
94+
const stopIndex = this.context.stop?.stop ?? startIndex;
9695
return Range.create(
9796
this.document.positionAt(startIndex),
9897
this.document.positionAt(stopIndex + 1)
@@ -107,4 +106,4 @@ export abstract class BaseContextSyntaxElement extends BaseSyntaxElement {
107106
constructor(ctx: ParserRuleContext, doc: TextDocument) {
108107
super(ctx, doc);
109108
}
110-
}
109+
}
Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
import { ParserRuleContext } from 'antlr4ts';
1+
import { ParserRuleContext } from 'antlr4ng';
22
import { BaseContextSyntaxElement, HasDiagnosticCapability } from './base';
33
import { TextDocument } from 'vscode-languageserver-textdocument';
4-
import { ValueStmtContext, WhileWendStmtContext } from '../../antlr/out/vbaParser';
54
import { Diagnostic } from 'vscode-languageserver';
65
import { WhileWendDeprecatedDiagnostic } from '../../capabilities/diagnostics';
76

@@ -13,22 +12,22 @@ class BaseLoopElement extends BaseContextSyntaxElement {
1312
}
1413

1514

16-
export class WhileWendLoopElement extends BaseLoopElement implements HasDiagnosticCapability {
17-
diagnostics: Diagnostic[] = [];
18-
valueStatement: ValueStatementElement;
15+
// export class WhileWendLoopElement extends BaseLoopElement implements HasDiagnosticCapability {
16+
// diagnostics: Diagnostic[] = [];
17+
// valueStatement: ValueStatementElement;
1918

20-
constructor(context: WhileWendStmtContext, document: TextDocument) {
21-
super(context, document);
22-
this.valueStatement = new ValueStatementElement(context.valueStmt(), document);
23-
}
19+
// constructor(context: WhileWendStmtContext, document: TextDocument) {
20+
// super(context, document);
21+
// this.valueStatement = new ValueStatementElement(context.valueStmt(), document);
22+
// }
2423

25-
evaluateDiagnostics(): void {
26-
this.diagnostics.push(new WhileWendDeprecatedDiagnostic(this.valueStatement.range));
27-
}
28-
}
24+
// evaluateDiagnostics(): void {
25+
// this.diagnostics.push(new WhileWendDeprecatedDiagnostic(this.valueStatement.range));
26+
// }
27+
// }
2928

30-
class ValueStatementElement extends BaseContextSyntaxElement {
31-
constructor(context: ValueStmtContext, document: TextDocument) {
32-
super(context, document);
33-
}
34-
}
29+
// class ValueStatementElement extends BaseContextSyntaxElement {
30+
// constructor(context: ValueStmtContext, document: TextDocument) {
31+
// super(context, document);
32+
// }
33+
// }

0 commit comments

Comments
 (0)