Skip to content

Commit

Permalink
Cannot use provided schemas eclipse-wildwebdeveloper#461
Browse files Browse the repository at this point in the history
Fixed preferernce listener installation

Fixes: eclipse-wildwebdeveloper#461

Signed-off-by: Victor Rubezhny <vrubezhny@redhat.com>
  • Loading branch information
vrubezhny committed Jul 23, 2020
1 parent 60c8616 commit 16b7cff
Showing 1 changed file with 10 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@

@SuppressWarnings("restriction")
public class YAMLLanguageServer extends ProcessStreamConnectionProvider {
private static final String SETTINGS_KEY = "settings";
private static final String YAML_KEY = "yaml";
private static final String VALIDATE_KEY = "validate";
private static final String COMPLETION_KEY = "completion";
Expand All @@ -53,22 +52,16 @@ public class YAMLLanguageServer extends ProcessStreamConnectionProvider {
@Override
public void propertyChange(PropertyChangeEvent event) {
if (YAMLPreferenceInitializer.YAML_SCHEMA_PREFERENCE.equals(event.getProperty())) {
Map<String, Object> yaml = getYamlSchemaOptions();
Map<String, Object> settings = new HashMap<>();
settings.put(YAML_KEY, yaml);
Map<String, Object> options = new HashMap<>();
options.put(SETTINGS_KEY, settings);
settings.put(YAML_KEY, getYamlConfigurationOptions());

DidChangeConfigurationParams params = new DidChangeConfigurationParams(settings);
LanguageServiceAccessor.getActiveLanguageServers(null).stream().filter(server -> yamlLsDefinition.equals(LanguageServiceAccessor.resolveServerDefinition(server).get()))
.forEach(ls -> ls.getWorkspaceService().didChangeConfiguration(params));
}
}
};

static {
store.addPropertyChangeListener(psListener);
}

public YAMLLanguageServer() {
List<String> commands = new ArrayList<>();
commands.add(NodeJSManager.getNodeJsLocation().getAbsolutePath());
Expand All @@ -91,15 +84,15 @@ public void handleMessage(Message message, LanguageServer languageServer, URI ro
ResponseMessage responseMessage = (ResponseMessage) message;
if (responseMessage.getResult() instanceof InitializeResult) {
Map<String, Object> settings = new HashMap<>();
settings.put(YAML_KEY, getYamlSchemaOptions());
settings.put(YAML_KEY, getYamlConfigurationOptions());

DidChangeConfigurationParams params = new DidChangeConfigurationParams(settings);
languageServer.getWorkspaceService().didChangeConfiguration(params);
}
}
}

private static Map<String, Object> getYamlSchemaOptions() {
private static Map<String, Object> getYamlConfigurationOptions() {
Map<String, Object> yaml = new HashMap<>();
IPreferenceStore preferenceStore = Activator.getDefault().getPreferenceStore();
String schemaStr = preferenceStore.getString(YAMLPreferenceInitializer.YAML_SCHEMA_PREFERENCE);
Expand All @@ -116,6 +109,12 @@ public String toString() {
return "YAML Language Server: " + super.toString();
}

@Override
public void start() throws IOException {
super.start();
store.addPropertyChangeListener(psListener);
}

@Override
public void stop() {
store.removePropertyChangeListener(psListener);
Expand Down

0 comments on commit 16b7cff

Please sign in to comment.