Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
XMLExtensionRegistry: capture initial settings iff it's absent
FileContentGeneratorPlugin: type test the registry Signed-off-by: Yatao Li <yatli@microsoft.com>
- Loading branch information
1 parent
9f5f757
commit f0503e2
Showing
3 changed files
with
112 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
...nx/src/test/java/org/eclipse/lemminx/services/extensions/ExtensionRegistryDoSaveTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
/** | ||
* Copyright (c) 2020 Yatao Li. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v2.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v20.html | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Yatao Li <yatao.li@live.com> - initial API and implementation | ||
*/ | ||
package org.eclipse.lemminx.services.extensions; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import java.util.function.Predicate; | ||
|
||
import org.eclipse.lemminx.XMLAssert.SettingsSaveContext; | ||
import org.eclipse.lemminx.dom.DOMDocument; | ||
import org.eclipse.lemminx.services.extensions.IXMLExtension; | ||
import org.eclipse.lemminx.services.extensions.XMLExtensionsRegistry; | ||
import org.eclipse.lemminx.services.extensions.save.ISaveContext; | ||
import org.eclipse.lsp4j.InitializeParams; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import com.google.gson.JsonObject; | ||
|
||
/** | ||
* Ensures that {@code XMLExtensionsRegistry.doSave()} correctly captures the | ||
* initial LS configuration, and the configuration is correctly forwarded to | ||
* {@code IXMLExtension.doSave()} for registered extensions. | ||
*/ | ||
public class ExtensionRegistryDoSaveTest { | ||
|
||
class RegistryTestExtension implements IXMLExtension { | ||
|
||
private ISaveContext context = null; | ||
|
||
@Override | ||
public void start(InitializeParams params, XMLExtensionsRegistry registry) { | ||
} | ||
|
||
@Override | ||
public void stop(XMLExtensionsRegistry registry) { | ||
} | ||
|
||
@Override | ||
public void doSave(ISaveContext context) { | ||
this.context = context; | ||
} | ||
|
||
public ISaveContext getContext() { | ||
return context; | ||
} | ||
} | ||
|
||
private static class SaveFileContext implements ISaveContext { | ||
@Override | ||
public DOMDocument getDocument(String uri) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public void collectDocumentToValidate(Predicate<DOMDocument> validateDocumentPredicate) { | ||
} | ||
|
||
@Override | ||
public SaveContextType getType() { | ||
return SaveContextType.DOCUMENT; | ||
} | ||
|
||
@Override | ||
public String getUri() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public Object getSettings() { | ||
return null; | ||
} | ||
} | ||
|
||
@Test | ||
public void initialConfiguration() { | ||
XMLExtensionsRegistry registry = new XMLExtensionsRegistry(); | ||
ISaveContext settingsSaveContext = new SettingsSaveContext(new JsonObject()); | ||
// initial config passed in during server startup. | ||
registry.doSave(settingsSaveContext); | ||
// then another event comes in from the client | ||
registry.doSave(new SaveFileContext()); | ||
// extension registration is triggered | ||
registry.initializeIfNeeded(); | ||
RegistryTestExtension extension = new RegistryTestExtension(); | ||
registry.registerExtension(extension); | ||
// examine that the extension properly receives the initial config | ||
assertEquals(settingsSaveContext, extension.getContext()); | ||
} | ||
} |