Skip to content

Commit 5c77663

Browse files
committed
fixed diagnostic error, for values in quotes, fixes #64
1 parent 93cda6e commit 5c77663

File tree

2 files changed

+30
-5
lines changed

2 files changed

+30
-5
lines changed

src/providers/ObjectScriptDiagnosticProvider.ts

+13-3
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,15 @@ export class ObjectScriptDiagnosticProvider {
8585
text = text.replace(/\/\/.*$/, "");
8686
text = text.replace(/#+;.*$/, "");
8787
text = text.replace(/;.*$/, "");
88+
text = text.replace(/\/\*.*(?=\*\/)\*\//g, e => e.replace(/./g, " "));
8889
return text;
8990
}
9091

92+
/// replace value in double quotes by spaces
93+
private stripQuoted(text: string) {
94+
return text.replace(/"(?:.*(?="")"")*[^"]*"/g, e => '"' + e.replace(/./g, " ").slice(2) + '"');
95+
}
96+
9197
private commands(document: vscode.TextDocument): vscode.Diagnostic[] {
9298
const result = new Array<vscode.Diagnostic>();
9399
const isClass = document.fileName.toLowerCase().endsWith(".cls");
@@ -102,7 +108,9 @@ export class ObjectScriptDiagnosticProvider {
102108
let sqlParens = 0;
103109
for (let i = 0; i < document.lineCount; i++) {
104110
const line = document.lineAt(i);
105-
const text = this.stripLineComments(line.text);
111+
let text = line.text;
112+
text = this.stripLineComments(text);
113+
text = this.stripQuoted(text);
106114

107115
// it is important to check script tag context before ObjectScript comments
108116
// since /* ... */ comments can also be used in JavaScript
@@ -205,7 +213,9 @@ export class ObjectScriptDiagnosticProvider {
205213
let isCode = !isClass;
206214
for (let i = 0; i < document.lineCount; i++) {
207215
const line = document.lineAt(i);
208-
const text = this.stripLineComments(line.text);
216+
let text = line.text;
217+
text = this.stripLineComments(text);
218+
text = this.stripQuoted(text);
209219

210220
if (text.match(/\/\*/)) {
211221
inComment = true;
@@ -230,7 +240,7 @@ export class ObjectScriptDiagnosticProvider {
230240
continue;
231241
}
232242

233-
const pattern = /(?<!\$)(\$\b[a-z]+)\b/gi;
243+
const pattern = /(?<!\$)(\$[a-z]+)/gi;
234244
let functionsMatch = null;
235245
while ((functionsMatch = pattern.exec(text)) !== null) {
236246
const [, found] = functionsMatch;

src/utils/index.ts

+17-2
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,19 @@ export function portFromDockerCompose(): { port: number; docker: boolean } {
139139
if (!internalPort || !file || !service || service === "") {
140140
return result;
141141
}
142-
const cwd = workspaceFolderUri().fsPath;
142+
const workspaceFolderPath = workspaceFolderUri().fsPath;
143+
const workspaceRootPath = vscode.workspace.workspaceFolders[0].uri.fsPath;
144+
145+
const cwd = fs.existsSync(path.join(workspaceFolderPath, file))
146+
? workspaceFolderPath
147+
: fs.existsSync(path.join(workspaceRootPath, file))
148+
? workspaceRootPath
149+
: null;
150+
151+
if (!cwd) {
152+
return result;
153+
}
154+
143155
const cmd = `docker-compose -f ${file} port --protocol=tcp ${service} ${internalPort}`;
144156
try {
145157
const serviceLine = execSync(cmd, {
@@ -169,15 +181,18 @@ export function terminalWithDocker() {
169181
const terminalName = `ObjectScript:${workspace}`;
170182
let terminal = vscode.window.terminals.find(el => el.name === terminalName);
171183
if (!terminal) {
184+
outputChannel.appendLine("Open terminal");
172185
terminal = vscode.window.createTerminal(terminalName, "docker-compose", [
173186
"-f",
174187
file,
175188
"exec",
176189
service,
177190
"/bin/bash",
178191
"-c",
179-
`command -v ccontrol >/dev/null 2>&1 && ccontrol session $ISC_PACKAGE_INSTANCENAME -U ${ns} || iris session $ISC_PACKAGE_INSTANCENAME -U ${ns}`,
192+
`command -v ccontrol >/dev/null 2>&1 && (ccontrol session $ISC_PACKAGE_INSTANCENAME -U ${ns} || iris session $ISC_PACKAGE_INSTANCENAME -U ${ns})`,
180193
]);
194+
} else {
195+
outputChannel.appendLine("terminal already exists");
181196
}
182197
terminal.show();
183198
return terminal;

0 commit comments

Comments
 (0)