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 17dce0c commit 9eb6c58
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 4 deletions.
4 changes: 4 additions & 0 deletions src/languages/turbo-gherkin/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export function getLineMaxColumn(line: string): number {

export interface IWorkerContext {
matcher: KeywordMatcher;
directives: ISpprDirect;
metatags: string[];
steplist: any;
keypairs: any;
Expand Down Expand Up @@ -77,6 +78,7 @@ export enum MessageType {
SetKeypairs,
SetMessages,
SetVariables,
SetDirectives,
UpdateModel,
DeleteModel,
GetCodeActions,
Expand All @@ -99,6 +101,7 @@ export function type2str(type: MessageType) {
case MessageType.SetKeypairs: return "SetKeypairs";
case MessageType.SetMessages: return "SetMessages";
case MessageType.SetVariables: return "SetVariables";
case MessageType.SetDirectives: return "SetDirectives";
case MessageType.UpdateModel: return "UpdateModel";
case MessageType.DeleteModel: return "DeleteModel";
case MessageType.GetCodeActions: return "GetCodeActions";
Expand All @@ -120,6 +123,7 @@ export type WorkerMessage =
| { id?: number, type: MessageType.SetMessages, data: any }
| { id?: number, type: MessageType.SetElements, values: string, clear: boolean }
| { id?: number, type: MessageType.SetVariables, values: string, clear: boolean }
| { id?: number, type: MessageType.SetDirectives, data: any }
| { id?: number, type: MessageType.SetImports, data: any }
| { id?: number, type: MessageType.UpdateModel, versionId: number, uri: string }
| { id?: number, type: MessageType.DeleteModel, uri: string }
Expand Down
6 changes: 3 additions & 3 deletions src/languages/turbo-gherkin/model.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { IWorkerModel, VAIndent, VAToken } from "./common";
import { KeywordMatcher } from "./matcher";
import { IDirectExp, KeywordMatcher } from "./matcher";

function getIndent(text: string, tabSize: number) {
let indent = 0;
Expand All @@ -12,7 +12,7 @@ function getIndent(text: string, tabSize: number) {
return indent + 1;
}

function getToken(text: string, sppr: boolean) {
function getToken(text: string, sppr: boolean, direct: IDirectExp) {
if (sppr) {
if (/^\s*\/\*.*$/.test(text)) return VAToken.StartComment;
if (/^.*\*\/\s*/.test(text)) return VAToken.EndComment;
Expand All @@ -37,7 +37,7 @@ export function getModelTokens(
const lineCount = model.getLineCount();
for (let lineNumber = 1; lineNumber <= lineCount; lineNumber++) {
let text = model.getLineContent(lineNumber);
let token = getToken(text, matcher.sppr);
let token = getToken(text, matcher.sppr, matcher.directives);
if (multilineParam) {
if (token == VAToken.Multiline) {
multilineParam = false;
Expand Down
1 change: 1 addition & 0 deletions src/languages/turbo-gherkin/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ export class VanessaGherkinProvider {
}

public setDirectives = (arg: string): void => {
worker.postMessage({ type: MessageType.SetDirectives, data: arg });
this._directives = JSON.parse(arg) as ISpprDirect;
this.matcher?.setDirectives(this.directives);
}
Expand Down
8 changes: 7 additions & 1 deletion src/languages/turbo-gherkin/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { setStepList, updateStepLabels } from './steplist';

const context: IWorkerContext = {
matcher: undefined,
directives: {},
metatags: ["try", "except", "попытка", "исключение"],
steplist: {},
keypairs: {},
Expand Down Expand Up @@ -85,11 +86,16 @@ export function process(msg: WorkerMessage) {
return { id: msg.id, data: { suggestions }, success: true };
case MessageType.SetKeywords:
context.matcher = new KeywordMatcher(msg.data);
context.matcher.setDirectives(context.directives);
context.matcher.setKeypairs(context.keypairs);
context.matcher.setMetatags(context.metatags)
context.matcher.setSPPR(context.sppr)
context.matcher.setSPPR(context.sppr);
updateStepLabels(context);
break;
case MessageType.SetDirectives:
context.directives = JSON.parse(msg.data);
context.matcher?.setDirectives(context.directives)
break;
case MessageType.SetKeypairs:
context.keypairs = msg.data;
context.matcher?.setKeypairs(context.keypairs);
Expand Down

0 comments on commit 9eb6c58

Please sign in to comment.