Rename methods

This commit is contained in:
Jacob Wallraff
2023-03-03 12:39:40 -08:00
parent ffcd06c8c5
commit 5a199d4c52
5 changed files with 18 additions and 34 deletions
+3 -3
View File
@@ -28,7 +28,7 @@ import {transform} from "./utils/transform";
import {Value, ValueProviderConfig} from "./value-providers/config";
import {defaultValueProviders} from "./value-providers/default";
import {definitionValues} from "./value-providers/definition";
import {getParsedWorkflow, getWorkflowTemplate} from "./utils/workflow-cache";
import {fetchOrParseWorkflow, fetchOrConvertWorkflowTemplate} from "./utils/workflow-cache";
export function getExpressionInput(input: string, pos: number): string {
// Find start marker around the cursor position
@@ -69,12 +69,12 @@ export async function complete(
content: newDoc.getText()
};
const parsedWorkflow = getParsedWorkflow(file, textDocument.uri);
const parsedWorkflow = fetchOrParseWorkflow(file, textDocument.uri);
if (!parsedWorkflow) {
return [];
}
const template = await getWorkflowTemplate(file, parsedWorkflow, textDocument.uri, config, {
const template = await fetchOrConvertWorkflowTemplate(file, parsedWorkflow, textDocument.uri, config, {
fetchReusableWorkflowDepth: config?.fileProvider ? 1 : 0,
errorPolicy: ErrorPolicy.TryConversion
});
+3 -3
View File
@@ -5,7 +5,7 @@ import {TextDocument} from "vscode-languageserver-textdocument";
import {DocumentLink} from "vscode-languageserver-types";
import {parseActionReference} from "./action";
import {mapRange} from "./utils/range";
import {getParsedWorkflow, getWorkflowTemplate} from "./utils/workflow-cache";
import {fetchOrParseWorkflow, fetchOrConvertWorkflowTemplate} from "./utils/workflow-cache";
export async function documentLinks(document: TextDocument): Promise<DocumentLink[]> {
const file: File = {
@@ -13,12 +13,12 @@ export async function documentLinks(document: TextDocument): Promise<DocumentLin
content: document.getText()
};
const parsedWorkflow = getParsedWorkflow(file, document.uri);
const parsedWorkflow = fetchOrParseWorkflow(file, document.uri);
if (!parsedWorkflow) {
return [];
}
const template = await getWorkflowTemplate(file, parsedWorkflow, document.uri, undefined, {
const template = await fetchOrConvertWorkflowTemplate(file, parsedWorkflow, document.uri, undefined, {
errorPolicy: ErrorPolicy.TryConversion
});
+3 -3
View File
@@ -25,7 +25,7 @@ import {info} from "./log";
import {isPotentiallyExpression} from "./utils/expression-detection";
import {findToken, TokenResult} from "./utils/find-token";
import {mapRange} from "./utils/range";
import {getParsedWorkflow, getWorkflowTemplate} from "./utils/workflow-cache";
import {fetchOrParseWorkflow, fetchOrConvertWorkflowTemplate} from "./utils/workflow-cache";
export type HoverConfig = {
descriptionProvider?: DescriptionProvider;
@@ -43,12 +43,12 @@ export async function hover(document: TextDocument, position: Position, config?:
content: document.getText()
};
const parsedWorkflow = getParsedWorkflow(file, document.uri);
const parsedWorkflow = fetchOrParseWorkflow(file, document.uri);
if (!parsedWorkflow) {
return null;
}
const template = await getWorkflowTemplate(file, parsedWorkflow, document.uri, config, {
const template = await fetchOrConvertWorkflowTemplate(file, parsedWorkflow, document.uri, config, {
errorPolicy: ErrorPolicy.TryConversion,
fetchReusableWorkflowDepth: config?.fileProvider ? 1 : 0
});
+6 -22
View File
@@ -9,14 +9,6 @@ import { CompletionConfig } from "../complete";
const parsedWorkflowCache = new Map<string, ParseWorkflowResult>();
const workflowTemplateCache = new Map<string, WorkflowTemplate>();
export function cacheParsedWorkflow(uri: string, parsedWorkflowResult: ParseWorkflowResult) {
parsedWorkflowCache.set(uri, parsedWorkflowResult);
}
export function getParsedWorkflowCacheEntry(uri: string): ParseWorkflowResult | undefined {
return parsedWorkflowCache.get(uri);
}
export function clearParsedCacheEntry(uri: string) {
parsedWorkflowCache.delete(uri);
}
@@ -25,14 +17,6 @@ export function clearParsedCache() {
parsedWorkflowCache.clear();
}
export function cacheWorkflowTemplate(uri: string, workflowTemplate: WorkflowTemplate) {
workflowTemplateCache.set(uri, workflowTemplate);
}
export function getWorkflowTemplateCacheEntry(uri: string): WorkflowTemplate | undefined {
return workflowTemplateCache.get(uri);
}
export function clearWorkflowTemplateCacheEntry(uri: string) {
workflowTemplateCache.delete(uri);
}
@@ -41,23 +25,23 @@ export function clearWorkflowTemplateCache() {
workflowTemplateCache.clear();
}
export function getParsedWorkflow(file: File, uri: string): ParseWorkflowResult | undefined {
let result = getParsedWorkflowCacheEntry(uri);
export function fetchOrParseWorkflow(file: File, uri: string): ParseWorkflowResult | undefined {
let result = parsedWorkflowCache.get(uri);
if (!result || !result.value) {
result = parseWorkflow(file, nullTrace);
if (!result.value) {
return undefined;
}
cacheParsedWorkflow(uri, result)
parsedWorkflowCache.set(uri, result);
}
return result;
}
export async function getWorkflowTemplate(file: File, parsedWorkflow: ParseWorkflowResult, uri: string, config?: CompletionConfig, options?: WorkflowTemplateConverterOptions): Promise<WorkflowTemplate> {
let template = getWorkflowTemplateCacheEntry(uri);
export async function fetchOrConvertWorkflowTemplate(file: File, parsedWorkflow: ParseWorkflowResult, uri: string, config?: CompletionConfig, options?: WorkflowTemplateConverterOptions): Promise<WorkflowTemplate> {
let template = workflowTemplateCache.get(uri);
if (!template) {
template = await convertWorkflowTemplate(file.name, parsedWorkflow.context, parsedWorkflow.value!, config?.fileProvider, options);
cacheWorkflowTemplate(uri, template);
workflowTemplateCache.set(uri, template);
}
return template;
}
+3 -3
View File
@@ -26,7 +26,7 @@ import {mapRange} from "./utils/range";
import {validateAction} from "./validate-action";
import {ValueProviderConfig, ValueProviderKind} from "./value-providers/config";
import {defaultValueProviders} from "./value-providers/default";
import { getParsedWorkflow, getWorkflowTemplate } from "./utils/workflow-cache";
import {fetchOrParseWorkflow, fetchOrConvertWorkflowTemplate} from "./utils/workflow-cache";
export type ValidationConfig = {
valueProviderConfig?: ValueProviderConfig;
@@ -50,14 +50,14 @@ export async function validate(textDocument: TextDocument, config?: ValidationCo
const diagnostics: Diagnostic[] = [];
try {
const parsedWorkflow = getParsedWorkflow(file, textDocument.uri);
const parsedWorkflow = fetchOrParseWorkflow(file, textDocument.uri);
if (!parsedWorkflow) {
return [];
}
if (parsedWorkflow.value) {
// Errors will be updated in the context. Attempt to do the conversion anyway in order to give the user more information
const template = await getWorkflowTemplate(file, parsedWorkflow, textDocument.uri, config, {
const template = await fetchOrConvertWorkflowTemplate(file, parsedWorkflow, textDocument.uri, config, {
fetchReusableWorkflowDepth: config?.fileProvider ? 1 : 0,
errorPolicy: ErrorPolicy.TryConversion
});