Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow using TypeScript version specified by project #1308

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions org.eclipse.wildwebdeveloper/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,15 @@
<icon contentType="org.eclipse.wildwebdeveloper.tsx" icon="icons/tsEditorIcon.png"/>
</extension>

<extension
id="JSTSPreferenceInitializer"
name="JSTSPreferenceInitializer"
point="org.eclipse.core.runtime.preferences">
<initializer
class="org.eclipse.wildwebdeveloper.jsts.ui.preferences.JSTSPreferenceInitializer">
</initializer>
</extension>

<extension
id="JavaScriptPreferenceInitializer"
name="JavaScriptPreferenceInitializer"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2016 Red Hat Inc. and others.
* Copyright (c) 2016-2023 Red Hat Inc. and others.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
Expand All @@ -10,9 +10,13 @@
* Contributors:
* Mickael Istria (Red Hat Inc.) - initial implementation
* Andrew Obuchowicz (Red Hat Inc.) - Add ESLint support
* Pierre-Yves Bigourdan - Allow using TypeScript version specified by project
*******************************************************************************/
package org.eclipse.wildwebdeveloper.jsts;

import static org.eclipse.wildwebdeveloper.jsts.ui.preferences.JSTSPreferenceServerConstants.TYPESCRIPT_PREFERENCES_TSSERVER_TYPESCRIPT_VERSION_PROJECT;
import static org.eclipse.wildwebdeveloper.jsts.ui.preferences.JSTSPreferenceServerConstants.getTypeScriptVersion;

import java.io.File;
import java.io.IOException;
import java.net.URI;
Expand Down Expand Up @@ -77,10 +81,13 @@ public Object getInitializationOptions(URI rootUri) {
plugins.add(new TypeScriptPlugin("typescript-lit-html-plugin"));
options.put("plugins", plugins.stream().map(TypeScriptPlugin::toMap).toArray());

// Initialize tsserver path
Map<String, String> tsServer = new HashMap<>();
tsServer.put("path", tsserverPath);
options.put("tsserver", tsServer);
// If the tsserver path is not explicitly specified, tsserver will use the local
// TypeScript version installed as part of the project's dependencies, if found.
if (!TYPESCRIPT_PREFERENCES_TSSERVER_TYPESCRIPT_VERSION_PROJECT.equals(getTypeScriptVersion())) {
Map<String, String> tsServer = new HashMap<>();
tsServer.put("path", tsserverPath);
options.put("tsserver", tsServer);
}
} catch (IOException e) {
Activator.getDefault().getLog().log(
new Status(IStatus.ERROR, Activator.getDefault().getBundle().getSymbolicName(), e.getMessage(), e));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2022 Red Hat Inc. and others.
* Copyright (c) 2022-2023 Red Hat Inc. and others.
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
Expand All @@ -8,6 +8,7 @@
*
* Contributors:
* Angelo ZERR (Red Hat Inc.) - initial implementation
* Pierre-Yves Bigourdan - Allow using TypeScript version specified by project
*******************************************************************************/
package org.eclipse.wildwebdeveloper.jsts.ui;

Expand All @@ -19,6 +20,10 @@
*/
public class Messages extends NLS {

public static String JSTSPreferencePage_typeScriptVersion;
public static String JSTSPreferencePage_typeScriptVersion_eclipse;
public static String JSTSPreferencePage_typeScriptVersion_project;

// --------- TypeScript Inlay Hints preference page
public static String TypeScriptInlayHintPreferencePage_showInlayHintsFor_label;
public static String TypeScriptInlayHintPreferencePage_includeInlayEnumMemberValueHints;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#/*******************************************************************************
# * Copyright (c) 2022 Red Hat Inc. and others.
# * Copyright (c) 2022-2023 Red Hat Inc. and others.
# * This program and the accompanying materials are made
# * available under the terms of the Eclipse Public License 2.0
# * which is available at https://www.eclipse.org/legal/epl-2.0/
Expand All @@ -8,8 +8,14 @@
# *
# * Contributors:
# * Angelo ZERR (Red Hat Inc.) - initial implementation
# * Pierre-Yves Bigourdan - Allow using TypeScript version specified by project
# *******************************************************************************/

JSTSPreferencePage_typeScriptVersion=Typescript version used for JavaScript and TypeScript language features:
JSTSPreferencePage_typeScriptVersion_eclipse=Eclipse version
JSTSPreferencePage_typeScriptVersion_project=Project version


# TypeScript Inlay Hints preference page
TypeScriptInlayHintPreferencePage_showInlayHintsFor_label=Show inlay hints for:
TypeScriptInlayHintPreferencePage_includeInlayEnumMemberValueHints=member values in enum declarations.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*******************************************************************************
* Copyright (c) 2023 Red Hat Inc. and others.
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Pierre-Yves Bigourdan - initial implementation
*******************************************************************************/
package org.eclipse.wildwebdeveloper.jsts.ui.preferences;

import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer;

/**
* JS/TS preference initializer.
*
*/
public class JSTSPreferenceInitializer extends AbstractPreferenceInitializer {

@Override
public void initializeDefaultPreferences() {
JSTSPreferenceServerConstants.initializeDefaultPreferences();
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2022 Red Hat Inc. and others.
* Copyright (c) 2022-2023 Red Hat Inc. and others.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
Expand All @@ -12,10 +12,17 @@
*******************************************************************************/
package org.eclipse.wildwebdeveloper.jsts.ui.preferences;

import static org.eclipse.wildwebdeveloper.jsts.ui.preferences.JSTSPreferenceServerConstants.TYPESCRIPT_PREFERENCES_TSSERVER_TYPESCRIPT_VERSION;
import static org.eclipse.wildwebdeveloper.jsts.ui.preferences.JSTSPreferenceServerConstants.TYPESCRIPT_PREFERENCES_TSSERVER_TYPESCRIPT_VERSION_ECLIPSE;
import static org.eclipse.wildwebdeveloper.jsts.ui.preferences.JSTSPreferenceServerConstants.TYPESCRIPT_PREFERENCES_TSSERVER_TYPESCRIPT_VERSION_PROJECT;

import org.eclipse.jface.preference.ComboFieldEditor;
import org.eclipse.jface.preference.FieldEditorPreferencePage;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPreferencePage;
import org.eclipse.wildwebdeveloper.Activator;
import org.eclipse.wildwebdeveloper.jsts.ui.Messages;

/**
* JS/TS main preference page.
Expand All @@ -34,5 +41,14 @@ public void init(IWorkbench workbench) {

@Override
protected void createFieldEditors() {
Composite parent = getFieldEditorParent();
addField(new ComboFieldEditor(TYPESCRIPT_PREFERENCES_TSSERVER_TYPESCRIPT_VERSION,
Messages.JSTSPreferencePage_typeScriptVersion,
new String[][] {
{ Messages.JSTSPreferencePage_typeScriptVersion_eclipse,
TYPESCRIPT_PREFERENCES_TSSERVER_TYPESCRIPT_VERSION_ECLIPSE },
{ Messages.JSTSPreferencePage_typeScriptVersion_project,
TYPESCRIPT_PREFERENCES_TSSERVER_TYPESCRIPT_VERSION_PROJECT } },
parent));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*******************************************************************************
vrubezhny marked this conversation as resolved.
Show resolved Hide resolved
* Copyright (c) 2023 Red Hat Inc. and others.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Pierre-Yves Bigourdan - initial implementation
*******************************************************************************/
package org.eclipse.wildwebdeveloper.jsts.ui.preferences;

import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.wildwebdeveloper.Activator;

/**
* JS/TS preference server constants.
*
*/
public class JSTSPreferenceServerConstants {

public static final String TYPESCRIPT_PREFERENCES_TSSERVER_TYPESCRIPT_VERSION = "typescript.tsserver.typescript.version";

public static final String TYPESCRIPT_PREFERENCES_TSSERVER_TYPESCRIPT_VERSION_ECLIPSE = "Eclipse version";
public static final String TYPESCRIPT_PREFERENCES_TSSERVER_TYPESCRIPT_VERSION_PROJECT = "Project version";

public static String getTypeScriptVersion() {
IPreferenceStore store = Activator.getDefault().getPreferenceStore();
return store.getString(TYPESCRIPT_PREFERENCES_TSSERVER_TYPESCRIPT_VERSION);
}

public static void initializeDefaultPreferences() {
IPreferenceStore store = Activator.getDefault().getPreferenceStore();
store.setDefault(TYPESCRIPT_PREFERENCES_TSSERVER_TYPESCRIPT_VERSION, TYPESCRIPT_PREFERENCES_TSSERVER_TYPESCRIPT_VERSION_ECLIPSE);
}
}