|
| 1 | +/******************************************************************************* |
| 2 | +* Copyright (c) 2026 Red Hat Inc. and others. |
| 3 | +* All rights reserved. This program and the accompanying materials |
| 4 | +* which accompanies this distribution, and is available at |
| 5 | +* http://www.eclipse.org/legal/epl-v20.html |
| 6 | +* |
| 7 | +* SPDX-License-Identifier: EPL-2.0 |
| 8 | +* |
| 9 | +* Contributors: |
| 10 | +* Red Hat Inc. - initial API and implementation |
| 11 | +*******************************************************************************/ |
| 12 | +package org.eclipse.lemminx.extensions.minify; |
| 13 | + |
| 14 | +import org.eclipse.lemminx.extensions.minify.commands.MinifyDocumentCommand; |
| 15 | +import org.eclipse.lemminx.extensions.minify.participants.MinifyCodeActionParticipant; |
| 16 | +import org.eclipse.lemminx.services.IXMLDocumentProvider; |
| 17 | +import org.eclipse.lemminx.services.extensions.IXMLExtension; |
| 18 | +import org.eclipse.lemminx.services.extensions.XMLExtensionsRegistry; |
| 19 | +import org.eclipse.lemminx.services.extensions.commands.IXMLCommandService; |
| 20 | +import org.eclipse.lemminx.services.extensions.save.ISaveContext; |
| 21 | +import org.eclipse.lsp4j.InitializeParams; |
| 22 | + |
| 23 | +/** |
| 24 | + * Minify plugin to register the minify command and code action. |
| 25 | + */ |
| 26 | +public class MinifyPlugin implements IXMLExtension { |
| 27 | + |
| 28 | + private MinifyCodeActionParticipant codeActionParticipant; |
| 29 | + |
| 30 | + @Override |
| 31 | + public void start(InitializeParams params, XMLExtensionsRegistry registry) { |
| 32 | + // Register minify command |
| 33 | + IXMLCommandService commandService = registry.getCommandService(); |
| 34 | + if (commandService != null) { |
| 35 | + IXMLDocumentProvider documentProvider = registry.getDocumentProvider(); |
| 36 | + commandService.registerCommand(MinifyDocumentCommand.COMMAND_ID, |
| 37 | + new MinifyDocumentCommand(documentProvider)); |
| 38 | + } |
| 39 | + |
| 40 | + // Register minify code action |
| 41 | + codeActionParticipant = new MinifyCodeActionParticipant(); |
| 42 | + registry.registerCodeActionParticipant(codeActionParticipant); |
| 43 | + } |
| 44 | + |
| 45 | + @Override |
| 46 | + public void stop(XMLExtensionsRegistry registry) { |
| 47 | + // Unregister minify command |
| 48 | + IXMLCommandService commandService = registry.getCommandService(); |
| 49 | + if (commandService != null) { |
| 50 | + commandService.unregisterCommand(MinifyDocumentCommand.COMMAND_ID); |
| 51 | + } |
| 52 | + |
| 53 | + // Unregister minify code action |
| 54 | + registry.unregisterCodeActionParticipant(codeActionParticipant); |
| 55 | + } |
| 56 | + |
| 57 | + @Override |
| 58 | + public void doSave(ISaveContext context) { |
| 59 | + // Nothing to do on save |
| 60 | + } |
| 61 | +} |
0 commit comments