Skip to content

Commit 281fdd8

Browse files
author
angelozerr
committed
Show a.js, a.js.map inside a.ts in the Project Explorer. See
#47
1 parent 8b527b5 commit 281fdd8

File tree

38 files changed

+755
-260
lines changed

38 files changed

+755
-260
lines changed

core/ts.core/src/ts/internal/resources/DefaultTypeScriptResourcesManager.java

+25-6
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,15 @@ public boolean isJsFile(Object fileObject) {
4545
}
4646

4747
@Override
48-
public boolean isTsFile(Object fileObject) {
48+
public boolean isJsxFile(Object fileObject) {
4949
String ext = getExtension(fileObject);
50-
return ext != null && FileUtils.TS_EXTENSION.equals(ext.toLowerCase());
50+
return ext != null && FileUtils.JSX_EXTENSION.equals(ext.toLowerCase());
5151
}
5252

5353
@Override
54-
public boolean isJsxFile(Object fileObject) {
54+
public boolean isTsFile(Object fileObject) {
5555
String ext = getExtension(fileObject);
56-
return ext != null && FileUtils.JSX_EXTENSION.equals(ext.toLowerCase());
56+
return ext != null && FileUtils.TS_EXTENSION.equals(ext.toLowerCase());
5757
}
5858

5959
@Override
@@ -63,9 +63,18 @@ public boolean isTsxFile(Object fileObject) {
6363
}
6464

6565
@Override
66-
public boolean isSourceMapFile(Object fileObject) {
66+
public boolean isTsOrTsxFile(Object fileObject) {
6767
String ext = getExtension(fileObject);
68-
return ext != null && FileUtils.SOURCE_MAP_EXTENSION.equals(ext.toLowerCase());
68+
ext = ext != null ? ext.toLowerCase() : null;
69+
return ext != null && (FileUtils.TS_EXTENSION.equals(ext) || FileUtils.TSX_EXTENSION.equals(ext));
70+
}
71+
72+
@Override
73+
public boolean isTsOrTsxOrJsxFile(Object fileObject) {
74+
String ext = getExtension(fileObject);
75+
ext = ext != null ? ext.toLowerCase() : null;
76+
return ext != null && (FileUtils.TS_EXTENSION.equals(ext) || FileUtils.TSX_EXTENSION.equals(ext)
77+
|| FileUtils.JSX_EXTENSION.equals(ext));
6978
}
7079

7180
protected String getExtension(Object fileObject) {
@@ -77,4 +86,14 @@ protected String getExtension(Object fileObject) {
7786
return null;
7887
}
7988

89+
@Override
90+
public String getTypeScriptFilename(Object fileObject) {
91+
if (fileObject instanceof File) {
92+
return FileUtils.getTypeScriptFilename(((File) fileObject).getName());
93+
} else if (fileObject instanceof String) {
94+
return FileUtils.getTypeScriptFilename((String) fileObject);
95+
}
96+
return null;
97+
}
98+
8099
}

core/ts.core/src/ts/resources/ConfigurableTypeScriptResourcesManager.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public boolean isTSFile(Object fileObject) {
2727
return typeScriptResourcesManagerDelegate.isTsFile(fileObject);
2828
}
2929

30-
public boolean isJavaScriptFile(Object fileObject) {
30+
public boolean isJsFile(Object fileObject) {
3131
return typeScriptResourcesManagerDelegate.isJsFile(fileObject);
3232
}
3333
}

core/ts.core/src/ts/resources/ITypeScriptResourcesManagerDelegate.java

+34-13
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,6 @@ public interface ITypeScriptResourcesManagerDelegate {
4242
*/
4343
boolean isJsFile(Object fileObject);
4444

45-
/**
46-
* Returns true if the given file object is a TypeScript file and false
47-
* otherwise.
48-
*
49-
* @param fileObject
50-
* @return true if the given file object is a TypeScript file and false
51-
* otherwise.
52-
*/
53-
boolean isTsFile(Object fileObject);
54-
5545
/**
5646
* Returns true if the given file object is a JXS file and false otherwise.
5747
*
@@ -71,13 +61,44 @@ public interface ITypeScriptResourcesManagerDelegate {
7161
boolean isTsxFile(Object fileObject);
7262

7363
/**
74-
* Returns true if the given file object is a source map file and false
64+
* Returns true if the given file object is a TypeScript file and false
7565
* otherwise.
7666
*
7767
* @param fileObject
78-
* @return true if the given file object is a source map file and false
68+
* @return true if the given file object is a TypeScript file and false
7969
* otherwise.
8070
*/
81-
boolean isSourceMapFile(Object fileObject);
71+
boolean isTsFile(Object fileObject);
72+
73+
/**
74+
* Returns true if the given file object is a TypeScript or TypeScript/JSX
75+
* file and false otherwise.
76+
*
77+
* @param fileObject
78+
* @return true if the given file object is a TypeScript or TypeScript/JSX
79+
* file and false otherwise.
80+
*/
81+
boolean isTsOrTsxFile(Object fileObject);
82+
83+
/**
84+
* Returns true if the given file object is a TypeScript or TypeScript/JSX
85+
* or JSX file and false otherwise.
86+
*
87+
* @param fileObject
88+
* @return true if the given file object is a TypeScript or TypeScript/JSX
89+
* or JSX file and false otherwise.
90+
*/
91+
boolean isTsOrTsxOrJsxFile(Object fileObject);
92+
93+
/**
94+
* Returns the corresponding TypeScript file from the js or js.map file and
95+
* null otherwise.
96+
*
97+
* @param file
98+
* *.js or *.js.map file
99+
* @return the corresponding TypeScript file from the js or js.map file and
100+
* null otherwise.
101+
*/
102+
String getTypeScriptFilename(Object file);
82103

83104
}

core/ts.core/src/ts/resources/TypeScriptResourcesManager.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public static boolean isTSFile(Object fileObject) {
6767
return INSTANCE.isTSFile(fileObject);
6868
}
6969

70-
public static boolean isJavaScriptFile(Object fileObject) {
71-
return INSTANCE.isTSFile(fileObject);
70+
public static boolean isJSFile(Object fileObject) {
71+
return INSTANCE.isJsFile(fileObject);
7272
}
7373
}

core/ts.core/src/ts/resources/jsonconfig/CompilerOptions.java

+10
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,18 @@
22

33
public class CompilerOptions {
44

5+
private String outDir;
6+
57
private boolean alloyJs;
68

9+
public String getOutDir() {
10+
return outDir;
11+
}
12+
13+
public void setOutDir(String outDir) {
14+
this.outDir = outDir;
15+
}
16+
717
public boolean isAlloyJs() {
818
return alloyJs;
919
}

core/ts.core/src/ts/utils/FileUtils.java

+28-4
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public class FileUtils {
2525
public static final String TS_EXTENSION = "ts";
2626
public static final String JSX_EXTENSION = "jsx";
2727
public static final String TSX_EXTENSION = "tsx";
28-
public static final String SOURCE_MAP_EXTENSION = "sourcemap";
28+
public static final String MAP_EXTENSION = "map";
2929

3030
/**
3131
* Configuration file
@@ -42,11 +42,35 @@ public static String getFileExtension(String fileName) {
4242
return fileName.substring(index + 1);
4343
}
4444

45-
public static String getFileNameWithoutExtension(String fileName) {
45+
public static String getTypeScriptFilename(String fileName) {
4646
int index = fileName.lastIndexOf('.');
47-
if (index == -1)
47+
if (index == -1 || index == fileName.length() - 1) {
4848
return null;
49-
return fileName.substring(0, index);
49+
}
50+
String ext = fileName.substring(index + 1);
51+
if (FileUtils.JS_EXTENSION.equals(ext)) {
52+
StringBuilder tsFileName = new StringBuilder(fileName.substring(0, index));
53+
tsFileName.append('.');
54+
tsFileName.append(FileUtils.TS_EXTENSION);
55+
return tsFileName.toString();
56+
} else if (FileUtils.MAP_EXTENSION.equals(ext)) {
57+
return getTypeScriptFilename(fileName.substring(0, index));
58+
}
59+
return null;
60+
}
61+
62+
public static boolean isJsOrJsMapFile(String fileName) {
63+
int index = fileName.lastIndexOf('.');
64+
if (index == -1 || index == fileName.length() - 1) {
65+
return false;
66+
}
67+
String ext = fileName.substring(index + 1);
68+
if (FileUtils.JS_EXTENSION.equals(ext)) {
69+
return true;
70+
} else if (FileUtils.MAP_EXTENSION.equals(ext)) {
71+
return isJsOrJsMapFile(fileName.substring(0, index));
72+
}
73+
return false;
5074
}
5175

5276
/**

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

-33
Original file line numberDiff line numberDiff line change
@@ -13,39 +13,6 @@
1313
###############################################################################
1414
-->
1515
<plugin>
16-
17-
<extension point="org.eclipse.core.runtime.contentTypes">
18-
<content-type
19-
id="tsSource"
20-
name="%tsSourceName"
21-
base-type="org.eclipse.core.runtime.text"
22-
priority="high"
23-
default-charset="UTF-8"
24-
file-extensions="ts">
25-
</content-type>
26-
</extension>
27-
28-
<extension point="org.eclipse.core.runtime.contentTypes">
29-
<content-type
30-
id="jsxSource"
31-
name="%jsxSourceName"
32-
base-type="org.eclipse.core.runtime.text"
33-
priority="high"
34-
default-charset="UTF-8"
35-
file-extensions="jsx">
36-
</content-type>
37-
</extension>
38-
39-
<extension point="org.eclipse.core.runtime.contentTypes">
40-
<content-type
41-
id="tsxSource"
42-
name="%tsxSourceName"
43-
base-type="org.eclipse.core.runtime.text"
44-
priority="high"
45-
default-charset="UTF-8"
46-
file-extensions="tsx">
47-
</content-type>
48-
</extension>
4916

5017
<!--<extension
5118
point="org.eclipse.core.runtime.adapters">

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
name="%javaDocumentSetupParticipant"
2222
point="org.eclipse.core.filebuffers.documentSetup">
2323
<participant
24-
contentTypeId="ts.eclipse.ide.jsdt.core.tsSource"
24+
contentTypeId="ts.eclipse.ide.core.tsSource"
2525
extensions="ts,tsx,jsx"
2626
class="org.eclipse.wst.jsdt.internal.ui.javaeditor.JavaDocumentSetupParticipant">
2727
</participant>
@@ -38,9 +38,9 @@
3838
symbolicFontName="org.eclipse.wst.jsdt.ui.editors.textfont"
3939
id="ts.eclipse.ide.jsdt.ui.editor.TypeScriptEditor"
4040
extensions="ts,tsx,jsx">
41-
<contentTypeBinding contentTypeId="ts.eclipse.ide.jsdt.core.tsSource" />
42-
<contentTypeBinding contentTypeId="ts.eclipse.ide.jsdt.core.tsxSource" />
43-
<contentTypeBinding contentTypeId="ts.eclipse.ide.jsdt.core.jsxSource" />
41+
<contentTypeBinding contentTypeId="ts.eclipse.ide.core.tsSource" />
42+
<contentTypeBinding contentTypeId="ts.eclipse.ide.core.tsxSource" />
43+
<contentTypeBinding contentTypeId="ts.eclipse.ide.core.jsxSource" />
4444
</editor>
4545
</extension>
4646

eclipse/jsdt/ts.eclipse.ide.jsdt.ui/src/ts/eclipse/ide/jsdt/internal/ui/editor/contentassist/TypeScriptCompletionProposalComputer.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
import org.eclipse.wst.jsdt.ui.text.java.IJavaCompletionProposalComputer;
2424
import org.eclipse.wst.jsdt.ui.text.java.JavaContentAssistInvocationContext;
2525

26-
import ts.eclipse.ide.core.TypeScriptCorePlugin;
2726
import ts.eclipse.ide.core.resources.IIDETypeScriptProject;
27+
import ts.eclipse.ide.core.utils.TypeScriptResourceUtil;
2828
import ts.eclipse.ide.jsdt.internal.ui.Trace;
2929
import ts.eclipse.jface.text.contentassist.CompletionProposalCollector;
3030
import ts.resources.ITypeScriptFile;
@@ -49,9 +49,9 @@ public List computeCompletionProposals(ContentAssistInvocationContext context, I
4949
}
5050
if (resource != null) {
5151
try {
52-
if (TypeScriptCorePlugin.canConsumeTsserver(resource)) {
52+
if (TypeScriptResourceUtil.canConsumeTsserver(resource)) {
5353
IProject project = resource.getProject();
54-
IIDETypeScriptProject tsProject = TypeScriptCorePlugin.getTypeScriptProject(project);
54+
IIDETypeScriptProject tsProject = TypeScriptResourceUtil.getTypeScriptProject(project);
5555
if (tsProject != null) {
5656

5757
int position = context.getInvocationOffset();

eclipse/jsdt/ts.eclipse.ide.jsdt.ui/src/ts/eclipse/ide/jsdt/internal/ui/editor/format/TypeScriptContentFormatter.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414

1515
import ts.TypeScriptException;
1616
import ts.client.format.ITypeScriptFormatCollector;
17-
import ts.eclipse.ide.core.TypeScriptCorePlugin;
1817
import ts.eclipse.ide.core.resources.IIDETypeScriptFile;
1918
import ts.eclipse.ide.core.resources.IIDETypeScriptProject;
19+
import ts.eclipse.ide.core.utils.TypeScriptResourceUtil;
2020

2121
/**
2222
* Content formatter which consumes tsserver "format" command to format an
@@ -37,8 +37,7 @@ public TypeScriptContentFormatter(IResource resource) {
3737
@Override
3838
public void format(IDocument document, IRegion region) {
3939
try {
40-
IIDETypeScriptProject tsProject = TypeScriptCorePlugin.getDefault()
41-
.getTypeScriptProject(resource.getProject());
40+
IIDETypeScriptProject tsProject = TypeScriptResourceUtil.getTypeScriptProject(resource.getProject());
4241
final IIDETypeScriptFile tsFile = tsProject.openFile(resource, document);
4342

4443
final MultiTextEdit textEdit = new MultiTextEdit();

eclipse/jsdt/ts.eclipse.ide.jsdt.ui/src/ts/eclipse/ide/jsdt/internal/ui/validation/JSDTEditorTracker.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
import org.eclipse.ui.PlatformUI;
2929
import org.eclipse.ui.texteditor.ITextEditor;
3030

31-
import ts.eclipse.ide.core.TypeScriptCorePlugin;
31+
import ts.eclipse.ide.core.utils.TypeScriptResourceUtil;
3232
import ts.eclipse.ide.jsdt.internal.ui.JSDTTypeScriptUIPlugin;
3333
import ts.eclipse.ide.ui.utils.EditorUtils;
3434

@@ -149,7 +149,7 @@ public void partOpened(IWorkbenchPart part) {
149149
private void editorOpened(IEditorPart part) {
150150
if (part instanceof ITextEditor) {
151151
IResource resource = EditorUtils.getResource(part);
152-
if (resource != null && TypeScriptCorePlugin.canConsumeTsserver(resource)) {
152+
if (resource != null && TypeScriptResourceUtil.canConsumeTsserver(resource)) {
153153
ISourceViewer viewer = EditorUtils.getSourceViewer(part);
154154
if (viewer != null) {
155155
TypeScriptDocumentRegionProcessor processor = fAsYouTypeValidators.get(part);

eclipse/ts.eclipse.ide.core/META-INF/MANIFEST.MF

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ Export-Package: ts.eclipse.ide.core,
2121
ts.eclipse.ide.core.preferences,
2222
ts.eclipse.ide.core.repository,
2323
ts.eclipse.ide.core.resources,
24+
ts.eclipse.ide.core.resources.jsconfig,
2425
ts.eclipse.ide.core.utils
2526
Bundle-ActivationPolicy: lazy
2627
Bundle-Activator: ts.eclipse.ide.core.TypeScriptCorePlugin

eclipse/ts.eclipse.ide.core/plugin.xml

+34-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,40 @@
2020
<extension-point id="nodeJSInstalls"
2121
name="%nodeJSInstallsContribution.name"
2222
schema="schema/nodeJSInstalls.exsd" />
23-
23+
24+
<extension point="org.eclipse.core.runtime.contentTypes">
25+
<content-type
26+
id="tsSource"
27+
name="%tsSourceName"
28+
base-type="org.eclipse.core.runtime.text"
29+
priority="high"
30+
default-charset="UTF-8"
31+
file-extensions="ts">
32+
</content-type>
33+
</extension>
34+
35+
<extension point="org.eclipse.core.runtime.contentTypes">
36+
<content-type
37+
id="jsxSource"
38+
name="%jsxSourceName"
39+
base-type="org.eclipse.core.runtime.text"
40+
priority="high"
41+
default-charset="UTF-8"
42+
file-extensions="jsx">
43+
</content-type>
44+
</extension>
45+
46+
<extension point="org.eclipse.core.runtime.contentTypes">
47+
<content-type
48+
id="tsxSource"
49+
name="%tsxSourceName"
50+
base-type="org.eclipse.core.runtime.text"
51+
priority="high"
52+
default-charset="UTF-8"
53+
file-extensions="tsx">
54+
</content-type>
55+
</extension>
56+
2457
<extension point="org.eclipse.core.expressions.propertyTesters">
2558
<propertyTester
2659
id="ts.eclipse.ide.core.TypeScriptNatureTester"

0 commit comments

Comments
 (0)