下面列出了怎么用org.eclipse.lsp4j.DidChangeConfigurationParams的API类实例代码及写法,或者点击链接到github查看源代码。
@Override
public void handleMessage(Message message, LanguageServer languageServer, URI rootUri) {
IPreferenceStore preferenceStore = Activator.getDefault().getPreferenceStore();
String schemaStr = preferenceStore.getString(YAMLPreferenceInitializer.YAML_SCHEMA_PREFERENCE);
if (cachedSchema == null || !schemaStr.equals(cachedSchema)) {
cachedSchema = schemaStr;
Map<String, Object> schemas = new Gson().fromJson(schemaStr, new TypeToken<HashMap<String, Object>>() {}.getType());
Map<String, Object> yaml = new HashMap<>();
yaml.put("schemas", schemas);
yaml.put("validate", true);
yaml.put("completion", true);
yaml.put("hover", true);
Map<String, Object> settings = new HashMap<>();
settings.put("yaml", yaml);
DidChangeConfigurationParams params = new DidChangeConfigurationParams(settings);
languageServer.getWorkspaceService().didChangeConfiguration(params);
}
}
@Override
public void handleMessage(Message message, LanguageServer languageServer, URI rootUri) {
if (message instanceof ResponseMessage) {
ResponseMessage responseMessage = (ResponseMessage) message;
if (responseMessage.getResult() instanceof InitializeResult) {
Map<String, Object> htmlOptions = new HashMap<>();
Map<String, Object> validateOptions = new HashMap<>();
validateOptions.put("scripts", true);
validateOptions.put("styles", true);
htmlOptions.put("validate", validateOptions);
htmlOptions.put("format", Collections.singletonMap("enable", Boolean.TRUE));
Map<String, Object> html = new HashMap<>();
html.put("html", htmlOptions);
DidChangeConfigurationParams params = new DidChangeConfigurationParams(html);
languageServer.getWorkspaceService().didChangeConfiguration(params);
}
}
}
@SuppressWarnings("unchecked")
@Override
public void didChangeConfiguration(DidChangeConfigurationParams params) {
if (!(params.getSettings() instanceof JsonObject)) {
return;
}
JsonObject settings = (JsonObject) params.getSettings();
if (settings.has(VIRTUALIZATION_NAME_ID)) {
JsonElement element = settings.get(VIRTUALIZATION_NAME_ID);
String virtualizationName = element.getAsString();
if (virtualizationName != null) {
LOGGER.info("Setting language server metadata scope to the virtualization: " + virtualizationName);
this.currentVirtualizationName = virtualizationName;
}
}
}
@Override
public void didChangeConfiguration(DidChangeConfigurationParams params) {
if (!(params.getSettings() instanceof JsonObject)) {
return;
}
JsonObject settings = (JsonObject) params.getSettings();
this.updateClasspath(settings);
}
@Test
void testUpdateOfConfig() throws Exception {
CamelLanguageServer camelLanguageServer = initializeLanguageServer("<from uri=\"\" xmlns=\"http://camel.apache.org/schema/blueprint\"></from>\n");
CompletableFuture<Either<List<CompletionItem>, CompletionList>> completions = getCompletionFor(camelLanguageServer, new Position(0, 11));
assertThat(completions.get().getLeft()).contains(createBasicExpectedCompletionItem());
String component = "{\n" +
" \"component\": {\n" +
" \"kind\": \"component\",\n" +
" \"scheme\": \"aSecondcomponent\",\n" +
" \"syntax\": \"aSecondcomponent:withsyntax\",\n" +
" \"title\": \"A Second Component\",\n" +
" \"description\": \"Description of my second component.\",\n" +
" \"label\": \"\",\n" +
" \"deprecated\": false,\n" +
" \"deprecationNote\": \"\",\n" +
" \"async\": false,\n" +
" \"consumerOnly\": true,\n" +
" \"producerOnly\": false,\n" +
" \"lenientProperties\": false,\n" +
" \"javaType\": \"org.test.ASecondComponent\",\n" +
" \"firstVersion\": \"1.0.0\",\n" +
" \"groupId\": \"org.test\",\n" +
" \"artifactId\": \"camel-asecondcomponent\",\n" +
" \"version\": \"3.0.0-RC3\"\n" +
" },\n" +
" \"componentProperties\": {\n" +
" },\n" +
" \"properties\": {\n" +
" }\n" +
"}";
DidChangeConfigurationParams params = new DidChangeConfigurationParams(createMapSettingsWithComponent(component));
camelLanguageServer.getWorkspaceService().didChangeConfiguration(params);
assertThat(getCompletionFor(camelLanguageServer, new Position(0, 11)).get().getLeft())
.contains(createExpectedExtraComponentCompletionItem(0, 11, 0, 11, "aSecondcomponent:withsyntax", "Description of my second component."));
}
@Override
public void handleMessage(Message message, LanguageServer languageServer, URI rootUri) {
if (message instanceof ResponseMessage) {
ResponseMessage responseMessage = (ResponseMessage)message;
if (responseMessage.getResult() instanceof InitializeResult) {
// enable validation: so far, no better way found than changing conf after init.
DidChangeConfigurationParams params = new DidChangeConfigurationParams(getInitializationOptions(rootUri));
languageServer.getWorkspaceService().didChangeConfiguration(params);
}
}
}
@Override
public void propertyChange(PropertyChangeEvent event) {
// TODO Auto-generated method stub
if (XMLPreferenceInitializer.XML_PREFERENCES_CATAGLOGS.equals(event.getProperty())) {
Map<String, Object> config = mergeCustomInitializationOptions(extensionJarRegistry.getInitiatizationOptions());
DidChangeConfigurationParams params = new DidChangeConfigurationParams(
Collections.singletonMap(XML_KEY, ((Map)config.get(SETTINGS_KEY)).get(XML_KEY)));
LanguageServiceAccessor.getActiveLanguageServers(null).stream().filter(server -> lemminxDefinition.equals(LanguageServiceAccessor.resolveServerDefinition(server).get()))
.forEach(ls -> ls.getWorkspaceService().didChangeConfiguration(params));
}
}
private static void sendDidChangeConfigurationsMessage(Map<String, String> updatedSettings) {
DidChangeConfigurationParams params = new DidChangeConfigurationParams();
params.setSettings(updatedSettings);
LSPDocumentInfo info = infoFromOpenEditors();
if (info != null) {
info.getInitializedLanguageClient()
.thenAccept(languageServer -> languageServer.getWorkspaceService().didChangeConfiguration(params));
}
}
@Override
public void didChangeConfiguration(DidChangeConfigurationParams params) {
logInfo(">> workspace/didChangeConfiguration");
Object settings = JSONUtility.toModel(params.getSettings(), Map.class);
if (settings instanceof Map) {
Collection<IPath> rootPaths = preferenceManager.getPreferences().getRootPaths();
@SuppressWarnings("unchecked")
Preferences prefs = Preferences.createFrom((Map<String, Object>) settings);
prefs.setRootPaths(rootPaths);
preferenceManager.update(prefs);
}
}
@Test
public void testAutobuilding() throws Exception {
boolean enabled = isAutoBuilding();
try {
assertTrue("Autobuilding is off", isAutoBuilding());
Map<String, Object> map = new HashMap<>();
map.put(Preferences.AUTOBUILD_ENABLED_KEY, false);
DidChangeConfigurationParams params = new DidChangeConfigurationParams(map);
server.didChangeConfiguration(params);
assertFalse("Autobuilding is on", isAutoBuilding());
} finally {
projManager.setAutoBuilding(enabled);
}
}
@Override
public void didChangeConfiguration(DidChangeConfigurationParams params)
{
if(!(params.getSettings() instanceof JsonObject))
{
return;
}
JsonObject settings = (JsonObject) params.getSettings();
this.updateSDK(settings);
this.updateRealTimeProblems(settings);
this.updateSourcePathWarning(settings);
this.updateJVMArgs(settings);
}
@Override
public void didChangeConfiguration(DidChangeConfigurationParams params) {
requestManager.runWrite(() -> {
workspaceManager.refreshWorkspaceConfig(CancelIndicator.NullImpl);
return null;
}, (a, b) -> null);
}
@SuppressWarnings("unused")
public static void didChangeConfiguration(@NotNull DidChangeConfigurationParams params, @NotNull Project project) {
final Set<LanguageServerWrapper> serverWrappers = IntellijLanguageClient.getProjectToLanguageWrappers()
.get(FileUtils.projectToUri(project));
serverWrappers.forEach(s -> s.getRequestManager().didChangeConfiguration(params));
}
@Override
public void didChangeConfiguration(DidChangeConfigurationParams params) {
xmlLanguageServer.updateSettings(params.getSettings());
xmlLanguageServer.capabilityManager.syncDynamicCapabilitiesWithPreferences();
}
@Override
public void didChangeConfiguration(DidChangeConfigurationParams params) {
Object settings = params.getSettings();
settingsManager.apply(params);
LOGGER.info("SERVER: changeConfig: settings -> {}", settings);
}
public void apply(DidChangeConfigurationParams params) {
applySettings(params.getSettings());
}
@Override
public void didChangeConfiguration(DidChangeConfigurationParams params) {
}
@Override
public void didChangeConfiguration(DidChangeConfigurationParams params) {
reinitWorkspace();
}
@Override
public void didChangeConfiguration(DidChangeConfigurationParams arg0) {
//TODO: no real configuration right now
}
@Override
public void didChangeConfiguration(DidChangeConfigurationParams params) {
}
@Override
public void didChangeConfiguration(DidChangeConfigurationParams params) {
log.info("didChangeConfiguration");
}
@Test
void testUpdateOfConfig() throws Exception {
camelCatalogVersion = "3.0.0-RC3";
CamelLanguageServer camelLanguageServer = basicCompletionCheckBefore3_3();
assertThat(camelLanguageServer.getTextDocumentService().getCamelCatalog().get().getLoadedVersion()).isEqualTo(camelCatalogVersion);
DidChangeConfigurationParams params = new DidChangeConfigurationParams(createMapSettingsWithVersion("2.23.4"));
camelLanguageServer.getWorkspaceService().didChangeConfiguration(params);
checkLoadedCamelCatalogVersion(camelLanguageServer, "2.23.4");
}
/**
* A notification sent from the client to the server to signal the change of
* configuration settings.
*/
@JsonNotification
void didChangeConfiguration(DidChangeConfigurationParams params);