Skip to content

Commit 1701341

Browse files
authored
Merge pull request #180 from intersystems-community/#112-diagnostic-non-latin
Added diagnostic to warn if non-latin characters found in class elements
2 parents e42529e + d8101e0 commit 1701341

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

src/providers/ObjectScriptDiagnosticProvider.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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)