Skip to content

Commit

Permalink
Preference store per language
Browse files Browse the repository at this point in the history
Signed-off-by: azerr <[email protected]>
  • Loading branch information
angelozerr committed Nov 2, 2022
1 parent f002ea8 commit 0cf7dfe
Show file tree
Hide file tree
Showing 35 changed files with 135 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,16 @@
*******************************************************************************/
package org.eclipse.wildwebdeveloper;

import org.eclipse.core.runtime.preferences.InstanceScope;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.eclipse.ui.preferences.ScopedPreferenceStore;
import org.eclipse.wildwebdeveloper.css.CSSLanguageServer;
import org.eclipse.wildwebdeveloper.html.HTMLLanguageServer;
import org.eclipse.wildwebdeveloper.yaml.YAMLLanguageServer;
import org.osgi.framework.BundleContext;

/**
Expand All @@ -28,6 +34,12 @@ public class Activator extends AbstractUIPlugin {

// The shared instance
private static Activator plugin;

private ScopedPreferenceStore cssPreferenceStore;

private ScopedPreferenceStore htmlPreferenceStore;

private ScopedPreferenceStore yamlPreferenceStore;

/**
* The constructor
Expand Down Expand Up @@ -57,8 +69,8 @@ public static Activator getDefault() {
}

/**
* Returns the currently active workbench window shell or <code>null</code>
* if none.
* Returns the currently active workbench window shell or <code>null</code> if
* none.
*
* @return the currently active workbench window shell or <code>null</code>
*/
Expand All @@ -69,10 +81,69 @@ public static Shell getShell() {
if (windows.length > 0) {
return windows[0].getShell();
}
}
else {
} else {
return window.getShell();
}
return null;
}

/**
* Returns the CSS preference store.
*
* @return the CSS preference store.
*/
public IPreferenceStore getCSSPreferenceStore() {
// Create the preference store lazily.
ScopedPreferenceStore result = cssPreferenceStore;
if (result == null) { // First check (no locking)
synchronized (this) {
result = cssPreferenceStore;
if (result == null) { // Second check (with locking)
cssPreferenceStore = result = new ScopedPreferenceStore(InstanceScope.INSTANCE,
CSSLanguageServer.LANGUAGE_SERVER_ID);
}
}
}
return result;
}

/**
* Returns the HTML preference store.
*
* @return the HTML preference store.
*/
public IPreferenceStore getHTMLPreferenceStore() {
// Create the preference store lazily.
ScopedPreferenceStore result = htmlPreferenceStore;
if (result == null) { // First check (no locking)
synchronized (this) {
result = htmlPreferenceStore;
if (result == null) { // Second check (with locking)
htmlPreferenceStore = result = new ScopedPreferenceStore(InstanceScope.INSTANCE,
HTMLLanguageServer.LANGUAGE_SERVER_ID);
}
}
}
return result;
}

/**
* Returns the YAML preference store.
*
* @return the YAML preference store.
*/
public IPreferenceStore getYAMLPreferenceStore() {
// Create the preference store lazily.
ScopedPreferenceStore result = yamlPreferenceStore;
if (result == null) { // First check (no locking)
synchronized (this) {
result = yamlPreferenceStore;
if (result == null) { // Second check (with locking)
yamlPreferenceStore = result = new ScopedPreferenceStore(InstanceScope.INSTANCE,
YAMLLanguageServer.LANGUAGE_SERVER_ID);
}
}
}
return result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@

public class CSSLanguageServer extends ProcessStreamConnectionProviderWithPreference {

private static final String CSS_LANGUAGE_SERVER_ID = "org.eclipse.wildwebdeveloper.css";
public static final String LANGUAGE_SERVER_ID = "org.eclipse.wildwebdeveloper.css";

private static final String[] SUPPORTED_SECTIONS = { "css", "scss", "less" };

public CSSLanguageServer() {
super(CSS_LANGUAGE_SERVER_ID, Activator.getDefault().getPreferenceStore(), SUPPORTED_SECTIONS);
super(LANGUAGE_SERVER_ID, Activator.getDefault().getCSSPreferenceStore(), SUPPORTED_SECTIONS);
List<String> commands = new ArrayList<>();
commands.add(NodeJSManager.getNodeJsLocation().getAbsolutePath());
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,6 @@ public void createFieldEditors() {

@Override
public void init(IWorkbench workbench) {
setPreferenceStore(Activator.getDefault().getPreferenceStore());
setPreferenceStore(Activator.getDefault().getCSSPreferenceStore());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,6 @@ public void createFieldEditors() {

@Override
public void init(IWorkbench workbench) {
setPreferenceStore(Activator.getDefault().getPreferenceStore());
setPreferenceStore(Activator.getDefault().getCSSPreferenceStore());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,6 @@ public void createFieldEditors() {

@Override
public void init(IWorkbench workbench) {
setPreferenceStore(Activator.getDefault().getPreferenceStore());
setPreferenceStore(Activator.getDefault().getCSSPreferenceStore());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public CSSPreferencePage() {

@Override
public void init(IWorkbench workbench) {
setPreferenceStore(Activator.getDefault().getPreferenceStore());
setPreferenceStore(Activator.getDefault().getCSSPreferenceStore());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public class CSSPreferenceServerConstants {
public static final String CSS_PREFERENCES_LINT_UNKNOWNATRULES = "css.lint.unknownAtRules";

public static Settings getGlobalSettings() {
Settings settings = new Settings(Activator.getDefault().getPreferenceStore());
Settings settings = new Settings(getPreferenceStore());

// Completion settings
settings.fillAsBoolean(CSS_PREFERENCES_COMPLETION_TRIGGER_PROPERTY_VALUE_COMPLETION);
Expand Down Expand Up @@ -117,7 +117,7 @@ public static Settings getGlobalSettings() {
}

public static void initializeDefaultPreferences() {
IPreferenceStore store = Activator.getDefault().getPreferenceStore();
IPreferenceStore store = getPreferenceStore();

// Server settings

Expand Down Expand Up @@ -174,4 +174,14 @@ public static void initializeDefaultPreferences() {
public static boolean isMatchCssSection(String section) {
return isMatchSection(section, CSS_SECTION);
}

/**
* Returns the CSS preference store.
*
* @return the CSS preference store.
*/
public static IPreferenceStore getPreferenceStore() {
return Activator.getDefault().getPreferenceStore();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,6 @@ private void addSeverityField(String name, String labelText) {

@Override
public void init(IWorkbench workbench) {
setPreferenceStore(Activator.getDefault().getPreferenceStore());
setPreferenceStore(Activator.getDefault().getCSSPreferenceStore());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,6 @@ public void createFieldEditors() {

@Override
public void init(IWorkbench workbench) {
setPreferenceStore(Activator.getDefault().getPreferenceStore());
setPreferenceStore(Activator.getDefault().getCSSPreferenceStore());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,6 @@ public void createFieldEditors() {

@Override
public void init(IWorkbench workbench) {
setPreferenceStore(Activator.getDefault().getPreferenceStore());
setPreferenceStore(Activator.getDefault().getCSSPreferenceStore());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,6 @@ public void createFieldEditors() {

@Override
public void init(IWorkbench workbench) {
setPreferenceStore(Activator.getDefault().getPreferenceStore());
setPreferenceStore(Activator.getDefault().getCSSPreferenceStore());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public LESSPreferencePage() {

@Override
public void init(IWorkbench workbench) {
setPreferenceStore(Activator.getDefault().getPreferenceStore());
setPreferenceStore(Activator.getDefault().getCSSPreferenceStore());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public class LESSPreferenceServerConstants {
public static final String LESS_PREFERENCES_LINT_UNKNOWNATRULES = "less.lint.unknownAtRules";

public static Settings getGlobalSettings() {
Settings settings = new Settings(Activator.getDefault().getPreferenceStore());
Settings settings = new Settings(Activator.getDefault().getCSSPreferenceStore());

// Completion settings
settings.fillAsBoolean(LESS_PREFERENCES_COMPLETION_TRIGGER_PROPERTY_VALUE_COMPLETION);
Expand Down Expand Up @@ -117,7 +117,7 @@ public static Settings getGlobalSettings() {
}

public static void initializeDefaultPreferences() {
IPreferenceStore store = Activator.getDefault().getPreferenceStore();
IPreferenceStore store = Activator.getDefault().getCSSPreferenceStore();

// Server settings

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,6 @@ private void addSeverityField(String name, String labelText) {

@Override
public void init(IWorkbench workbench) {
setPreferenceStore(Activator.getDefault().getPreferenceStore());
setPreferenceStore(Activator.getDefault().getCSSPreferenceStore());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,6 @@ public void createFieldEditors() {

@Override
public void init(IWorkbench workbench) {
setPreferenceStore(Activator.getDefault().getPreferenceStore());
setPreferenceStore(Activator.getDefault().getCSSPreferenceStore());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,6 @@ public void createFieldEditors() {

@Override
public void init(IWorkbench workbench) {
setPreferenceStore(Activator.getDefault().getPreferenceStore());
setPreferenceStore(Activator.getDefault().getCSSPreferenceStore());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,6 @@ public void createFieldEditors() {

@Override
public void init(IWorkbench workbench) {
setPreferenceStore(Activator.getDefault().getPreferenceStore());
setPreferenceStore(Activator.getDefault().getCSSPreferenceStore());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public SCSSPreferencePage() {

@Override
public void init(IWorkbench workbench) {
setPreferenceStore(Activator.getDefault().getPreferenceStore());
setPreferenceStore(Activator.getDefault().getCSSPreferenceStore());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public class SCSSPreferenceServerConstants {
public static final String SCSS_PREFERENCES_LINT_UNKNOWNATRULES = "scss.lint.unknownAtRules";

public static Settings getGlobalSettings() {
Settings settings = new Settings(Activator.getDefault().getPreferenceStore());
Settings settings = new Settings(Activator.getDefault().getCSSPreferenceStore());

// Completion settings
settings.fillAsBoolean(SCSS_PREFERENCES_COMPLETION_TRIGGER_PROPERTY_VALUE_COMPLETION);
Expand Down Expand Up @@ -117,7 +117,7 @@ public static Settings getGlobalSettings() {
}

public static void initializeDefaultPreferences() {
IPreferenceStore store = Activator.getDefault().getPreferenceStore();
IPreferenceStore store = Activator.getDefault().getCSSPreferenceStore();

// Server settings

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,6 @@ private void addSeverityField(String name, String labelText) {

@Override
public void init(IWorkbench workbench) {
setPreferenceStore(Activator.getDefault().getPreferenceStore());
setPreferenceStore(Activator.getDefault().getCSSPreferenceStore());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@
*/
public class HTMLLanguageServer extends ProcessStreamConnectionProviderWithPreference {

private static final String HTML_LANGUAGE_SERVER_ID = "org.eclipse.wildwebdeveloper.html";
public static final String LANGUAGE_SERVER_ID = "org.eclipse.wildwebdeveloper.html";

private static final String[] SUPPORTED_SECTIONS = { "html", "css", "javascript" };

public HTMLLanguageServer() {
super(HTML_LANGUAGE_SERVER_ID, Activator.getDefault().getPreferenceStore(), SUPPORTED_SECTIONS);
super(LANGUAGE_SERVER_ID, Activator.getDefault().getHTMLPreferenceStore(), SUPPORTED_SECTIONS);
List<String> commands = new ArrayList<>();
commands.add(NodeJSManager.getNodeJsLocation().getAbsolutePath());
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,11 @@ private void autoInsert(DocumentEvent event) {
}

private boolean isAutoClosingTagEnabled() {
return Activator.getDefault().getPreferenceStore().getBoolean(HTML_PREFERENCES_AUTO_CLOSING_TAGS);
return Activator.getDefault().getHTMLPreferenceStore().getBoolean(HTML_PREFERENCES_AUTO_CLOSING_TAGS);
}

private boolean isAutoCreateQuotesEnabled() {
return Activator.getDefault().getPreferenceStore().getBoolean(HTML_PREFERENCES_AUTO_CREATE_QUOTES);
return Activator.getDefault().getHTMLPreferenceStore().getBoolean(HTML_PREFERENCES_AUTO_CREATE_QUOTES);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,6 @@ public void createFieldEditors() {

@Override
public void init(IWorkbench workbench) {
setPreferenceStore(Activator.getDefault().getPreferenceStore());
setPreferenceStore(Activator.getDefault().getHTMLPreferenceStore());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,6 @@ public void createFieldEditors() {

@Override
public void init(IWorkbench workbench) {
setPreferenceStore(Activator.getDefault().getPreferenceStore());
setPreferenceStore(Activator.getDefault().getHTMLPreferenceStore());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,6 @@ public void createFieldEditors() {

@Override
public void init(IWorkbench workbench) {
setPreferenceStore(Activator.getDefault().getPreferenceStore());
setPreferenceStore(Activator.getDefault().getHTMLPreferenceStore());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,16 @@ public HTMLPreferencePage() {
super(GRID);
}

@Override
public void init(IWorkbench workbench) {
setPreferenceStore(Activator.getDefault().getPreferenceStore());
}

@Override
protected void createFieldEditors() {
addField(new BooleanFieldEditor(HTML_PREFERENCES_AUTO_CLOSING_TAGS, Messages.HTMLPreferencePage_autoClosingTags,
getFieldEditorParent()));
addField(new BooleanFieldEditor(HTML_PREFERENCES_AUTO_CREATE_QUOTES,
Messages.HTMLPreferencePage_autoCreateQuotes, getFieldEditorParent()));
}

@Override
public void init(IWorkbench workbench) {
setPreferenceStore(Activator.getDefault().getHTMLPreferenceStore());
}
}
Loading

0 comments on commit 0cf7dfe

Please sign in to comment.