Skip to content

Commit

Permalink
Сворачивание кода для директив СППР
Browse files Browse the repository at this point in the history
  • Loading branch information
lintest committed Feb 26, 2023
1 parent 9eb6c58 commit f78c3e3
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 9 deletions.
3 changes: 3 additions & 0 deletions src/languages/turbo-gherkin/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ export enum VAToken {
Asterisk,
StartComment,
EndComment,
DirectIf,
DirectElse,
DirectEndif,
}

export interface VAIndent {
Expand Down
7 changes: 7 additions & 0 deletions src/languages/turbo-gherkin/folding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ export function getCodeFolding(
let kind = undefined;
const line = model.getLineToken(i);
switch (model.getLineToken(i).token) {
case VAToken.DirectIf:
case VAToken.DirectElse:
for (let j = i + 1; j <= lineCount; j++) {
const next = model.getLineToken(j);
if (next.indent <= line.indent) break; else k = j;
}
break;
case VAToken.Instruction:
for (let j = i + 1; j <= lineCount; j++) {
const next = model.getLineToken(j);
Expand Down
44 changes: 35 additions & 9 deletions src/languages/turbo-gherkin/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,16 @@ function getIndent(text: string, tabSize: number) {
}

function getToken(text: string, sppr: boolean, direct: IDirectExp) {
if (/^\s*$/.test(text)) return VAToken.Empty;
if (sppr) {
if (/^\s*\/\*.*$/.test(text)) return VAToken.StartComment;
if (/^.*\*\/\s*/.test(text)) return VAToken.EndComment;
}
if (/^\s*$/.test(text)) return VAToken.Empty;
if (direct) {
if (direct.if && direct.if.test(text)) return VAToken.DirectIf;
if (direct.else && direct.else.test(text)) return VAToken.DirectElse;
if (direct.endif && direct.endif.test(text)) return VAToken.DirectEndif;
}
if (/^[\s]*@/.test(text)) return VAToken.Instruction;
if (/^[\s]*\|/.test(text)) return VAToken.Parameter;
if (/^[\s]*[#|//]/.test(text)) return VAToken.Comment;
Expand All @@ -32,6 +37,7 @@ export function getModelTokens(
tabSize: number,
): Array<VAIndent> {
const tokens: Array<VAIndent> = [];
let directIndent = 0;
let multilineParam = false;
let multilineComment = false;
const lineCount = model.getLineCount();
Expand All @@ -57,14 +63,34 @@ export function getModelTokens(
token = VAToken.Comment;
}
}
if (token != VAToken.Operator && token != VAToken.Asterisk) {
const indent = getIndent(text, tabSize);
tokens.push({ token, indent });
} else {
let indent = 0;
if (matcher.isSection(text)) token = VAToken.Section;
else indent = getIndent(text, tabSize);
tokens.push({ token, indent });
let indent: number;
switch (token) {
case VAToken.DirectIf:
directIndent += 1000;
indent = directIndent - 1;
tokens.push({ token, indent });
break;
case VAToken.DirectElse:
indent = directIndent - 1;
tokens.push({ token, indent });
break;
case VAToken.DirectEndif:
directIndent -= 1000;
indent = directIndent - 1;
tokens.push({ token, indent });
break;
case VAToken.Operator:
case VAToken.Asterisk:
indent = 0;
if (matcher.isSection(text)) token = VAToken.Section;
else indent = directIndent + getIndent(text, tabSize);
tokens.push({ token, indent });
break;
default: {
indent = directIndent + getIndent(text, tabSize);
tokens.push({ token, indent });
break;
}
}
}
return tokens;
Expand Down
3 changes: 3 additions & 0 deletions src/languages/turbo-gherkin/syntax.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ export function checkSyntax(
case VAToken.Multiline:
case VAToken.Parameter:
case VAToken.Instruction:
case VAToken.DirectIf:
case VAToken.DirectElse:
case VAToken.DirectEndif:
continue;
case VAToken.Comment:
matchImage(images, lineNumber, line, token);
Expand Down

0 comments on commit f78c3e3

Please sign in to comment.