Skip to content

Commit d8101e0

Browse files
committed
Added diagnostic to warn if non-latin characters found in class elements names
1 parent ef4f2f1 commit d8101e0

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

src/providers/ObjectScriptDiagnosticProvider.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export class ObjectScriptDiagnosticProvider {
1111
this._collection = vscode.languages.createDiagnosticCollection("ObjectScript");
1212
}
1313

14-
public updateDiagnostics(document: vscode.TextDocument) {
14+
public updateDiagnostics(document: vscode.TextDocument): void {
1515
if (document.languageId.startsWith("objectscript")) {
1616
this._collection.set(document.uri, [
1717
...this.classMembers(document),
@@ -47,7 +47,7 @@ export class ObjectScriptDiagnosticProvider {
4747
}
4848

4949
const memberMatch = text.match(
50-
/^(Class|Property|Relationship|Index|(?:(?:Client)?(?:Class)?Method)|ClientClassMethod|Method|XData|Query|Trigger|ForeignKey|Projection|Parameter)\s(\b[^ (]+\b)/i
50+
/^(Class|Property|Relationship|Index|(?:(?:Client)?(?:Class)?Method)|ClientClassMethod|Method|XData|Query|Trigger|ForeignKey|Projection|Parameter)\s((?:"[^"]+")|(?:[^ (;]+))/i
5151
);
5252
if (memberMatch) {
5353
const [fullMatch, type, name] = memberMatch;
@@ -72,6 +72,25 @@ export class ObjectScriptDiagnosticProvider {
7272
});
7373
}
7474
map.set(key, fullMatch);
75+
76+
let leftChars;
77+
if (!name.startsWith('"') && (leftChars = name.replace(/[%a-z0-9.]/gi, "")) && leftChars !== "") {
78+
const pos = line.text.indexOf(name);
79+
const range = new vscode.Range(new vscode.Position(i, pos), new vscode.Position(i, pos + name.length));
80+
result.push({
81+
code: "",
82+
message: "Non-latin characters",
83+
range,
84+
severity: vscode.DiagnosticSeverity.Warning,
85+
source: "",
86+
relatedInformation: [
87+
new vscode.DiagnosticRelatedInformation(
88+
new vscode.Location(document.uri, range),
89+
`Element name contains non-latin characters: ${leftChars}`
90+
),
91+
],
92+
});
93+
}
7594
}
7695
}
7796

0 commit comments

Comments
 (0)