Skip to content

Commit 3da9d82

Browse files
committed
Improve the creation of Mathematica Modules and Projects
1 parent ef97083 commit 3da9d82

21 files changed

Lines changed: 310 additions & 221 deletions

build.gradle

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ if (project.file('gradle.properties').exists()) {
4242
apply from: "gradle.properties"
4343
}
4444

45-
// turn this on for profiling the running sandbox
46-
//task runIde {
47-
// jvmArgs = ["-agentpath:/home/patrick/build/share/yjp-2017.02/bin/linux-x86-64/libyjpagent.so=delay=2000"]
48-
//}
45+
// run this task for profiling the running sandbox
46+
task runIdeProfiler(type: org.jetbrains.intellij.tasks.RunIdeTask) {
47+
jvmArgs = ["-agentpath:/home/patrick/build/share/yjp-2017.02/bin/linux-x86-64/libyjpagent.so=delay=2000"]
48+
}
4949

5050
sourceSets {
5151
//noinspection GroovyAssignabilityCheck
@@ -78,7 +78,7 @@ task wrapper(type: Wrapper) {
7878
version '3.0pre5'
7979

8080
intellij {
81-
// version = '2017.2.5'
81+
version = '2017.3'
8282
downloadSources = true
8383
pluginName = 'Mathematica-IntelliJ-Plugin'
8484
updateSinceUntilBuild = false

resources/META-INF/plugin.xml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,13 @@
3636
<lang.ast.factory language="Mathematica" implementationClass="de.halirutan.mathematica.lang.tree.MathematicaASTFactory"/>
3737
<lang.parserDefinition language="Mathematica" implementationClass="de.halirutan.mathematica.lang.parsing.prattparser.MathematicaParserDefinition"/>
3838

39+
3940
<sdkType id="Mathematica Sdk" implementation="de.halirutan.mathematica.sdk.MathematicaSdkType"/>
4041
<moduleType id="MATHEMATICA_MODULE" implementationClass="de.halirutan.mathematica.module.MathematicaModuleType"/>
42+
<!--<moduleBuilder builderClass="de.halirutan.mathematica.module.MathematicaEmptyModule"/>-->
43+
<!--<moduleBuilder builderClass="de.halirutan.mathematica.module.MathematicaBasicModule"/>-->
44+
<!--<moduleBuilder builderClass="de.halirutan.mathematica.module.MathematicaApplicationModule"/>-->
4145
<moduleConfigurationEditorProvider implementation="de.halirutan.mathematica.module.MathematicaModuleConfigurationEditor"/>
42-
4346
<projectTemplatesFactory implementation="de.halirutan.mathematica.module.MathematicaProjectTemplatesFactory"/>
4447

4548
<lang.syntaxHighlighterFactory language="Mathematica" implementationClass="de.halirutan.mathematica.codeinsight.highlighting.MathematicaSyntaxHighlighterFactory"/>
@@ -102,6 +105,7 @@
102105
<applicationService serviceInterface="de.halirutan.mathematica.settings.MathematicaSettings" serviceImplementation="de.halirutan.mathematica.settings.MathematicaSettings"/>
103106
<applicationConfigurable groupId="language" displayName="Mathematica" id="preferences.Mathematica" instance="de.halirutan.mathematica.settings.MathematicaSettingsConfigurable"/>
104107

108+
105109
<spellchecker.support language="Mathematica" implementationClass="de.halirutan.mathematica.codeinsight.spellcheck.MathematicaSpellCheck"/>
106110
<spellchecker.bundledDictionaryProvider implementation="de.halirutan.mathematica.codeinsight.spellcheck.MathematicaDictionaryProvider"/>
107111

resources/de/halirutan/mathematica/MathematicaBundle.properties

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,15 @@ language.level.10.1=Mathematica Version 10.1
3434
language.level.10=Mathematica Version 10.0
3535
language.level.9=Mathematica Version 9
3636
language.level.8=Mathematica Version 8
37-
module.type.description=Creates an empty project or module for custom layouts.
38-
module.type.name=Empty Module
39-
project.template.mathematica=Mathematica
40-
project.template.basic=Basic Package
41-
project.template.basic.description=A basic Mathematica package provides a simple package file and a notebook. Use this for simple or moderately sized Mathematica packages.
42-
project.template.application=Mathematica Application
43-
project.template.application.description=A Mathematica application is used for large packages and more complicated applications.
37+
module.type.description=Creates a Module for working with Mathematica.
38+
module.type.name=Mathematica Module
39+
project.template.group.name=Mathematica
40+
project.template.basic=Basic Package Module
41+
project.template.basic.description=A basic Mathematica package provides a simple package file and a notebook. Use this for simple one-file packages that don't have a complex structure and don't require a PacletInfo file.
42+
project.template.application=Mathematica Application Module
43+
project.template.application.description=A Mathematica application is used for large packages and more complicated applications. This module will set up a directory for your package that contains a PacletInfo.m file and a Kernel/init.m initialization file.
4444
project.template.empty=Empty Mathematica Module
45-
project.template.empty.description=An empty module where you can set the file structure yourself
45+
project.template.empty.description=An empty module where you can set the file structure yourself.
4646
project.template.test=Unit Test Module
4747
project.template.documentation=Documentation Module
4848
project.template.test.description=Unit test module

resources/fileTemplates/internal/Package.m.ft

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@
1212
(* :Keywords: *)
1313
(* :Discussion: *)
1414

15-
BeginPackage["${NAME}`"]
15+
BeginPackage["${NAME}`"];
1616
(* Exported symbols added here with SymbolName::usage *)
1717

18-
Begin["`Private`"]
18+
Begin["`Private`"];
1919

20-
End[] (* `Private` *)
20+
End[]; (* `Private` *)
2121

2222
EndPackage[]
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
(* Paclet Info File *)
2+
(* Created by Mathematica Plugin for IntelliJ IDEA *)
3+
4+
Paclet[
5+
Name -> "${MathematicaContext}",
6+
Version -> "0.1",
7+
MathematicaVersion -> "${MathematicaVersion}",
8+
Extensions ->
9+
{
10+
{"Kernel", Root -> "Kernel", Context -> "${MathematicaContext}`"}
11+
}
12+
]
13+
14+
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<html>
2+
<body>
3+
A template for a Mathematica PacletInfo.m file
4+
</body>
5+
</html>

src/de/halirutan/mathematica/file/MathematicaFileTemplateProvider.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ public class MathematicaFileTemplateProvider {
4242
@NonNls
4343
public static final String PACKAGE = "Package.m";
4444

45+
@NonNls
46+
public static final String PACLET_INFO = "PacletInfo.m";
47+
4548
@NonNls
4649
public static final String NOTEBOOK = "Notebook.nb";
4750

@@ -54,12 +57,13 @@ public class MathematicaFileTemplateProvider {
5457
@NonNls
5558
public static final String INIT = "init.m";
5659

60+
5761
@Nullable
58-
private static PsiElement createFromTemplate(@NotNull Project project,
59-
@NotNull VirtualFile rootDir,
60-
@NotNull String templateName,
61-
@NotNull String fileName,
62-
@NotNull Properties properties) throws Exception {
62+
public static PsiElement createFromTemplate(@NotNull Project project,
63+
@NotNull VirtualFile rootDir,
64+
@NotNull String templateName,
65+
@NotNull String fileName,
66+
@NotNull Properties properties) throws Exception {
6367
rootDir.refresh(false, false);
6468
PsiDirectory directory = PsiManager.getInstance(project).findDirectory(rootDir);
6569
if (directory != null) {

src/de/halirutan/mathematica/index/packageexport/MathematicaPackageExportIndex.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
public class MathematicaPackageExportIndex extends ScalarIndexExtension<PackageExportSymbol> {
4848

4949
public static final ID<PackageExportSymbol, Void> INDEX_ID = ID.create("Mathematica.fileExports");
50-
private static final int BASE_VERSION = 10;
50+
private static final int BASE_VERSION = 11;
5151
private static final LanguageFileType MATHEMATICA_FILE_TYPE = MathematicaLanguage.INSTANCE.getAssociatedFileType();
5252
private static final Set<String> IGNORED_FILES = new HashSet<>();
5353

src/de/halirutan/mathematica/lang/resolve/MathematicaGlobalResolveCache.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public class MathematicaGlobalResolveCache {
3232
private final Map<LightFileSymbol, SymbolResolveResult> myCachedFileSymbols = new ConcurrentHashMap<>();
3333
private final Map<LightBuiltInSymbol, SymbolResolveResult> myCachedBuiltinSymbols = new ConcurrentHashMap<>();
3434
private final Map<LightExternalSymbol, SymbolResolveResult> myCachedExternalSymbols = new ConcurrentHashMap<>();
35-
private boolean myIsCacheValid = false;
35+
private boolean myInvalidCache = true;
3636

3737
private MathematicaGlobalResolveCache(@Nullable("can be null in com.intellij.core.JavaCoreApplicationEnvironment.JavaCoreApplicationEnvironment") MessageBus messageBus) {
3838
if (messageBus != null) {
@@ -52,14 +52,14 @@ public static MathematicaGlobalResolveCache getInstance(Project project) {
5252
}
5353

5454
private void markInvalid() {
55-
myIsCacheValid = false;
55+
myInvalidCache = true;
5656
}
5757

5858
private void clearCaches() {
5959
myCachedFileSymbols.clear();
6060
myCachedBuiltinSymbols.clear();
6161
myCachedExternalSymbols.clear();
62-
myIsCacheValid = true;
62+
myInvalidCache = false;
6363

6464
}
6565

@@ -83,7 +83,7 @@ private boolean containsExternalSymbol(@NotNull Symbol symbol) {
8383
}
8484

8585
public SymbolResolveResult cacheFileSymbol(@NotNull Symbol symbol, PsiElement scopeElement) {
86-
if (!myIsCacheValid) {
86+
if (myInvalidCache) {
8787
clearCaches();
8888
}
8989
final LightFileSymbol lightSymbol = new LightFileSymbol(symbol);
@@ -92,7 +92,7 @@ public SymbolResolveResult cacheFileSymbol(@NotNull Symbol symbol, PsiElement sc
9292
}
9393

9494
public SymbolResolveResult cacheInvalidFileSymbol(@NotNull Symbol symbol, PsiElement scopeElement) {
95-
if (!myIsCacheValid) {
95+
if (myInvalidCache) {
9696
clearCaches();
9797
}
9898
final LightFileSymbol lightSymbol = new LightFileSymbol(symbol);
@@ -102,7 +102,7 @@ public SymbolResolveResult cacheInvalidFileSymbol(@NotNull Symbol symbol, PsiEle
102102

103103

104104
public SymbolResolveResult cacheBuiltInSymbol(@NotNull Symbol symbol) {
105-
if (!myIsCacheValid) {
105+
if (myInvalidCache) {
106106
clearCaches();
107107
}
108108
final LightBuiltInSymbol lightSymbol = new LightBuiltInSymbol(symbol);
@@ -111,7 +111,7 @@ public SymbolResolveResult cacheBuiltInSymbol(@NotNull Symbol symbol) {
111111
}
112112

113113
public SymbolResolveResult cacheExternalSymbol(@NotNull Symbol symbol, @NotNull Symbol externalSymbol, PsiElement scopeElement) {
114-
if (!myIsCacheValid) {
114+
if (myInvalidCache) {
115115
clearCaches();
116116
}
117117
final LightExternalSymbol lightSymbol = new LightExternalSymbol(symbol);
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package de.halirutan.mathematica.module;
2+
3+
import com.intellij.openapi.project.Project;
4+
import com.intellij.openapi.vfs.VirtualFile;
5+
import de.halirutan.mathematica.MathematicaBundle;
6+
7+
/**
8+
* @author patrick (08.12.17).
9+
*/
10+
public class MathematicaApplicationModule extends MathematicaModuleBuilder {
11+
public MathematicaApplicationModule() {
12+
}
13+
14+
15+
@Override
16+
public String getPresentableName() {
17+
return MathematicaBundle.message("project.template.application");
18+
}
19+
20+
@Override
21+
public String getDescription() {
22+
return MathematicaBundle.message("project.template.application.description");
23+
}
24+
25+
@Override
26+
protected void createModuleStructure(Project project, VirtualFile contentRoot) {
27+
createKernelFiles(project, contentRoot);
28+
createProjectFiles(project, contentRoot);
29+
createPacletInfoFile(project, contentRoot);
30+
}
31+
32+
@Override
33+
protected boolean isAvailable() {
34+
return true;
35+
}
36+
}

0 commit comments

Comments
 (0)