Skip to content

Commit 4b48de1

Browse files
committed
error when duplication of members names in class closes #63
1 parent 7eb49a5 commit 4b48de1

File tree

3 files changed

+71
-2
lines changed

3 files changed

+71
-2
lines changed

src/api/index.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import * as url from "url";
55
import * as vscode from "vscode";
66
import * as Cache from "vscode-cache";
77
import { config, extensionContext, FILESYSTEM_SCHEMA, workspaceState } from "../extension";
8-
import { currentWorkspaceFolder, outputConsole } from "../utils";
8+
import { currentWorkspaceFolder, outputConsole, outputChannel } from "../utils";
99

1010
const DEFAULT_API_VERSION = 1;
1111
// require("request-promise").debug = true;
@@ -178,6 +178,10 @@ export class AtelierAPI {
178178
if (data.console) {
179179
outputConsole(data.console);
180180
}
181+
if (data.result.status && data.result.status !== "") {
182+
outputChannel.appendLine(data.result.status);
183+
throw new Error(data.result.status);
184+
}
181185
if (data.status.summary) {
182186
throw new Error(data.status.summary);
183187
} else if (data.result.status) {

src/commands/compile.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ export async function importAndCompile(askFLags = false): Promise<any> {
100100
return importFile(file)
101101
.catch(error => {
102102
// console.error(error);
103+
throw error;
103104
})
104105
.then(() => compile([file], flags));
105106
}

src/providers/ObjectScriptDiagnosticProvider.ts

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,74 @@ export class ObjectScriptDiagnosticProvider {
1313

1414
public updateDiagnostics(document: vscode.TextDocument) {
1515
if (document.languageId.startsWith("objectscript")) {
16-
this._collection.set(document.uri, [...this.commands(document), ...this.functions(document)]);
16+
this._collection.set(document.uri, [
17+
...this.classMembers(document),
18+
...this.commands(document),
19+
...this.functions(document),
20+
]);
1721
}
1822
}
1923

24+
private classMembers(document: vscode.TextDocument): vscode.Diagnostic[] {
25+
const result = new Array<vscode.Diagnostic>();
26+
const isClass = document.fileName.toLowerCase().endsWith(".cls");
27+
if (!isClass) {
28+
return [];
29+
}
30+
31+
const map = new Map<string, string>();
32+
let inComment = false;
33+
34+
for (let i = 0; i < document.lineCount; i++) {
35+
const line = document.lineAt(i);
36+
const text = this.stripLineComments(line.text);
37+
38+
if (text.match(/\/\*/)) {
39+
inComment = true;
40+
}
41+
42+
if (inComment) {
43+
if (text.match(/\*\//)) {
44+
inComment = false;
45+
}
46+
continue;
47+
}
48+
49+
const memberMatch = text.match(
50+
/^(Class|Property|Relationship|Index|ClassMethod|Method|XData|Query|Trigger|ForeignKey|Projection|Parameter)\s(\b[^ (]+\b)/i
51+
);
52+
if (memberMatch) {
53+
const [fullMatch, type, name] = memberMatch;
54+
const simpleType = type
55+
.toLowerCase()
56+
.replace("classmethod", "method")
57+
.replace("relationship", "property");
58+
const key = simpleType === "class" ? simpleType : [simpleType, name].join(":");
59+
if (map.has(key)) {
60+
const original = map.get(key);
61+
const pos = line.text.indexOf(name);
62+
const range = new vscode.Range(new vscode.Position(i, pos), new vscode.Position(i, pos + name.length));
63+
result.push({
64+
code: "",
65+
message: "Element name conflict",
66+
range,
67+
severity: vscode.DiagnosticSeverity.Error,
68+
source: "",
69+
relatedInformation: [
70+
new vscode.DiagnosticRelatedInformation(
71+
new vscode.Location(document.uri, range),
72+
`'${original}' already defined earlier`
73+
),
74+
],
75+
});
76+
}
77+
map.set(key, fullMatch);
78+
}
79+
}
80+
81+
return result;
82+
}
83+
2084
private stripLineComments(text: string) {
2185
text = text.replace(/\/\/.*$/, "");
2286
text = text.replace(/#+;.*$/, "");

0 commit comments

Comments
 (0)