Skip to content

Commit b664e33

Browse files
author
angelozerr
committed
Show "TypeScript" project properties if there is one or several
"tsconfig.json" defines in the TypeScript build path. See #12
1 parent f669ff2 commit b664e33

23 files changed

+364
-122
lines changed

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

+20
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,17 @@
4545
import org.eclipse.ui.IPartService;
4646
import org.eclipse.ui.IWorkbenchPart;
4747
import org.eclipse.ui.IWorkbenchWindow;
48+
import org.eclipse.ui.PlatformUI;
4849
import org.eclipse.ui.editors.text.EditorsUI;
4950
import org.eclipse.ui.texteditor.AbstractDecoratedTextEditor;
5051
import org.eclipse.ui.texteditor.AbstractDecoratedTextEditorPreferenceConstants;
5152
import org.eclipse.ui.texteditor.ChainedPreferenceStore;
5253
import org.eclipse.ui.texteditor.SourceViewerDecorationSupport;
5354
import org.eclipse.wst.jsdt.core.JavaScriptCore;
55+
import org.eclipse.wst.jsdt.internal.ui.IJavaHelpContextIds;
5456
import org.eclipse.wst.jsdt.internal.ui.JavaScriptPlugin;
57+
import org.eclipse.wst.jsdt.internal.ui.actions.AddBlockCommentAction;
58+
import org.eclipse.wst.jsdt.internal.ui.actions.RemoveBlockCommentAction;
5559
import org.eclipse.wst.jsdt.internal.ui.text.JavaPairMatcher;
5660
import org.eclipse.wst.jsdt.internal.ui.text.PreferencesAdapter;
5761
import org.eclipse.wst.jsdt.ui.PreferenceConstants;
@@ -271,6 +275,22 @@ protected void createActions() {
271275
Action action = new GotoMatchingBracketAction(this);
272276
action.setActionDefinitionId(IJavaEditorActionDefinitionIds.GOTO_MATCHING_BRACKET);
273277
setAction(GotoMatchingBracketAction.GOTO_MATCHING_BRACKET, action);
278+
279+
/*action= new AddBlockCommentAction(TypeScriptEditorMessages.getResourceBundle(), "AddBlockComment.", this); //$NON-NLS-1$
280+
action.setActionDefinitionId(IJavaEditorActionDefinitionIds.ADD_BLOCK_COMMENT);
281+
setAction("AddBlockComment", action); //$NON-NLS-1$
282+
markAsStateDependentAction("AddBlockComment", true); //$NON-NLS-1$
283+
markAsSelectionDependentAction("AddBlockComment", true); //$NON-NLS-1$
284+
PlatformUI.getWorkbench().getHelpSystem().setHelp(action, IJavaHelpContextIds.ADD_BLOCK_COMMENT_ACTION);
285+
286+
action= new RemoveBlockCommentAction(TypeScriptEditorMessages.getResourceBundle(), "RemoveBlockComment.", this); //$NON-NLS-1$
287+
action.setActionDefinitionId(IJavaEditorActionDefinitionIds.REMOVE_BLOCK_COMMENT);
288+
setAction("RemoveBlockComment", action); //$NON-NLS-1$
289+
markAsStateDependentAction("RemoveBlockComment", true); //$NON-NLS-1$
290+
markAsSelectionDependentAction("RemoveBlockComment", true); //$NON-NLS-1$
291+
PlatformUI.getWorkbench().getHelpSystem().setHelp(action, IJavaHelpContextIds.REMOVE_BLOCK_COMMENT_ACTION);
292+
*/
293+
274294
}
275295

276296
@Override

eclipse/ts.eclipse.ide.core/src/ts/eclipse/ide/core/builder/TypeScriptBuilder.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public class TypeScriptBuilder extends IncrementalProjectBuilder {
3838
protected IProject[] build(int kind, Map<String, String> args, final IProgressMonitor monitor)
3939
throws CoreException {
4040
IProject project = this.getProject();
41-
if (!TypeScriptResourceUtil.hasTypeScriptNature(project)) {
41+
if (!TypeScriptResourceUtil.isTypeScriptProject(project)) {
4242
return null;
4343
}
4444

@@ -103,7 +103,7 @@ public boolean visit(IResourceDelta delta) throws CoreException {
103103
case IResource.ROOT:
104104
return true;
105105
case IResource.PROJECT:
106-
return TypeScriptResourceUtil.hasTypeScriptNature((IProject) resource);
106+
return TypeScriptResourceUtil.isTypeScriptProject((IProject) resource);
107107
case IResource.FOLDER:
108108
return buildPath.isInScope(resource);
109109
case IResource.FILE:

eclipse/ts.eclipse.ide.core/src/ts/eclipse/ide/core/preferences/TypeScriptCorePreferenceConstants.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public class TypeScriptCorePreferenceConstants {
6262
// public static final String DEFAULT_NATURE_SALSA_PATHS = JSCONFIG_JSON +
6363
// ",src/" + JSCONFIG_JSON; //$NON-NLS-1$
6464

65-
public static final String TYPESCRIPT_BUILD_PATH = "typeBuildScriptPath"; //$NON-NLS-1$
65+
public static final String TYPESCRIPT_BUILD_PATH = "typeScriptBuildPath"; //$NON-NLS-1$
6666

6767
public static final String DEFAULT_TYPESCRIPT_BUILD_PATH = new DefaultTypeScriptBuildPath().toString(); // $NON-NLS-1$
6868

eclipse/ts.eclipse.ide.core/src/ts/eclipse/ide/core/resources/AbstractTypeScriptSettings.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ protected IEclipsePreferences getProjectPreferences() {
9393
}
9494

9595
protected IEclipsePreferences getWorkspacePreferences() {
96-
return TypeScriptSettingsHelper.getWorkspacePreferences(pluginId);
96+
return WorkspaceTypeScriptSettingsHelper.getWorkspacePreferences(pluginId);
9797
}
9898

9999
public void dispose() {

eclipse/ts.eclipse.ide.core/src/ts/eclipse/ide/core/resources/TypeScriptSettingsHelper.java renamed to eclipse/ts.eclipse.ide.core/src/ts/eclipse/ide/core/resources/WorkspaceTypeScriptSettingsHelper.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88
import ts.eclipse.ide.core.TypeScriptCorePlugin;
99
import ts.eclipse.ide.core.preferences.TypeScriptCorePreferenceConstants;
1010

11-
public class TypeScriptSettingsHelper {
11+
public class WorkspaceTypeScriptSettingsHelper {
1212

1313
private static UseSalsa useSalsa;
1414

1515
static {
16-
IEclipsePreferences preferences = TypeScriptSettingsHelper
16+
IEclipsePreferences preferences = WorkspaceTypeScriptSettingsHelper
1717
.getWorkspacePreferences(TypeScriptCorePlugin.PLUGIN_ID);
1818
String name = preferences.get(TypeScriptCorePreferenceConstants.USE_SALSA_AS_JS_INFERENCE,
1919
UseSalsa.WhenNoJSDTNature.name());
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,47 @@
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+
*/
111
package ts.eclipse.ide.core.resources.buildpath;
212

313
import java.util.List;
414

515
import org.eclipse.core.resources.IContainer;
616
import org.eclipse.core.resources.IResource;
717

18+
/**
19+
* TypeScript build path API.
20+
*
21+
*/
822
public interface ITypeScriptBuildPath {
923

24+
/**
25+
* Returns list of folders root of the project which hosts "tsconfig.json".
26+
*
27+
* @return list of folders root of the project which hosts "tsconfig.json".
28+
*/
1029
List<IContainer> getContainers();
1130

12-
List<ITypeScriptBuildPathEntry> getEntries();
13-
31+
/**
32+
* Returns true if the given resource is in the scope of the build path and
33+
* false otherwise.
34+
*
35+
* @param resource
36+
* @return true if the given resource is in the scope of the build path and
37+
* false otherwise.
38+
*/
1439
boolean isInScope(IResource resource);
1540

1641
IContainer getContainer(IResource resource);
42+
43+
void addEntry(ITypeScriptBuildPathEntry entry);
44+
45+
void removeEntry(ITypeScriptBuildPathEntry entry);
46+
1747
}

eclipse/ts.eclipse.ide.core/src/ts/eclipse/ide/core/resources/buildpath/ITypeScriptBuildPathEntry.java

-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,4 @@ public interface ITypeScriptBuildPathEntry {
1010

1111
IPath getPath();
1212

13-
IPath[] getInclusionPatterns();
14-
15-
IPath[] getExclusionPatterns();
1613
}

eclipse/ts.eclipse.ide.core/src/ts/eclipse/ide/core/utils/TypeScriptResourceUtil.java

+16-9
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
import ts.eclipse.ide.core.TypeScriptCorePlugin;
2929
import ts.eclipse.ide.core.builder.TypeScriptBuilder;
30+
import ts.eclipse.ide.core.preferences.TypeScriptCorePreferenceConstants;
3031
import ts.eclipse.ide.core.resources.IIDETypeScriptProject;
3132
import ts.eclipse.ide.core.resources.jsconfig.IDETsconfigJson;
3233
import ts.eclipse.ide.internal.core.resources.IDEResourcesManager;
@@ -44,7 +45,7 @@ public class TypeScriptResourceUtil {
4445
public static boolean isTsOrTsxFile(Object element) {
4546
return IDEResourcesManager.getInstance().isTsOrTsxFile(element);
4647
}
47-
48+
4849
public static boolean isTsOrTsxOrJsxFile(Object element) {
4950
return IDEResourcesManager.getInstance().isTsOrTsxOrJsxFile(element);
5051
}
@@ -54,16 +55,22 @@ public static boolean isJsOrJsMapFile(Object element) {
5455
}
5556

5657
/**
57-
* Return true if the given project contains a "tsconfig.json" file false
58-
* otherwise.
58+
* Returns true if the given project contains one or several "tsconfig.json"
59+
* file(s) false otherwise.
60+
*
61+
* To have a very good performance, "tsconfig.json" is not searched by
62+
* scanning the whole files of the project but it checks if "tsconfig.json"
63+
* exists in several folders ('/tsconfig.json' or '/src/tsconfig.json).
64+
* Those folders can be customized with preferences buildpath
65+
* {@link TypeScriptCorePreferenceConstants#TYPESCRIPT_BUILD_PATH}.
5966
*
6067
* @param project
6168
* Eclipse project.
62-
* @return true if the given project contains a "tsconfig.json" file and
63-
* false otherwise.
69+
* @return true if the given project contains one or several "tsconfig.json"
70+
* file(s) false otherwise.
6471
*/
65-
public static boolean hasTypeScriptNature(IProject project) {
66-
return IDEResourcesManager.getInstance().hasTypeScriptNature(project);
72+
public static boolean isTypeScriptProject(IProject project) {
73+
return IDEResourcesManager.getInstance().isTypeScriptProject(project);
6774
}
6875

6976
public static boolean canConsumeTsserver(IProject project, Object fileObject) {
@@ -197,8 +204,8 @@ public static void refreshAndCollectEmittedFiles(IFile tsFile, IDETsconfigJson t
197204
}
198205
}
199206

200-
private static void refreshAndCollect(IPath filePath, IContainer baseDir, boolean refresh,
201-
List<IFile> emittedFiles) throws CoreException {
207+
private static void refreshAndCollect(IPath filePath, IContainer baseDir, boolean refresh, List<IFile> emittedFiles)
208+
throws CoreException {
202209
IFile file = null;
203210
if (refresh) {
204211
file = baseDir.getFile(filePath);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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.internal.core;
12+
13+
import java.util.MissingResourceException;
14+
import java.util.ResourceBundle;
15+
16+
import org.eclipse.osgi.util.NLS;
17+
18+
/**
19+
* TypeScript Core messages.
20+
*
21+
*/
22+
public class TypeScriptCoreMessages extends NLS {
23+
24+
private static final String BUNDLE_NAME = "ts.eclipse.ide.internal.core.TypeScriptCoreMessages"; //$NON-NLS-1$
25+
26+
private static ResourceBundle fResourceBundle;
27+
28+
// Job
29+
public static String SaveProjectPreferencesJob_name;
30+
public static String SaveProjectPreferencesJob_taskName;
31+
32+
public static ResourceBundle getResourceBundle() {
33+
try {
34+
if (fResourceBundle == null)
35+
fResourceBundle = ResourceBundle.getBundle(BUNDLE_NAME);
36+
} catch (MissingResourceException x) {
37+
fResourceBundle = null;
38+
}
39+
return fResourceBundle;
40+
}
41+
42+
static {
43+
NLS.initializeMessages(BUNDLE_NAME, TypeScriptCoreMessages.class);
44+
}
45+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
###############################################################################
2+
# Copyright (c) 2015-2016 Angelo Zerr and others.
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+
12+
SaveProjectPreferencesJob_name=Save project preferences job
13+
SaveProjectPreferencesJob_taskName=Saving preferences of project {0}

eclipse/ts.eclipse.ide.core/src/ts/eclipse/ide/internal/core/TypeScriptNatureTester.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ public TypeScriptNatureTester() {
2323
*/
2424
@Override
2525
public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
26-
2726
if (IS_TYPESCRIPT_PROJECT_PROPERTY.equals(property)) {
2827
return testIsTypeScriptProject(receiver);
2928
} else if (HAS_TYPESCRIPT_BUILDER_PROPERTY.equals(property)) {
@@ -36,7 +35,7 @@ private boolean testIsTypeScriptProject(Object receiver) {
3635
if (receiver instanceof IAdaptable) {
3736
IProject project = (IProject) ((IAdaptable) receiver).getAdapter(IProject.class);
3837
if (project != null) {
39-
return TypeScriptResourceUtil.hasTypeScriptNature(project);
38+
return TypeScriptResourceUtil.isTypeScriptProject(project);
4039
}
4140
}
4241
return false;

eclipse/ts.eclipse.ide.core/src/ts/eclipse/ide/internal/core/preferences/TypeScriptCorePreferenceInitializer.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import ts.eclipse.ide.core.nodejs.IEmbeddedNodejs;
2323
import ts.eclipse.ide.core.nodejs.INodejsInstallManager;
2424
import ts.eclipse.ide.core.preferences.TypeScriptCorePreferenceConstants;
25-
import ts.eclipse.ide.core.resources.TypeScriptSettingsHelper;
25+
import ts.eclipse.ide.core.resources.WorkspaceTypeScriptSettingsHelper;
2626
import ts.eclipse.ide.core.resources.UseSalsa;
2727
import ts.eclipse.ide.internal.core.Trace;
2828
import ts.repository.ITypeScriptRepository;
@@ -35,7 +35,7 @@ public class TypeScriptCorePreferenceInitializer extends AbstractPreferenceIniti
3535

3636
@Override
3737
public void initializeDefaultPreferences() {
38-
IEclipsePreferences node = TypeScriptSettingsHelper.getWorkspacePreferences(TypeScriptCorePlugin.PLUGIN_ID);
38+
IEclipsePreferences node = WorkspaceTypeScriptSettingsHelper.getWorkspacePreferences(TypeScriptCorePlugin.PLUGIN_ID);
3939

4040
// initialize properties for direct access of node.js server (start an
4141
// internal process)
@@ -60,7 +60,7 @@ public void initializeDefaultPreferences() {
6060

6161
// Initialize default path where TypeScript files *.ts, *.tsx must be
6262
// searched for compilation and validation must be done
63-
initializeTypeScriptPaths(node);
63+
initializeTypeScriptBuildPath(node);
6464

6565
// node.put(TypeScriptCorePreferenceConstants.NATURE_TYPESCRIPT_PATHS,
6666
// TypeScriptCorePreferenceConstants.DEFAULT_NATURE_TYPESCRIPT_PATHS);
@@ -113,7 +113,7 @@ private void initializeSalsa(IEclipsePreferences node) {
113113
node.put(TypeScriptCorePreferenceConstants.USE_SALSA_AS_JS_INFERENCE, UseSalsa.WhenNoJSDTNature.name());
114114
}
115115

116-
private void initializeTypeScriptPaths(IEclipsePreferences node) {
116+
private void initializeTypeScriptBuildPath(IEclipsePreferences node) {
117117
node.put(TypeScriptCorePreferenceConstants.TYPESCRIPT_BUILD_PATH,
118118
TypeScriptCorePreferenceConstants.DEFAULT_TYPESCRIPT_BUILD_PATH);
119119

eclipse/ts.eclipse.ide.core/src/ts/eclipse/ide/internal/core/resources/IDEResourcesManager.java

+28-15
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@
1717
import org.eclipse.core.resources.IProject;
1818
import org.eclipse.core.runtime.CoreException;
1919

20-
import ts.eclipse.ide.core.resources.TypeScriptSettingsHelper;
20+
import ts.eclipse.ide.core.preferences.TypeScriptCorePreferenceConstants;
2121
import ts.eclipse.ide.core.resources.UseSalsa;
22+
import ts.eclipse.ide.core.resources.WorkspaceTypeScriptSettingsHelper;
2223
import ts.eclipse.ide.internal.core.Trace;
23-
import ts.resources.ITypeScriptProject;
2424
import ts.resources.ITypeScriptResourcesManagerDelegate;
2525
import ts.utils.FileUtils;
2626

@@ -33,7 +33,7 @@ public static IDEResourcesManager getInstance() {
3333
}
3434

3535
@Override
36-
public ITypeScriptProject getTypeScriptProject(Object obj, boolean force) throws IOException {
36+
public IDETypeScriptProject getTypeScriptProject(Object obj, boolean force) throws IOException {
3737
if (obj instanceof IProject) {
3838
IProject project = (IProject) obj;
3939
try {
@@ -72,21 +72,34 @@ private synchronized IDETypeScriptProject create(IProject project) throws CoreEx
7272
return tsProject;
7373
}
7474

75-
public boolean hasTypeScriptNature(IProject project) {
76-
// see https://github.com/angelozerr/typescript.java/issues/12
77-
// FIXME: All projects can be a TypeScript project. It means that
78-
// project
79-
// properties display every time "TypeScript" menu item. But is it a
80-
// problem?
81-
// To hide the TypeScript menu item we could check that project contains
82-
// tsconfig.json or src/tsconfig.json
83-
// User could add a new path for tsconfig.json in the preferences but
84-
// I'm afrais that it's a little complex.
85-
return true;
75+
/**
76+
* Returns true if the given project contains one or several "tsconfig.json"
77+
* file(s) false otherwise.
78+
*
79+
* To have a very good performance, "tsconfig.json" is not searched by
80+
* scanning the whole files of the project but it checks if "tsconfig.json"
81+
* exists in several folders ('/tsconfig.json' or '/src/tsconfig.json).
82+
* Those folders can be customized with preferences buildpath
83+
* {@link TypeScriptCorePreferenceConstants#TYPESCRIPT_BUILD_PATH}.
84+
*
85+
* @param project
86+
* Eclipse project.
87+
* @return true if the given project contains one or several "tsconfig.json"
88+
* file(s) false otherwise.
89+
*/
90+
public boolean isTypeScriptProject(IProject project) {
91+
// check that TypeScript project have build path.
92+
try {
93+
IDETypeScriptProject tsProject = getTypeScriptProject(project, false);
94+
return tsProject != null && tsProject.getTypeScriptBuildPath().getContainers().size() > 0;
95+
} catch (Exception e) {
96+
Trace.trace(Trace.SEVERE, "Error while getting TypeScript project", e);
97+
}
98+
return false;
8699
}
87100

88101
public boolean hasSalsaNature(IProject project) {
89-
UseSalsa useSalsa = TypeScriptSettingsHelper.getUseSalsa();
102+
UseSalsa useSalsa = WorkspaceTypeScriptSettingsHelper.getUseSalsa();
90103
switch (useSalsa) {
91104
case Never:
92105
return false;

0 commit comments

Comments
 (0)