Revert "initial changes for value provider"
This reverts commit 3f7cfbfdb1.
This commit is contained in:
@@ -7,10 +7,7 @@ import { Octokit } from "@octokit/rest";
|
|||||||
import { CompletionItem, DocumentUri, Position } from "vscode-languageserver";
|
import { CompletionItem, DocumentUri, Position } from "vscode-languageserver";
|
||||||
import { TextDocument } from "vscode-languageserver-textdocument";
|
import { TextDocument } from "vscode-languageserver-textdocument";
|
||||||
import { RepositoryContext } from "./initializationOptions";
|
import { RepositoryContext } from "./initializationOptions";
|
||||||
import { getJobNames } from "./value-providers/needs";
|
|
||||||
import { getRunnerLabels } from "./value-providers/runs-on";
|
import { getRunnerLabels } from "./value-providers/runs-on";
|
||||||
import { WorkflowTemplate } from "@github/actions-workflow-parser";
|
|
||||||
|
|
||||||
|
|
||||||
export async function onCompletion(
|
export async function onCompletion(
|
||||||
position: Position,
|
position: Position,
|
||||||
@@ -20,8 +17,8 @@ export async function onCompletion(
|
|||||||
repoWorkflowMap: Map<string, RepositoryContext>
|
repoWorkflowMap: Map<string, RepositoryContext>
|
||||||
): Promise<CompletionItem[]> {
|
): Promise<CompletionItem[]> {
|
||||||
const config: ValueProviderConfig = {
|
const config: ValueProviderConfig = {
|
||||||
getCustomValues: async (key: string, context: WorkflowContext, template: WorkflowTemplate | undefined) =>
|
getCustomValues: async (key: string, context: WorkflowContext) =>
|
||||||
getCustomValues(key, context, sessionToken, repoWorkflowMap, template),
|
getCustomValues(key, context, sessionToken, repoWorkflowMap),
|
||||||
};
|
};
|
||||||
return await complete(document, position, config);
|
return await complete(document, position, config);
|
||||||
}
|
}
|
||||||
@@ -30,8 +27,7 @@ async function getCustomValues(
|
|||||||
key: string,
|
key: string,
|
||||||
context: WorkflowContext,
|
context: WorkflowContext,
|
||||||
sessionToken: string | undefined,
|
sessionToken: string | undefined,
|
||||||
repoWorkspaceMap: Map<string, RepositoryContext>,
|
repoWorkspaceMap: Map<string, RepositoryContext>
|
||||||
template: WorkflowTemplate | undefined
|
|
||||||
) {
|
) {
|
||||||
if (!sessionToken) {
|
if (!sessionToken) {
|
||||||
return;
|
return;
|
||||||
@@ -48,7 +44,4 @@ async function getCustomValues(
|
|||||||
});
|
});
|
||||||
return await getRunnerLabels(octokit, repo.owner, repo.name);
|
return await getRunnerLabels(octokit, repo.owner, repo.name);
|
||||||
}
|
}
|
||||||
if (key === "needs" && template) {
|
|
||||||
return await getJobNames(template);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,19 +0,0 @@
|
|||||||
import { Value } from "@github/actions-languageservice/value-providers/config";
|
|
||||||
import { WorkflowTemplate } from "@github/actions-workflow-parser/model/workflow-template";
|
|
||||||
|
|
||||||
export async function getJobNames(
|
|
||||||
template: WorkflowTemplate
|
|
||||||
): Promise<Value[]> {
|
|
||||||
const labels = new Set<string>([
|
|
||||||
// "dummy-job",
|
|
||||||
]);
|
|
||||||
|
|
||||||
const jobsValues = template.jobs.jobNames;
|
|
||||||
if (jobsValues) {
|
|
||||||
for (const job of jobsValues?.values() || []) {
|
|
||||||
labels.add(job);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return Array.from(labels).map((label) => ({ label }));
|
|
||||||
}
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
import { convertWorkflowTemplate, parseWorkflow, WorkflowTemplate } from "@github/actions-workflow-parser";
|
import { parseWorkflow } from "@github/actions-workflow-parser";
|
||||||
import {
|
import {
|
||||||
SEQUENCE_TYPE,
|
SEQUENCE_TYPE,
|
||||||
STRING_TYPE,
|
STRING_TYPE,
|
||||||
@@ -31,24 +31,16 @@ export async function complete(
|
|||||||
content: newDoc.getText(),
|
content: newDoc.getText(),
|
||||||
};
|
};
|
||||||
const result = parseWorkflow(file.name, [file], nullTrace);
|
const result = parseWorkflow(file.name, [file], nullTrace);
|
||||||
const [innerToken, parent] = findInnerTokenAndParent(newPos, result.value);
|
|
||||||
let template: WorkflowTemplate | undefined = undefined;
|
|
||||||
const valueToRemove = parent?.definition?.keyname;
|
|
||||||
if (result.value) {
|
|
||||||
template = convertWorkflowTemplate(result.context, result.value);
|
|
||||||
console.log("template", template);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
const [innerToken, parent] = findInnerTokenAndParent(newPos, result.value);
|
||||||
const values = await getValues(
|
const values = await getValues(
|
||||||
innerToken,
|
innerToken,
|
||||||
parent,
|
parent,
|
||||||
newPos,
|
newPos,
|
||||||
textDocument.uri,
|
textDocument.uri,
|
||||||
valueProviderConfig,
|
valueProviderConfig
|
||||||
template,
|
|
||||||
);
|
);
|
||||||
const valuesFiltered = values.filter((x) => x.label !== valueToRemove);
|
return values.map((value) => CompletionItem.create(value.label));
|
||||||
return valuesFiltered.map((value) => CompletionItem.create(value.label));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getValues(
|
async function getValues(
|
||||||
@@ -56,8 +48,7 @@ async function getValues(
|
|||||||
parent: TemplateToken | null,
|
parent: TemplateToken | null,
|
||||||
position: Position,
|
position: Position,
|
||||||
workflowUri: string,
|
workflowUri: string,
|
||||||
valueProviderConfig: ValueProviderConfig | undefined,
|
valueProviderConfig: ValueProviderConfig | undefined
|
||||||
template: WorkflowTemplate | undefined,
|
|
||||||
): Promise<Value[]> {
|
): Promise<Value[]> {
|
||||||
if (!parent) {
|
if (!parent) {
|
||||||
return [];
|
return [];
|
||||||
@@ -71,21 +62,16 @@ async function getValues(
|
|||||||
}
|
}
|
||||||
|
|
||||||
const existingValues = getExistingValues(token, parent);
|
const existingValues = getExistingValues(token, parent);
|
||||||
console.log("Parent", parent);
|
|
||||||
console.log("Token", token);
|
|
||||||
|
|
||||||
let customValues: Value[] | undefined = undefined;
|
let customValues: Value[] | undefined = undefined;
|
||||||
if (token?.definition?.key) {
|
if (token?.definition?.key) {
|
||||||
customValues = await valueProviderConfig?.getCustomValues(
|
customValues = await valueProviderConfig?.getCustomValues(
|
||||||
token.definition.key,
|
token.definition.key,
|
||||||
{ uri: workflowUri },
|
{ uri: workflowUri }
|
||||||
template,
|
|
||||||
);
|
);
|
||||||
// add to custom values?
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (customValues !== undefined) {
|
if (customValues !== undefined) {
|
||||||
console.log("filterAndSortCompletionOptions with customValues")
|
|
||||||
return filterAndSortCompletionOptions(customValues, existingValues);
|
return filterAndSortCompletionOptions(customValues, existingValues);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -101,7 +87,6 @@ async function getValues(
|
|||||||
}
|
}
|
||||||
const values = valueProvider();
|
const values = valueProvider();
|
||||||
|
|
||||||
console.log("filterAndSortCompletionOptions with values")
|
|
||||||
return filterAndSortCompletionOptions(values, existingValues);
|
return filterAndSortCompletionOptions(values, existingValues);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -47,10 +47,7 @@ export function findInnerTokenAndParent(
|
|||||||
if (nullNodeOnLine(pos, key, value)) {
|
if (nullNodeOnLine(pos, key, value)) {
|
||||||
return [value, key];
|
return [value, key];
|
||||||
}
|
}
|
||||||
//value.definition?.keyname = key.value;
|
|
||||||
if (value.definition){
|
|
||||||
value.definition.keyname = key.toString();
|
|
||||||
}
|
|
||||||
s.push(value);
|
s.push(value);
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
@@ -77,8 +74,8 @@ function posInToken(pos: Position, token: TemplateToken): boolean {
|
|||||||
const r = token.range;
|
const r = token.range;
|
||||||
|
|
||||||
// TokenRange is one-based, Position is zero-based
|
// TokenRange is one-based, Position is zero-based
|
||||||
const tokenLine = pos.line //+ 1;
|
const tokenLine = pos.line + 1;
|
||||||
const tokenChar = pos.character //+ 1;
|
const tokenChar = pos.character + 1;
|
||||||
|
|
||||||
// Check lines
|
// Check lines
|
||||||
if (r.start[0] > tokenLine || tokenLine > r.end[0]) {
|
if (r.start[0] > tokenLine || tokenLine > r.end[0]) {
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
import { WorkflowTemplate } from "@github/actions-workflow-parser/model/workflow-template";
|
|
||||||
|
|
||||||
export interface Value {
|
export interface Value {
|
||||||
label: string;
|
label: string;
|
||||||
description?: string;
|
description?: string;
|
||||||
@@ -13,8 +11,7 @@ export interface WorkflowContext {
|
|||||||
export interface ValueProviderConfig {
|
export interface ValueProviderConfig {
|
||||||
getCustomValues: (
|
getCustomValues: (
|
||||||
key: string,
|
key: string,
|
||||||
context: WorkflowContext,
|
context: WorkflowContext
|
||||||
template: WorkflowTemplate | undefined
|
|
||||||
) => Promise<Value[] | undefined>;
|
) => Promise<Value[] | undefined>;
|
||||||
getActionInputs?: (
|
getActionInputs?: (
|
||||||
owner: string,
|
owner: string,
|
||||||
|
|||||||
@@ -1,19 +0,0 @@
|
|||||||
import { Value } from "./config";
|
|
||||||
import { WorkflowTemplate } from "@github/actions-workflow-parser/model/workflow-template";
|
|
||||||
|
|
||||||
export async function getJobNames(
|
|
||||||
template: WorkflowTemplate
|
|
||||||
): Promise<Value[]> {
|
|
||||||
const labels = new Set<string>([
|
|
||||||
"dummy-job",
|
|
||||||
]);
|
|
||||||
|
|
||||||
const jobsValues = template.jobs.jobNames;
|
|
||||||
if (jobsValues) {
|
|
||||||
for (const job of jobsValues?.values() || []) {
|
|
||||||
labels.add(job);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return Array.from(labels).map((label) => ({ label }));
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user