Extract helper functions
This commit is contained in:
@@ -0,0 +1,15 @@
|
|||||||
|
import {TokenRange} from "@github/actions-workflow-parser/templates/tokens/token-range";
|
||||||
|
import {Position} from "vscode-languageserver-textdocument";
|
||||||
|
import {mapRange} from "./range";
|
||||||
|
|
||||||
|
export function getRelCharOffset(tokenRange: TokenRange, currentInput: string, pos: Position): number {
|
||||||
|
const range = mapRange(tokenRange);
|
||||||
|
if (range.start.line !== range.end.line) {
|
||||||
|
const lines = currentInput.split("\n");
|
||||||
|
const lineDiff = pos.line - range.start.line - 1;
|
||||||
|
const linesBeforeCusor = lines.slice(0, lineDiff);
|
||||||
|
return linesBeforeCusor.join("\n").length + pos.character + 1;
|
||||||
|
} else {
|
||||||
|
return pos.character - range.start.character;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
import {isString} from "@github/actions-workflow-parser";
|
||||||
|
import {DefinitionType} from "@github/actions-workflow-parser/templates/schema/definition-type";
|
||||||
|
import {StringDefinition} from "@github/actions-workflow-parser/templates/schema/string-definition";
|
||||||
|
import {OPEN_EXPRESSION} from "@github/actions-workflow-parser/templates/template-constants";
|
||||||
|
import {TemplateToken} from "@github/actions-workflow-parser/templates/tokens/index";
|
||||||
|
|
||||||
|
export function isStringExpression(token: TemplateToken): boolean {
|
||||||
|
const isExpression =
|
||||||
|
token.definition?.definitionType === DefinitionType.String && (token.definition as StringDefinition).isExpression;
|
||||||
|
const containsExpression = isString(token) && token.value.indexOf(OPEN_EXPRESSION) >= 0;
|
||||||
|
return isExpression || containsExpression;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user