diff --git a/package.json b/package.json index 04e6e58f..27402661 100644 --- a/package.json +++ b/package.json @@ -265,7 +265,7 @@ "@types/chai": "^4.2.12", "@types/fs-extra": "^9.0.6", "@types/mocha": "^2.2.48", - "@types/node": "^12.12.6", + "@types/node": "^18.x", "@types/sinon": "^10.0.6", "@types/sinon-chai": "^3.2.5", "@types/vscode": "^1.63.0", diff --git a/src/extension.ts b/src/extension.ts index f56b691e..09712fd5 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -6,7 +6,7 @@ *--------------------------------------------------------------------------------------------*/ 'use strict'; -import { workspace, ExtensionContext, extensions, window, commands, Uri } from 'vscode'; +import { workspace, ExtensionContext, extensions, window, commands, Uri, ConfigurationTarget, env } from 'vscode'; import { CommonLanguageClient, LanguageClientOptions, @@ -113,6 +113,7 @@ export function startClient( ): SchemaExtensionAPI { const telemetryErrorHandler = new TelemetryErrorHandler(runtime.telemetry, lsName, 4); const outputChannel = window.createOutputChannel(lsName); + const l10nPath = context.asAbsolutePath('../yaml-language-server/l10n'); // Options to control the language client const clientOptions: LanguageClientOptions = { // Register the server for on disk and newly created YAML documents @@ -129,6 +130,9 @@ export function startClient( revealOutputChannelOn: RevealOutputChannelOn.Never, errorHandler: telemetryErrorHandler, outputChannel: new TelemetryOutputChannel(outputChannel, runtime.telemetry), + initializationOptions: { + l10nPath, + }, }; // Create the language client and start it @@ -157,7 +161,7 @@ export function startClient( findConflicts(); client .onReady() - .then(() => { + .then(async () => { // Send a notification to the server with any YAML schema associations in all extensions client.sendNotification(SchemaAssociationNotification.type, getSchemaAssociations()); @@ -214,6 +218,8 @@ export function startClient( }); initializeRecommendation(context); + + await setDefaultFormatter(['dockercompose', 'github-actions-workflow']); }) .catch((err) => { sendStartupTelemetryEvent(runtime.telemetry, false, err); @@ -222,6 +228,23 @@ export function startClient( return schemaExtensionAPI; } +/** + * set redhat.vscode-yaml as default formatter + * @param extensions [dockercompose, github-actions-workflow] + */ +async function setDefaultFormatter(extensions: string[]): Promise { + const config = workspace.getConfiguration(); + extensions.forEach(async (extension) => { + const extensionConf = config.get>(`[${extension}]`) || {}; + if (extensionConf) { + if (extensionConf['editor.defaultFormatter'] === undefined) { + extensionConf['editor.defaultFormatter'] = 'redhat.vscode-yaml'; + await config.update(`[${extension}]`, extensionConf, ConfigurationTarget.Global); + } + } + }); +} + /** * Finds extensions that conflict with VSCode-YAML. * If one or more conflicts are found then show an uninstall notification diff --git a/yarn.lock b/yarn.lock index a5fd152e..7131a853 100644 --- a/yarn.lock +++ b/yarn.lock @@ -310,10 +310,12 @@ resolved "https://registry.yarnpkg.com/@types/node/-/node-18.15.3.tgz#f0b991c32cfc6a4e7f3399d6cb4b8cf9a0315014" integrity sha512-p6ua9zBxz5otCmbpb5D3U4B5Nanw6Pk3PPyX05xnxbB/fRv71N7CPmORg7uAD5P70T0xmx1pzAx/FUfa5X+3cw== -"@types/node@^12.12.6": - version "12.20.55" - resolved "https://registry.yarnpkg.com/@types/node/-/node-12.20.55.tgz#c329cbd434c42164f846b909bd6f85b5537f6240" - integrity sha512-J8xLz7q2OFulZ2cyGTLE1TbbZcjpno7FaN6zdJNrgAdrJ+DZzh/uFR6YrTb4C+nXakvud8Q4+rbhoIWlYQbUFQ== +"@types/node@^18.x": + version "18.19.112" + resolved "https://registry.yarnpkg.com/@types/node/-/node-18.19.112.tgz#cd2aee9c075402e0e1942a44101428881dbeb110" + integrity sha512-i+Vukt9POdS/MBI7YrrkkI5fMfwFtOjphSmt4WXYLfwqsfr6z/HdCx7LqT9M7JktGob8WNgj8nFB4TbGNE4Cog== + dependencies: + undici-types "~5.26.4" "@types/responselike@^1.0.0": version "1.0.0" @@ -4571,6 +4573,11 @@ underscore@^1.12.1: resolved "https://registry.yarnpkg.com/underscore/-/underscore-1.13.6.tgz#04786a1f589dc6c09f761fc5f45b89e935136441" integrity sha512-+A5Sja4HP1M08MaXya7p5LvjuM7K6q/2EaC0+iovj/wOcMsTzMvDFbasi/oSapiwOlt252IqsKqPjCl7huKS0A== +undici-types@~5.26.4: + version "5.26.5" + resolved "https://registry.yarnpkg.com/undici-types/-/undici-types-5.26.5.tgz#bcd539893d00b56e964fd2657a4866b221a65617" + integrity sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA== + universalify@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/universalify/-/universalify-2.0.0.tgz#75a4984efedc4b08975c5aeb73f530d02df25717"