Skip to content

#97 resolved diagnostic issue in html style block #179

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 7, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 24 additions & 10 deletions src/providers/ObjectScriptDiagnosticProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export class ObjectScriptDiagnosticProvider {
this._collection = vscode.languages.createDiagnosticCollection("ObjectScript");
}

public updateDiagnostics(document: vscode.TextDocument) {
public updateDiagnostics(document: vscode.TextDocument): void {
if (document.languageId.startsWith("objectscript")) {
this._collection.set(document.uri, [
...this.classMembers(document),
Expand Down Expand Up @@ -100,6 +100,8 @@ export class ObjectScriptDiagnosticProvider {
let isCode = !isClass;
let jsScript = false;
let js = false;
let html = false;
let htmlParens = 0;
let jsParens = 0;
let sql = false;
let sqlParens = 0;
Expand All @@ -111,21 +113,40 @@ export class ObjectScriptDiagnosticProvider {

// it is important to check script tag context before ObjectScript comments
// since /* ... */ comments can also be used in JavaScript
if (text.match(/<script .*>/i)) {
if (text.match(/<script.*>/i)) {
jsScript = true;
}
if (jsScript) {
if (text.match(/<\/script>/i)) {
jsScript = false;
}
continue;
}

if (text.match(/&js(cript)?/i)) {
js = true;
jsParens = 0;
}
if (js) {
jsParens = jsParens + (text.split("<").length - 1) - (text.split(">").length - 1);
let noParensText = text;
while (noParensText != (noParensText = noParensText.replace(/\([^()]*\)/g, "")));
jsParens = jsParens + (noParensText.split("<").length - 1) - (noParensText.split(">").length - 1);
if (jsParens <= 0) {
js = false;
}
continue;
}
if (text.match(/&html/i)) {
html = true;
htmlParens = 0;
}
if (html) {
htmlParens = htmlParens + (text.split("<").length - 1) - (text.split(">").length - 1);
if (htmlParens <= 0) {
html = false;
}
continue;
}

if (text.match(/(?:&|##)sql/i)) {
sql = true;
Expand All @@ -140,13 +161,6 @@ export class ObjectScriptDiagnosticProvider {
continue;
}

if (jsScript) {
if (text.match(/<\/script>/i)) {
jsScript = false;
}
continue;
}

if (text.match(/\/\*/)) {
inComment = true;
}
Expand Down