Skip to content

Commit eebc723

Browse files
committed
WIP
Builds fine, but different IDEA based IDEs have different classes available at runtime, will have to try to stick to common subset. WebStorm support should be based on similar version as AS and IntelliJ, eg ~141 which is WebStorm 10.x.
1 parent dc696d9 commit eebc723

File tree

9 files changed

+62
-30
lines changed

9 files changed

+62
-30
lines changed

src/ServiceStackIDEA/src/main/java/net/servicestack/idea/AddServiceStackRefHandler.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,10 @@ private static List<String> getDtoLines(String addressUrl, String qualifiedPacka
117117
}
118118

119119
private static INativeTypesHandler getNativeTypesHandler(String fileName) {
120-
if(fileName.endsWith(".kt")) return new KotlinNativeTypesHandler();
121-
if(fileName.endsWith(".java")) return new JavaNativeTypesHandler();
120+
INativeTypesHandler nativeTypesHandler = IDEAUtils.getNativeTypesHandler(fileName);
121+
if(nativeTypesHandler != null) {
122+
return nativeTypesHandler;
123+
}
122124
return defaultNativeTypesHandler;
123125
}
124126

src/ServiceStackIDEA/src/main/java/net/servicestack/idea/AddServiceStackReference.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,15 @@
88
import com.intellij.notification.Notifications;
99
import com.intellij.openapi.actionSystem.AnAction;
1010
import com.intellij.openapi.actionSystem.AnActionEvent;
11-
import com.intellij.openapi.actionSystem.DataKeys;
11+
import com.intellij.openapi.actionSystem.LangDataKeys;
1212
import com.intellij.openapi.editor.Document;
1313
import com.intellij.openapi.fileEditor.FileDocumentManager;
1414
import com.intellij.openapi.module.Module;
1515
import com.intellij.openapi.module.ModuleManager;
1616
import com.intellij.openapi.project.Project;
1717
import com.intellij.openapi.vfs.VirtualFile;
1818
import com.intellij.psi.*;
19+
import com.intellij.util.PlatformUtils;
1920
import org.jetbrains.annotations.NotNull;
2021

2122
import java.util.ArrayList;
@@ -33,7 +34,7 @@ public void actionPerformed(AnActionEvent e) {
3334
dialog.setTitle("Add ServiceStack Reference");
3435

3536
//Check if a package was selected in the left hand menu, populate package name
36-
PsiElement element = DataKeys.PSI_ELEMENT.getData(e.getDataContext());
37+
PsiElement element = LangDataKeys.PSI_ELEMENT.getData(e.getDataContext());
3738
if (element != null && element instanceof PsiPackage) {
3839
PsiPackage psiPackage = (PsiPackage) element;
3940
dialog.setSelectedPackage(psiPackage);
@@ -79,7 +80,7 @@ public void actionPerformed(AnActionEvent e) {
7980
}
8081

8182
//Check if a Java file was selected, display without a package name if no file.
82-
VirtualFile selectedFile = DataKeys.VIRTUAL_FILE.getData(e.getDataContext());
83+
VirtualFile selectedFile = LangDataKeys.VIRTUAL_FILE.getData(e.getDataContext());
8384
if (selectedFile == null) {
8485
Notification notification = new Notification("ServiceStackIDEA", "Error Add ServiceStack Reference", "Context menu failed find folder or file.", NotificationType.ERROR);
8586
Notifications.Bus.notify(notification);
@@ -153,7 +154,7 @@ public void update(AnActionEvent e) {
153154

154155
boolean isMavenModule = IDEAPomFileHelper.isMavenModule(module);
155156

156-
if (isAndroidProject(module) || isMavenModule) {
157+
if (isAndroidProject(module) || isMavenModule || PlatformUtils.isWebStorm()) {
157158
e.getPresentation().setEnabled(true);
158159
} else {
159160
e.getPresentation().setEnabled(false);
@@ -184,9 +185,9 @@ private static boolean isAndroidProject(@NotNull Module module) {
184185
}
185186

186187
static Module getModule(AnActionEvent e) {
187-
Module module = e.getData(DataKeys.MODULE);
188+
Module module = e.getData(LangDataKeys.MODULE);
188189
if (module == null) {
189-
Project project = e.getData(DataKeys.PROJECT);
190+
Project project = e.getData(LangDataKeys.PROJECT);
190191
return getModule(project);
191192
} else {
192193
return module;

src/ServiceStackIDEA/src/main/java/net/servicestack/idea/IDEAUtils.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import com.intellij.openapi.vfs.VirtualFile;
1010
import com.intellij.openapi.vfs.VirtualFileManager;
1111
import com.intellij.psi.PsiDocumentManager;
12+
import com.intellij.util.PlatformUtils;
1213

1314
import java.io.File;
1415

@@ -70,12 +71,19 @@ public static INativeTypesHandler getDefaultNativeTypesHandler(Module module) {
7071
if(IDEAPomFileHelper.isMavenProjectWithKotlin(module)) {
7172
return new KotlinNativeTypesHandler();
7273
}
74+
75+
if(PlatformUtils.isWebStorm()) {
76+
return new TypeScriptNativeTypesHandler();
77+
}
78+
7379
return new JavaNativeTypesHandler();
7480
}
7581

76-
public static INativeTypesHandler getNativeTypesHandler(Module module,String fileName) {
77-
if(fileName.endsWith(".kt")) return new KotlinNativeTypesHandler();
78-
if(fileName.endsWith(".java")) return new JavaNativeTypesHandler();
79-
return getDefaultNativeTypesHandler(module);
82+
public static INativeTypesHandler getNativeTypesHandler(String fileName) {
83+
INativeTypesHandler result = null;
84+
if(fileName.endsWith(".kt")) result = new KotlinNativeTypesHandler();
85+
if(fileName.endsWith(".java")) result = new JavaNativeTypesHandler();
86+
if(fileName.endsWith(".dtos.ts")) result = new TypeScriptNativeTypesHandler();
87+
return result;
8088
}
8189
}

src/ServiceStackIDEA/src/main/java/net/servicestack/idea/NativeTypesLanguage.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@
55
*/
66
public enum NativeTypesLanguage {
77
Java,
8-
Kotlin
8+
Kotlin,
9+
TypeScript
910
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package net.servicestack.idea;
2+
3+
/**
4+
* Created by Layoric on 13/05/2016.
5+
*/
6+
public class TypeScriptNativeTypesHandler extends BaseNativeTypesHandler {
7+
@Override
8+
public String getFileExtension() {
9+
return ".dtos.ts";
10+
}
11+
12+
@Override
13+
public String getRelativeTypesUrl() {
14+
return "types/typescript";
15+
}
16+
17+
@Override
18+
public NativeTypesLanguage getTypesLanguage() {
19+
return NativeTypesLanguage.TypeScript;
20+
}
21+
}

src/ServiceStackIDEA/src/main/java/net/servicestack/idea/UpdateServiceStackReference.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import com.intellij.openapi.actionSystem.AnAction;
44
import com.intellij.openapi.actionSystem.AnActionEvent;
5-
import com.intellij.openapi.actionSystem.DataKeys;
5+
import com.intellij.openapi.actionSystem.LangDataKeys;
66
import com.intellij.openapi.application.ApplicationManager;
77
import com.intellij.openapi.editor.Document;
88
import com.intellij.openapi.fileEditor.FileDocumentManager;
@@ -40,8 +40,9 @@ public void update(AnActionEvent e) {
4040
return;
4141
}
4242

43-
if(!psiFile.getFileType().getDefaultExtension().equals("java") &&
44-
!psiFile.getFileType().getDefaultExtension().equals("kt")) {
43+
INativeTypesHandler nativeTypesHandler = IDEAUtils.getNativeTypesHandler(psiFile.getName());
44+
45+
if(nativeTypesHandler == null) {
4546
e.getPresentation().setVisible(false);
4647
return;
4748
}
@@ -71,7 +72,7 @@ private static PsiFile getPsiFile(AnActionEvent e) {
7172
if(module == null) {
7273
return null;
7374
}
74-
VirtualFile selectedFile = DataKeys.VIRTUAL_FILE.getData(e.getDataContext());
75+
VirtualFile selectedFile = LangDataKeys.VIRTUAL_FILE.getData(e.getDataContext());
7576
if(selectedFile == null) {
7677
return null;
7778
}
@@ -90,9 +91,9 @@ private static PsiFile getPsiFile(AnActionEvent e) {
9091
}
9192

9293
static Module getModule(AnActionEvent e) {
93-
Module module = e.getData(DataKeys.MODULE);
94+
Module module = e.getData(LangDataKeys.MODULE);
9495
if (module == null) {
95-
Project project = e.getData(DataKeys.PROJECT);
96+
Project project = e.getData(LangDataKeys.PROJECT);
9697
return getModule(project);
9798
} else {
9899
return module;

src/ServiceStackIDEA/src/main/java/net/servicestack/idea/UpdateServiceStackReferenceIntention.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,9 @@
22

33
import com.intellij.codeInsight.intention.impl.QuickEditAction;
44
import com.intellij.openapi.editor.Editor;
5-
import com.intellij.openapi.module.Module;
6-
import com.intellij.openapi.module.ModuleUtil;
75
import com.intellij.openapi.project.Project;
86
import com.intellij.openapi.util.Iconable;
9-
import com.intellij.psi.PsiFile;
10-
import com.intellij.psi.PsiJavaFile;
7+
import com.intellij.psi.*;
118
import com.intellij.util.IncorrectOperationException;
129
import org.jetbrains.annotations.NotNull;
1310

@@ -34,9 +31,11 @@ public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile psiF
3431
if(psiFile == null) {
3532
return false;
3633
}
37-
if(!(psiFile instanceof PsiJavaFile || psiFile.getFileType().getDefaultExtension().equals("kt"))) {
34+
INativeTypesHandler nativeTypesHandler = IDEAUtils.getNativeTypesHandler(psiFile.getName());
35+
if(nativeTypesHandler == null) {
3836
return false;
3937
}
38+
4039
if(UpdateServiceStackUtils.containsOptionsHeader(psiFile)) {
4140
return true;
4241
}

src/ServiceStackIDEA/src/main/java/net/servicestack/idea/UpdateServiceStackUtils.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
import com.intellij.openapi.module.ModuleUtil;
1010
import com.intellij.openapi.util.TextRange;
1111
import com.intellij.psi.PsiFile;
12-
import com.intellij.psi.PsiJavaFile;
13-
import org.apache.commons.httpclient.NameValuePair;
1412
import org.apache.http.client.utils.URIBuilder;
1513

1614
import java.io.BufferedReader;
@@ -65,8 +63,7 @@ public static void updateServiceStackReference(PsiFile psiFile) {
6563
return;
6664
}
6765

68-
Module module = ModuleUtil.findModuleForPsiElement(psiFile);
69-
INativeTypesHandler nativeTypesHandler = IDEAUtils.getNativeTypesHandler(module,psiFile.getName());
66+
INativeTypesHandler nativeTypesHandler = IDEAUtils.getNativeTypesHandler(psiFile.getName());
7067

7168
String existingPath = builder.getPath();
7269
if(existingPath == null || existingPath.equals("/")) {

src/ServiceStackIDEA/src/main/resources/META-INF/plugin.xml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
<idea-plugin version="2">
22
<id>net.servicestack.ideaplugin</id>
33
<name>ServiceStack</name>
4-
<version>1.0.9</version>
4+
<version>1.0.10</version>
55
<vendor email="team@servicestack.net" url="https://servicestack.net/">ServiceStack</vendor>
66

77
<description><![CDATA[
88
Integration with ServiceStack Web Services, includes support for Java and Kotlin Add ServiceStack Reference.
99
]]></description>
1010

1111
<change-notes><![CDATA[
12-
1.0.9 - Fix plugin to support Android Studio 2.0.
12+
1.0.10 - Add TypeScript support and enable extension for use with WebStorm. <br />
13+
1.0.9 - Fix plugin to support Android Studio 2.0. <br />
1314
1.0.8 - Add support for Kotlin projects with Add/Update ServiceStack reference. <br />
1415
1.0.7 - Bug fixes and client now gets dependency version from ServiceStack.Java tags, falls back to 1.0.15 if it fails. <br />
1516
1.0.6 - Update client and android dependency versions to 1.0.13. <br />
@@ -27,6 +28,7 @@
2728
<!-- please see http://confluence.jetbrains.com/display/IDEADEV/Plugin+Compatibility+with+IntelliJ+Platform+Products
2829
on how to target different products -->
2930
<depends>com.intellij.modules.lang</depends>
31+
<depends>com.intellij.modules.platform</depends>
3032

3133
<extensions defaultExtensionNs="com.intellij">
3234
<!-- Add your extensions here -->

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy