Map workspaces to the correct repository
This commit is contained in:
@@ -28,7 +28,6 @@ const documents: TextDocuments<TextDocument> = new TextDocuments(TextDocument);
|
|||||||
|
|
||||||
let sessionToken: string | undefined;
|
let sessionToken: string | undefined;
|
||||||
let repos: RepositoryContext[] = [];
|
let repos: RepositoryContext[] = [];
|
||||||
let repoWorkspaceMap = new Map<string, RepositoryContext>();
|
|
||||||
|
|
||||||
let hasConfigurationCapability = false;
|
let hasConfigurationCapability = false;
|
||||||
let hasWorkspaceFolderCapability = false;
|
let hasWorkspaceFolderCapability = false;
|
||||||
@@ -50,9 +49,6 @@ connection.onInitialize((params: InitializeParams) => {
|
|||||||
sessionToken = options.sessionToken;
|
sessionToken = options.sessionToken;
|
||||||
if (options.repos) {
|
if (options.repos) {
|
||||||
repos = options.repos;
|
repos = options.repos;
|
||||||
for (const repo of repos) {
|
|
||||||
repoWorkspaceMap.set(repo.workspaceUri, repo);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const result: InitializeResult = {
|
const result: InitializeResult = {
|
||||||
@@ -110,10 +106,9 @@ connection.onCompletion(
|
|||||||
}: TextDocumentPositionParams): Promise<CompletionItem[]> => {
|
}: TextDocumentPositionParams): Promise<CompletionItem[]> => {
|
||||||
return await onCompletion(
|
return await onCompletion(
|
||||||
position,
|
position,
|
||||||
textDocument.uri,
|
|
||||||
documents.get(textDocument.uri)!,
|
documents.get(textDocument.uri)!,
|
||||||
sessionToken,
|
sessionToken,
|
||||||
repoWorkspaceMap
|
repos.find((repo) => textDocument.uri.startsWith(repo.workspaceUri))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { complete } from "@github/actions-languageservice/complete";
|
|||||||
import { WorkflowContext } from "@github/actions-languageservice/context/workflow-context";
|
import { WorkflowContext } from "@github/actions-languageservice/context/workflow-context";
|
||||||
import { ValueProviderConfig } from "@github/actions-languageservice/value-providers/config";
|
import { ValueProviderConfig } from "@github/actions-languageservice/value-providers/config";
|
||||||
import { Octokit } from "@octokit/rest";
|
import { Octokit } from "@octokit/rest";
|
||||||
import { CompletionItem, DocumentUri, Position } from "vscode-languageserver";
|
import { CompletionItem, 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 { getEnvironments } from "./value-providers/job-environment";
|
import { getEnvironments } from "./value-providers/job-environment";
|
||||||
@@ -10,14 +10,13 @@ import { getRunnerLabels } from "./value-providers/runs-on";
|
|||||||
|
|
||||||
export async function onCompletion(
|
export async function onCompletion(
|
||||||
position: Position,
|
position: Position,
|
||||||
uri: DocumentUri,
|
|
||||||
document: TextDocument,
|
document: TextDocument,
|
||||||
sessionToken: string | undefined,
|
sessionToken: string | undefined,
|
||||||
repoWorkflowMap: Map<string, RepositoryContext>
|
repoContext: RepositoryContext | undefined
|
||||||
): Promise<CompletionItem[]> {
|
): Promise<CompletionItem[]> {
|
||||||
const config: ValueProviderConfig = {
|
const config: ValueProviderConfig = {
|
||||||
getCustomValues: async (key: string, context: WorkflowContext) =>
|
getCustomValues: async (key: string, context: WorkflowContext) =>
|
||||||
getCustomValues(key, context, sessionToken, repoWorkflowMap),
|
getCustomValues(key, context, sessionToken, repoContext),
|
||||||
};
|
};
|
||||||
return await complete(document, position, config);
|
return await complete(document, position, config);
|
||||||
}
|
}
|
||||||
@@ -26,15 +25,9 @@ async function getCustomValues(
|
|||||||
key: string,
|
key: string,
|
||||||
context: WorkflowContext,
|
context: WorkflowContext,
|
||||||
sessionToken: string | undefined,
|
sessionToken: string | undefined,
|
||||||
repoWorkspaceMap: Map<string, RepositoryContext>
|
repo: RepositoryContext | undefined,
|
||||||
) {
|
) {
|
||||||
if (!sessionToken) {
|
if (!sessionToken || !repo) {
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: Parse workflow URI and look up repo for workspace
|
|
||||||
const [repo] = repoWorkspaceMap.values();
|
|
||||||
if (!repo) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user