Skip to content

Commit 49bc685

Browse files
authored
Merge pull request #198 from intersystems-community/names_diagnostic
Underline as an error member`s names which contains not valid characters, class without package
2 parents 7b8bf02 + 1848511 commit 49bc685

File tree

1 file changed

+54
-1
lines changed

1 file changed

+54
-1
lines changed

src/providers/ObjectScriptDiagnosticProvider.ts

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ export class ObjectScriptDiagnosticProvider {
4545
}
4646
continue;
4747
}
48+
let skipNonLatin = false;
4849

4950
const memberMatch = text.match(
5051
/^(Class|Property|Relationship|Index|(?:(?:Client)?(?:Class)?Method)|ClientClassMethod|Method|XData|Query|Trigger|ForeignKey|Projection|Parameter)\s((?:"[^"]+")|(?:[^ (;]+))/i
@@ -53,6 +54,53 @@ export class ObjectScriptDiagnosticProvider {
5354
const [fullMatch, type, name] = memberMatch;
5455
const simpleType = type.toLowerCase().replace("classmethod", "method").replace("relationship", "property");
5556
const key = simpleType === "class" ? simpleType : [simpleType, name].join(":");
57+
if (simpleType === "class") {
58+
if (!name.includes(".")) {
59+
const pos = line.text.indexOf(name);
60+
const range = new vscode.Range(new vscode.Position(i, pos), new vscode.Position(i, pos + name.length));
61+
result.push({
62+
code: "",
63+
message: "Class name is invalid",
64+
range,
65+
severity: vscode.DiagnosticSeverity.Error,
66+
source: "",
67+
relatedInformation: [
68+
new vscode.DiagnosticRelatedInformation(
69+
new vscode.Location(document.uri, range),
70+
`Class name '${name}' should have a package name prefix`
71+
),
72+
],
73+
});
74+
}
75+
}
76+
const notValid =
77+
simpleType !== "class" && name.startsWith('"') && name.endsWith('"')
78+
? simpleType !== "class" && name.includes(".")
79+
? "."
80+
: ""
81+
: name[0].replace(/[^\x21-\x2F\x3A-\x40\x5B-\x60\x7B-\x7E0-9]|%/g, "") +
82+
name
83+
.slice(1)
84+
.replace(simpleType === "class" ? "." : "", "")
85+
.replace(/[^\x21-\x2F\x3A-\x40\x5B-\x60\x7B-\x7E]/g, "");
86+
if (notValid !== "") {
87+
const pos = line.text.indexOf(name);
88+
const range = new vscode.Range(new vscode.Position(i, pos), new vscode.Position(i, pos + name.length));
89+
result.push({
90+
code: "",
91+
message: "Name is invalid",
92+
range,
93+
severity: vscode.DiagnosticSeverity.Error,
94+
source: "",
95+
relatedInformation: [
96+
new vscode.DiagnosticRelatedInformation(
97+
new vscode.Location(document.uri, range),
98+
`'${fullMatch}' contains invalid characters '${notValid}'`
99+
),
100+
],
101+
});
102+
skipNonLatin = true;
103+
}
56104
if (map.has(key)) {
57105
const original = map.get(key);
58106
const pos = line.text.indexOf(name);
@@ -74,7 +122,12 @@ export class ObjectScriptDiagnosticProvider {
74122
map.set(key, fullMatch);
75123

76124
let leftChars;
77-
if (!name.startsWith('"') && (leftChars = name.replace(/[%a-z0-9.]/gi, "")) && leftChars !== "") {
125+
if (
126+
!skipNonLatin &&
127+
!name.startsWith('"') &&
128+
(leftChars = name.replace(/[%a-z0-9.]/gi, "")) &&
129+
leftChars !== ""
130+
) {
78131
const pos = line.text.indexOf(name);
79132
const range = new vscode.Range(new vscode.Position(i, pos), new vscode.Position(i, pos + name.length));
80133
result.push({

0 commit comments

Comments
 (0)