Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow other VSCode Extensions to register bundles #403

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/commands.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

export namespace Commands {
/**
* Execute Workspace Command
*/
export const EXECUTE_WORKSPACE_COMMAND = 'yaml.execute.workspaceCommand';
}
33 changes: 31 additions & 2 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@

import * as path from 'path';

import { workspace, ExtensionContext, extensions } from 'vscode';
import { LanguageClient, LanguageClientOptions, ServerOptions, TransportKind, NotificationType } from 'vscode-languageclient';
import { workspace, ExtensionContext, extensions, commands } from 'vscode';
import { LanguageClient, LanguageClientOptions, ServerOptions, TransportKind, NotificationType, ExecuteCommandParams, ExecuteCommandRequest } from 'vscode-languageclient';
import { CUSTOM_SCHEMA_REQUEST, CUSTOM_CONTENT_REQUEST, SchemaExtensionAPI } from './schema-extension-api';
import { joinPath } from './paths';
import { Commands } from './commands';

export interface ISchemaAssociations {
[pattern: string]: string[];
Expand Down Expand Up @@ -64,6 +65,9 @@ export function activate(context: ExtensionContext): SchemaExtensionAPI {
// Notify the server about file changes to YAML and JSON files contained in the workspace
fileEvents: [workspace.createFileSystemWatcher('**/*.?(e)y?(a)ml'), workspace.createFileSystemWatcher('**/*.json')],
},
initializationOptions: {
bundles: gatherYAMLLanguageServerExtensions()
},
};

// Create the language client and start it
Expand Down Expand Up @@ -93,11 +97,36 @@ export function activate(context: ExtensionContext): SchemaExtensionAPI {
client.onRequest(CUSTOM_CONTENT_REQUEST, (uri: string) => {
return schemaExtensionAPI.requestCustomSchemaContent(uri);
});

commands.registerCommand(Commands.EXECUTE_WORKSPACE_COMMAND, (command, ...rest) => {
const params: ExecuteCommandParams = {
command: command[0],
arguments: rest
}
return client.sendRequest(ExecuteCommandRequest.type, params);
});
});

return schemaExtensionAPI;
}

function gatherYAMLLanguageServerExtensions(): string[] {
const yamlExtensionsArray = [];
for (const extInd in extensions.all) {
const currExtension = extensions.all[extInd];
const contributes = currExtension.packageJSON["contributes"];
if (contributes) {
const yamlExtension = contributes["yamlExtensions"];
if (yamlExtension && Array.isArray(yamlExtension)) {
for (const ext of yamlExtension) {
yamlExtensionsArray.push(path.resolve(currExtension.extensionPath, ext));
}
}
}
}
return yamlExtensionsArray;
}

function getSchemaAssociations(): ISchemaAssociation[] {
const associations: ISchemaAssociation[] = [];
extensions.all.forEach((extension) => {
Expand Down