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