Skip to content

Commit 573f251

Browse files
author
angelozerr
committed
Implement JSX syntax coloration. See
#11
1 parent eb58cdb commit 573f251

18 files changed

+1523
-28
lines changed
Loading

eclipse/jsdt/ts.eclipse.ide.jsdt.ui/plugin.properties

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ TypeScriptHyperLinkDetector=TypeScript Element
1717
# Editor
1818
JavaScriptEditor.name=JavaScript (Salsa) Editor
1919
TypeScriptEditor.name=TypeScript Editor
20+
JSXEditor.name=JSX Editor
2021

2122
# Hover
2223
ProblemTypeScriptHover= TypeScript Problem

eclipse/jsdt/ts.eclipse.ide.jsdt.ui/plugin.xml

+32-7
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313
###############################################################################
1414
-->
1515
<plugin>
16-
17-
<!-- TypeScript editor -->
1816

1917
<extension
2018
id="TypeScriptDocumentSetupParticipant"
@@ -23,10 +21,10 @@
2321
<participant
2422
contentTypeId="ts.eclipse.ide.core.tsSource"
2523
extensions="ts,tsx,jsx"
26-
class="org.eclipse.wst.jsdt.internal.ui.javaeditor.JavaDocumentSetupParticipant">
24+
class="ts.eclipse.ide.jsdt.internal.ui.editor.TypeScriptDocumentSetupParticipant">
2725
</participant>
2826
</extension>
29-
27+
3028
<!-- JavaScript Editor -->
3129
<extension
3230
point="org.eclipse.ui.editors">
@@ -54,13 +52,28 @@
5452
class="ts.eclipse.ide.jsdt.internal.ui.editor.TypeScriptEditor"
5553
symbolicFontName="org.eclipse.wst.jsdt.ui.editors.textfont"
5654
id="ts.eclipse.ide.jsdt.ui.editor.TypeScriptEditor"
57-
extensions="ts,tsx,jsx">
55+
extensions="ts">
5856
<contentTypeBinding contentTypeId="ts.eclipse.ide.core.tsSource" />
59-
<contentTypeBinding contentTypeId="ts.eclipse.ide.core.tsxSource" />
57+
</editor>
58+
</extension>
59+
60+
<!-- JSX Editor -->
61+
<extension
62+
point="org.eclipse.ui.editors">
63+
<editor
64+
name="%JSXEditor.name"
65+
default="true"
66+
icon="$nl$/icons/full/obj16/jsx.png"
67+
contributorClass="ts.eclipse.ide.jsdt.internal.ui.editor.TypeScriptEditorActionContributor"
68+
class="ts.eclipse.ide.jsdt.internal.ui.editor.TypeScriptEditor"
69+
symbolicFontName="org.eclipse.wst.jsdt.ui.editors.textfont"
70+
id="ts.eclipse.ide.jsdt.ui.editor.JSXEditor"
71+
extensions="jsx,tsx">
6072
<contentTypeBinding contentTypeId="ts.eclipse.ide.core.jsxSource" />
73+
<contentTypeBinding contentTypeId="ts.eclipse.ide.core.tsxSource" />
6174
</editor>
6275
</extension>
63-
76+
6477
<!-- dark theme defaults -->
6578
<extension
6679
point="org.eclipse.e4.ui.css.swt.theme">
@@ -82,6 +95,14 @@
8295
<javaCompletionProposalComputer
8396
class="ts.eclipse.ide.jsdt.internal.ui.editor.contentassist.TypeScriptCompletionProposalComputer"
8497
categoryId="ts.eclipse.ide.jsdt.ui.TypeScriptCompletionProposalCategory">
98+
<partition type="__dftl_partition_content_type"/>
99+
<partition type="__java_singleline_comment"/>
100+
<partition type="__java_multiline_comment"/>
101+
<partition type="__javascript_template_literal"/>
102+
<partition type="__java_string"/>
103+
<partition type="__java_character"/>
104+
<partition type="__java_javadoc"/>
105+
<partition type="__jsx"/>
85106
</javaCompletionProposalComputer>
86107
</extension>
87108

@@ -497,4 +518,8 @@
497518
</viewerContribution>
498519
</extension>
499520

521+
<extension point="org.eclipse.core.runtime.preferences">
522+
<initializer class="ts.eclipse.ide.jsdt.internal.ui.JSDTTypeScriptUIPreferenceInitializer"/>
523+
</extension>
524+
500525
</plugin>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/**
2+
* Copyright (c) 2015-2016 Angelo ZERR.
3+
* All rights reserved. This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License v1.0
5+
* which accompanies this distribution, and is available at
6+
* http://www.eclipse.org/legal/epl-v10.html
7+
*
8+
* Contributors:
9+
* Angelo Zerr <[email protected]> - initial API and implementation
10+
*/
11+
package ts.eclipse.ide.jsdt.internal.ui;
12+
13+
import ts.eclipse.ide.jsdt.ui.PreferenceConstants;
14+
15+
/**
16+
* Defines the constants used in the <code>org.eclipse.ui.themes</code>
17+
* extension contributed by this plug-in.
18+
*
19+
*
20+
*/
21+
public interface ITypeScriptThemeConstants {
22+
23+
String ID_PREFIX = JSDTTypeScriptUIPlugin.PLUGIN_ID + "."; //$NON-NLS-1$
24+
25+
/**
26+
* A theme constant that holds the color used to render JSX tag border
27+
* constants.
28+
*/
29+
public final String EDITOR_JSX_TAG_BORDER_COLOR = ID_PREFIX + PreferenceConstants.EDITOR_JSX_TAG_BORDER_COLOR;
30+
31+
/**
32+
* A theme constant that holds the color used to render JSX tag name
33+
* constants.
34+
*/
35+
public final String EDITOR_JSX_TAG_NAME_COLOR = ID_PREFIX + PreferenceConstants.EDITOR_JSX_TAG_NAME_COLOR;
36+
37+
/**
38+
* A theme constant that holds the color used to render JSX tag attribute
39+
* name constants.
40+
*/
41+
public final String EDITOR_JSX_TAG_ATTRIBUTE_NAME_COLOR = ID_PREFIX
42+
+ PreferenceConstants.EDITOR_JSX_TAG_ATTRIBUTE_NAME_COLOR;
43+
44+
/**
45+
* A theme constant that holds the color used to render JSX tag attribute
46+
* value constants.
47+
*/
48+
public final String EDITOR_JSX_TAG_ATTRIBUTE_VALUE_COLOR = ID_PREFIX
49+
+ PreferenceConstants.EDITOR_JSX_TAG_ATTRIBUTE_VALUE_COLOR;
50+
}

eclipse/jsdt/ts.eclipse.ide.jsdt.ui/src/ts/eclipse/ide/jsdt/internal/ui/JSDTTypeScriptUIPlugin.java

+28
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,17 @@
1111
*/
1212
package ts.eclipse.ide.jsdt.internal.ui;
1313

14+
import org.eclipse.core.runtime.IStatus;
15+
import org.eclipse.core.runtime.Status;
1416
import org.eclipse.swt.widgets.Shell;
1517
import org.eclipse.ui.IWorkbenchWindow;
1618
import org.eclipse.ui.plugin.AbstractUIPlugin;
1719
import org.eclipse.ui.texteditor.IDocumentProvider;
20+
import org.eclipse.wst.jsdt.core.JavaScriptCore;
1821
import org.osgi.framework.BundleContext;
1922

2023
import ts.eclipse.ide.jsdt.internal.ui.editor.TypeScriptDocumentProvider;
24+
import ts.eclipse.ide.jsdt.internal.ui.text.TypeScriptTextTools;
2125

2226
/**
2327
* The activator class controls the plug-in life cycle
@@ -27,11 +31,15 @@ public class JSDTTypeScriptUIPlugin extends AbstractUIPlugin {
2731
// The plug-in ID
2832
public static final String PLUGIN_ID = "ts.eclipse.ide.jsdt.ui"; //$NON-NLS-1$
2933

34+
private static final int INTERNAL_ERROR = 10001;
35+
3036
// The shared instance
3137
private static JSDTTypeScriptUIPlugin plugin;
3238

3339
private TypeScriptDocumentProvider documentProvider;
3440

41+
private TypeScriptTextTools fJavaTextTools;
42+
3543
/**
3644
* The constructor
3745
*/
@@ -87,4 +95,24 @@ public static Shell getActiveWorkbenchShell() {
8795
}
8896
return null;
8997
}
98+
99+
public synchronized TypeScriptTextTools getJavaTextTools() {
100+
if (fJavaTextTools == null)
101+
fJavaTextTools = new TypeScriptTextTools(getPreferenceStore(),
102+
JavaScriptCore.getPlugin().getPluginPreferences());
103+
return fJavaTextTools;
104+
}
105+
106+
public static void log(String message, Throwable e) {
107+
log(new Status(IStatus.ERROR, PLUGIN_ID, INTERNAL_ERROR, message, e));
108+
}
109+
110+
public static void log(Throwable e) {
111+
log("", e);
112+
}
113+
114+
public static void log(IStatus status) {
115+
getDefault().getLog().log(status);
116+
}
117+
90118
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
* Copyright (c) 2015-2016 Angelo ZERR.
3+
* All rights reserved. This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License v1.0
5+
* which accompanies this distribution, and is available at
6+
* http://www.eclipse.org/legal/epl-v10.html
7+
*
8+
* Contributors:
9+
* Angelo Zerr <[email protected]> - initial API and implementation
10+
*/
11+
package ts.eclipse.ide.jsdt.internal.ui;
12+
13+
import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer;
14+
import org.eclipse.jface.preference.IPreferenceStore;
15+
16+
import ts.eclipse.ide.jsdt.ui.PreferenceConstants;
17+
18+
/**
19+
* Preferences initializer for JSX.
20+
*
21+
*/
22+
public class JSDTTypeScriptUIPreferenceInitializer extends AbstractPreferenceInitializer {
23+
24+
@Override
25+
public void initializeDefaultPreferences() {
26+
IPreferenceStore store = PreferenceConstants.getPreferenceStore();
27+
PreferenceConstants.initializeDefaultValues(store);
28+
}
29+
30+
}

eclipse/jsdt/ts.eclipse.ide.jsdt.ui/src/ts/eclipse/ide/jsdt/internal/ui/editor/JavaScriptLightWeightEditor.java

+1
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,7 @@ private IPreferenceStore createCombinedPreferenceStore(IEditorInput input) {
264264
protected void addPreferenceStores(List stores, IEditorInput input) {
265265
stores.add(JavaScriptPlugin.getDefault().getPreferenceStore());
266266
stores.add(new PreferencesAdapter(JavaScriptCore.getPlugin().getPluginPreferences()));
267+
stores.add(new PreferencesAdapter(JSDTTypeScriptUIPlugin.getDefault().getPluginPreferences()));
267268
stores.add(EditorsUI.getPreferenceStore());
268269
}
269270

eclipse/jsdt/ts.eclipse.ide.jsdt.ui/src/ts/eclipse/ide/jsdt/internal/ui/editor/TypeScriptAutoIndentStrategy.java

+12-5
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,15 @@
4747
import org.eclipse.wst.jsdt.core.dom.JavaScriptUnit;
4848
import org.eclipse.wst.jsdt.core.dom.Statement;
4949
import org.eclipse.wst.jsdt.core.dom.WhileStatement;
50-
import org.eclipse.wst.jsdt.core.formatter.DefaultCodeFormatterConstants;
5150
import org.eclipse.wst.jsdt.internal.corext.dom.NodeFinder;
52-
import org.eclipse.wst.jsdt.internal.corext.util.CodeFormatterUtil;
5351
import org.eclipse.wst.jsdt.internal.ui.JavaScriptPlugin;
54-
import org.eclipse.wst.jsdt.internal.ui.text.FastJavaPartitionScanner;
5552
import org.eclipse.wst.jsdt.internal.ui.text.JavaHeuristicScanner;
5653
import org.eclipse.wst.jsdt.internal.ui.text.Symbols;
5754
import org.eclipse.wst.jsdt.ui.PreferenceConstants;
5855
import org.eclipse.wst.jsdt.ui.text.IJavaScriptPartitions;
5956

57+
import ts.eclipse.ide.jsdt.internal.ui.text.FastTypeScriptPartitionScanner;
58+
import ts.eclipse.ide.jsdt.internal.ui.text.jsx.IJSXPartitions;
6059
import ts.resources.ITypeScriptFile;
6160

6261

@@ -505,7 +504,14 @@ private static boolean isDefaultPartition(IDocument document, int position, Stri
505504
}
506505

507506
private boolean isClosed(IDocument document, int offset, int length) {
508-
507+
508+
// char[]c = {'{', '}'};
509+
// JavaPairMatcher matcher = new JavaPairMatcher(c);
510+
// IRegion r= matcher.match(document, offset, length);
511+
// if (true) {
512+
// return r != null;
513+
// }
514+
509515
CompilationUnitInfo info= getCompilationUnitForMethod(document, offset);
510516
if (info == null)
511517
return false;
@@ -609,9 +615,10 @@ private static void installJavaStuff(Document document) {
609615
IJavaScriptPartitions.JAVA_STRING,
610616
IJavaScriptPartitions.JAVASCRIPT_TEMPLATE_LITERAL,
611617
IJavaScriptPartitions.JAVA_CHARACTER,
618+
IJSXPartitions.JSX,
612619
IDocument.DEFAULT_CONTENT_TYPE
613620
};
614-
FastPartitioner partitioner= new FastPartitioner(new FastJavaPartitionScanner(), types);
621+
FastPartitioner partitioner= new FastPartitioner(new FastTypeScriptPartitionScanner(), types);
615622
partitioner.connect(document);
616623
document.setDocumentPartitioner(IJavaScriptPartitions.JAVA_PARTITIONING, partitioner);
617624
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/**
2+
* Copyright (c) 2015-2016 Angelo ZERR.
3+
* All rights reserved. This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License v1.0
5+
* which accompanies this distribution, and is available at
6+
* http://www.eclipse.org/legal/epl-v10.html
7+
*
8+
* Contributors:
9+
* Angelo Zerr <[email protected]> - initial API and implementation
10+
*/
11+
package ts.eclipse.ide.jsdt.internal.ui.editor;
12+
13+
import org.eclipse.core.filebuffers.IDocumentSetupParticipant;
14+
import org.eclipse.jface.text.IDocument;
15+
import org.eclipse.wst.jsdt.ui.text.IJavaScriptPartitions;
16+
17+
import ts.eclipse.ide.jsdt.internal.ui.JSDTTypeScriptUIPlugin;
18+
import ts.eclipse.ide.jsdt.internal.ui.text.TypeScriptTextTools;
19+
20+
/**
21+
* The document setup participant for TypeScript.
22+
*/
23+
public class TypeScriptDocumentSetupParticipant implements IDocumentSetupParticipant {
24+
25+
public TypeScriptDocumentSetupParticipant() {
26+
}
27+
28+
@Override
29+
public void setup(IDocument document) {
30+
TypeScriptTextTools tools = JSDTTypeScriptUIPlugin.getDefault().getJavaTextTools();
31+
tools.setupJavaDocumentPartitioner(document, IJavaScriptPartitions.JAVA_PARTITIONING);
32+
}
33+
}

eclipse/jsdt/ts.eclipse.ide.jsdt.ui/src/ts/eclipse/ide/jsdt/internal/ui/editor/TypeScriptEditor.java

-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@
7373
import org.eclipse.wst.jsdt.internal.ui.text.PreferencesAdapter;
7474
import org.eclipse.wst.jsdt.ui.IContextMenuConstants;
7575
import org.eclipse.wst.jsdt.ui.PreferenceConstants;
76-
import org.eclipse.wst.jsdt.ui.actions.IJavaEditorActionDefinitionIds;
7776

7877
import ts.TypeScriptException;
7978
import ts.client.ICancellationToken;

0 commit comments

Comments
 (0)