Skip to content

Commit 12330b2

Browse files
committed
some changes in diagnostic provider
1 parent dabd8c7 commit 12330b2

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed

src/providers/ObjectScriptDiagnosticProvider.ts

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,42 @@ export class ObjectScriptDiagnosticProvider {
2626

2727
private commands(document: vscode.TextDocument): vscode.Diagnostic[] {
2828
const result = new Array<vscode.Diagnostic>();
29+
const isClass = document.fileName.toLowerCase().endsWith(".cls");
2930

31+
let inComment = false;
32+
let endingComma = false;
33+
let isCode = !isClass;
3034
for (let i = 0; i < document.lineCount; i++) {
3135
const line = document.lineAt(i);
3236
const text = this.stripLineComments(line.text);
3337

38+
if (text.match(/\/\*/)) {
39+
inComment = true;
40+
}
41+
42+
if (inComment) {
43+
if (text.match(/\*\//)) {
44+
inComment = false;
45+
}
46+
continue;
47+
}
48+
if (endingComma) {
49+
endingComma = text.match(/,\s*$/) !== null;
50+
continue;
51+
}
52+
endingComma = text.match(/,\s*$/) !== null;
53+
if (isClass) {
54+
if (isCode) {
55+
isCode = text.match(/^}$/) === null;
56+
} else {
57+
isCode = text.match(/^(class)?method|trigger/i) != null;
58+
continue;
59+
}
60+
}
61+
if (!isCode) {
62+
continue;
63+
}
64+
3465
const commandsMatch = text.match(/^\s+(?:}\s)?\b([a-z]+)\b/i);
3566
if (commandsMatch) {
3667
const [, found] = commandsMatch;
@@ -60,10 +91,37 @@ export class ObjectScriptDiagnosticProvider {
6091
private functions(document: vscode.TextDocument): vscode.Diagnostic[] {
6192
const result = new Array<vscode.Diagnostic>();
6293

94+
const isClass = document.fileName.toLowerCase().endsWith(".cls");
95+
96+
let inComment = false;
97+
let isCode = !isClass;
6398
for (let i = 0; i < document.lineCount; i++) {
6499
const line = document.lineAt(i);
65100
const text = this.stripLineComments(line.text);
66101

102+
if (text.match(/\/\*/)) {
103+
inComment = true;
104+
}
105+
106+
if (inComment) {
107+
if (text.match(/\*\//)) {
108+
inComment = false;
109+
}
110+
continue;
111+
}
112+
113+
if (isClass) {
114+
if (isCode) {
115+
isCode = text.match(/^}$/) === null;
116+
} else {
117+
isCode = text.match(/^(class)?method|trigger/i) != null;
118+
continue;
119+
}
120+
}
121+
if (!isCode) {
122+
continue;
123+
}
124+
67125
const pattern = /(?<!\$)(\$\b[a-z]+)\b/gi;
68126
let functionsMatch = null;
69127
while ((functionsMatch = pattern.exec(text)) !== null) {

0 commit comments

Comments
 (0)