diff --git a/typescript.java-ts.core/.gitignore b/typescript.java-ts.core/.gitignore
new file mode 100644
index 00000000..b83d2226
--- /dev/null
+++ b/typescript.java-ts.core/.gitignore
@@ -0,0 +1 @@
+/target/
diff --git a/typescript.java-ts.core/LICENSE b/typescript.java-ts.core/LICENSE
new file mode 100644
index 00000000..29470672
--- /dev/null
+++ b/typescript.java-ts.core/LICENSE
@@ -0,0 +1,22 @@
+The MIT License (MIT)
+
+Copyright (c) 2015 Angelo
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
+
diff --git a/typescript.java-ts.core/README.md b/typescript.java-ts.core/README.md
new file mode 100644
index 00000000..5979959d
--- /dev/null
+++ b/typescript.java-ts.core/README.md
@@ -0,0 +1,9 @@
+# typescript.java ts.core, modified for jsweet
+
+This is a modified copy of [typescript.java](https://github.com/angelozerr/typescript.java)'s ts.core module.
+
+The source code has been reconstructed from the source jar available at https://repository.jsweet.org/artifactory/libs-release-local/org/jsweet/ext/typescript.java-ts.core/2.0.4/ since no other place could be found.
+
+## Licence
+
+The MIT License (MIT)
diff --git a/typescript.java-ts.core/pom.xml b/typescript.java-ts.core/pom.xml
new file mode 100644
index 00000000..38bd1c7a
--- /dev/null
+++ b/typescript.java-ts.core/pom.xml
@@ -0,0 +1,141 @@
+
+ 4.0.0
+ org.jsweet.ext
+ typescript.java-ts.core
+ jar
+ 2.0.4
+
+ ${maven.build.timestamp}
+ yyyy-MM-dd HH:mm:ss
+ UTF-8
+ 11
+ 1.${java.version.release}
+
+
+ src
+
+
+ src/main/resources
+ true
+
+
+
+
+ maven-compiler-plugin
+ 3.8.1
+
+ ${java.version.release}
+ ${java.version}
+ ${java.version}
+ ${java.version}
+ ${project.build.sourceEncoding}
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-surefire-plugin
+ 2.18.1
+
+
+ **/*.java
+
+
+
+
+ org.apache.maven.plugins
+ maven-source-plugin
+ 3.0.0
+
+
+ attach-sources
+
+ jar
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-javadoc-plugin
+ 2.10.3
+
+ 1.8
+ src
+ ${project.build.sourceEncoding}
+ ${skipJavadoc}
+ all
+ false
+ javadoc-out
+ javadoc-out/ts.core-${project.version}
+
+
+
+ attach-javadocs
+
+ jar
+
+
+
+
+
+
+
+
+ com.eclipsesource.minimal-json
+ minimal-json
+ 0.9.4
+
+
+ com.google.code.gson
+ gson
+ 2.8.6
+
+
+ org.tukaani
+ xz
+ 1.8
+
+
+ org.osgi
+ org.osgi.core
+ 4.3.0
+ provided
+
+
+
+
+
+
+ jsweet-central
+ libs-release
+ http://repository.jsweet.org/artifactory/libs-release-local
+
+
+
+ jsweet-snapshots
+ libs-snapshot
+ http://repository.jsweet.org/artifactory/libs-snapshot-local
+
+
+ jsweet-external
+ libs-release
+ http://repository.jsweet.org/artifactory/ext-release-local
+
+
+
+
+ jsweet-release
+ libs-release
+ http://repository.jsweet.org/artifactory/libs-release-local
+
+
+ jsweet-snapshots
+ libs-snapshot
+ http://repository.jsweet.org/artifactory/libs-snapshot-local
+
+
+
diff --git a/typescript.java-ts.core/src/main/java/ts/OS.java b/typescript.java-ts.core/src/main/java/ts/OS.java
new file mode 100644
index 00000000..cf78bf6d
--- /dev/null
+++ b/typescript.java-ts.core/src/main/java/ts/OS.java
@@ -0,0 +1,20 @@
+/**
+ * Copyright (c) 2016-2017 Angelo ZERR.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Angelo Zerr - initial API and implementation
+ */
+package ts;
+
+/**
+ * OS enumerations.
+ *
+ */
+public enum OS {
+
+ Windows, MacOS, Linux;
+}
diff --git a/typescript.java-ts.core/src/main/java/ts/ScriptElementKind.java b/typescript.java-ts.core/src/main/java/ts/ScriptElementKind.java
new file mode 100644
index 00000000..4dc6f430
--- /dev/null
+++ b/typescript.java-ts.core/src/main/java/ts/ScriptElementKind.java
@@ -0,0 +1,30 @@
+/**
+ * Copyright (c) 2015-2016 Angelo ZERR.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Angelo Zerr - initial API and implementation
+ */
+package ts;
+
+/**
+ * TypeScript model kind.
+ *
+ * @see https://github.com/Microsoft/TypeScript/blob/master/src/services/types.ts
+ *
+ */
+public enum ScriptElementKind {
+
+ ALIAS, PRIMITIVE_TYPE, KEYWORD, CLASS, INTERFACE, MODULE, SCRIPT, DIRECTORY, PROPERTY, METHOD, CONSTRUCTOR, FUNCTION, VAR, LET, ENUM, TYPE, ELEMENT, ATTRIBUTE, COMPONENT, CONST, GETTER, SETTER, WARNING;
+
+ public static ScriptElementKind getKind(String kind) {
+ try {
+ return ScriptElementKind.valueOf(kind.toUpperCase());
+ } catch (Exception e) {
+ return ScriptElementKind.WARNING;
+ }
+ }
+}
diff --git a/typescript.java-ts.core/src/main/java/ts/ScriptElementKindModifier.java b/typescript.java-ts.core/src/main/java/ts/ScriptElementKindModifier.java
new file mode 100644
index 00000000..28110c5e
--- /dev/null
+++ b/typescript.java-ts.core/src/main/java/ts/ScriptElementKindModifier.java
@@ -0,0 +1,54 @@
+/**
+ * Copyright (c) 2015-2016 Angelo ZERR.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Angelo Zerr - initial API and implementation
+ */
+package ts;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * TypeScript model kind modifier.
+ *
+ * @see https://github.com/Microsoft/TypeScript/blob/master/src/services/types.ts
+ *
+ */
+public enum ScriptElementKindModifier {
+
+ none(""), publicMemberModifier("public"), privateMemberModifier("private"), protectedMemberModifier(
+ "protected"), exportedModifier(
+ "export"), ambientModifier("declare"), staticModifier("static"), abstractModifier("abstract");
+
+ private static final Map cache = Collections.unmodifiableMap(initializeCache());
+
+ private final String name;
+
+ private ScriptElementKindModifier(String name) {
+ this.name = name;
+ }
+
+ private static Map initializeCache() {
+ Map cache = new HashMap<>();
+ ScriptElementKindModifier[] values = ScriptElementKindModifier.values();
+ for (int i = 0; i < values.length; i++) {
+ ScriptElementKindModifier value = values[i];
+ cache.put(value.getName(), value);
+ }
+ return cache;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public static ScriptElementKindModifier getKindModifier(String modifier) {
+ return cache.get(modifier);
+ }
+}
diff --git a/typescript.java-ts.core/src/main/java/ts/TypeScriptException.java b/typescript.java-ts.core/src/main/java/ts/TypeScriptException.java
new file mode 100644
index 00000000..1a3bb89a
--- /dev/null
+++ b/typescript.java-ts.core/src/main/java/ts/TypeScriptException.java
@@ -0,0 +1,28 @@
+/**
+ * Copyright (c) 2015-2016 Angelo ZERR.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Angelo Zerr - initial API and implementation
+ */
+package ts;
+
+/**
+ * TypeScript Exception.
+ *
+ */
+@SuppressWarnings("serial")
+public class TypeScriptException extends Exception {
+
+ public TypeScriptException(String message) {
+ super(message);
+ }
+
+ public TypeScriptException(Throwable e) {
+ super(e);
+ }
+
+}
diff --git a/typescript.java-ts.core/src/main/java/ts/TypeScriptNoContentAvailableException.java b/typescript.java-ts.core/src/main/java/ts/TypeScriptNoContentAvailableException.java
new file mode 100644
index 00000000..c08285bf
--- /dev/null
+++ b/typescript.java-ts.core/src/main/java/ts/TypeScriptNoContentAvailableException.java
@@ -0,0 +1,25 @@
+/**
+ * Copyright (c) 2015-2016 Angelo ZERR.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Angelo Zerr - initial API and implementation
+ */
+package ts;
+
+/**
+ * TypeScript exception thown when tsserver throws error "No content
+ * available."
+ *
+ */
+@SuppressWarnings("serial")
+public class TypeScriptNoContentAvailableException extends TypeScriptException {
+
+ public TypeScriptNoContentAvailableException(String message) {
+ super(message);
+ }
+
+}
diff --git a/typescript.java-ts.core/src/main/java/ts/client/CodeEdit.java b/typescript.java-ts.core/src/main/java/ts/client/CodeEdit.java
new file mode 100644
index 00000000..f692c4e0
--- /dev/null
+++ b/typescript.java-ts.core/src/main/java/ts/client/CodeEdit.java
@@ -0,0 +1,64 @@
+/**
+ * Copyright (c) 2015-2016 Angelo ZERR.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Angelo Zerr - initial API and implementation
+ */
+package ts.client;
+
+/**
+ * Object found in response messages defining an editing instruction for a span
+ * of text in source code. The effect of this instruction is to replace the text
+ * starting at start and ending one character before end with newText. For an
+ * insertion, the text span is empty. For a deletion, newText is empty.
+ */
+public class CodeEdit {
+
+ /**
+ * First character of the text span to edit.
+ */
+ private Location start;
+
+ /**
+ * One character past last character of the text span to edit.
+ */
+ private Location end;
+
+ /**
+ * Replace the span defined above with this string (may be the empty
+ * string).
+ */
+ private String newText;
+
+ /**
+ * Returns first character of the text span to edit.
+ *
+ * @return first character of the text span to edit.
+ */
+ public Location getStart() {
+ return start;
+ }
+
+ /**
+ * Returns one character past last character of the text span to edit.
+ *
+ * @return one character past last character of the text span to edit.
+ */
+ public Location getEnd() {
+ return end;
+ }
+
+ /**
+ * Replace the span defined above with this string (may be the empty string)
+ *
+ * @return replace the span defined above with this string (may be the empty
+ * string)
+ */
+ public String getNewText() {
+ return newText;
+ }
+}
diff --git a/typescript.java-ts.core/src/main/java/ts/client/CommandCapability.java b/typescript.java-ts.core/src/main/java/ts/client/CommandCapability.java
new file mode 100644
index 00000000..aa45b65a
--- /dev/null
+++ b/typescript.java-ts.core/src/main/java/ts/client/CommandCapability.java
@@ -0,0 +1,26 @@
+package ts.client;
+
+import ts.utils.VersionHelper;
+
+public enum CommandCapability implements ISupportable {
+
+ DiagnosticWithCategory("2.3.1");
+
+ private String sinceVersion;
+
+ private CommandCapability(String version) {
+ this.sinceVersion = version;
+ }
+
+ /**
+ * Return true if the tsc compiler option support the given version and
+ * false otherwise.
+ *
+ * @param version
+ * @return true if the tsc compiler option support the given version and
+ * false otherwise.
+ */
+ public boolean canSupport(String version) {
+ return VersionHelper.canSupport(version, sinceVersion);
+ }
+}
diff --git a/typescript.java-ts.core/src/main/java/ts/client/CommandNames.java b/typescript.java-ts.core/src/main/java/ts/client/CommandNames.java
new file mode 100644
index 00000000..64341fbb
--- /dev/null
+++ b/typescript.java-ts.core/src/main/java/ts/client/CommandNames.java
@@ -0,0 +1,93 @@
+/**
+ * Copyright (c) 2015-2016 Angelo ZERR.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Angelo Zerr - initial API and implementation
+ */
+package ts.client;
+
+import ts.utils.VersionHelper;
+
+/**
+ * Command names of tsserver.
+ *
+ */
+public enum CommandNames implements ISupportable {
+
+ Open("open"),
+ Close("close"),
+ Change("change"),
+ NavBar("navbar"),
+ Completions("completions"),
+ CompletionEntryDetails("completionEntryDetails"),
+ Reload("reload"),
+ Definition("definition"),
+ SignatureHelp("signatureHelp"),
+ QuickInfo("quickinfo"),
+ Geterr("geterr"),
+ GeterrForProject("geterrForProject"),
+ Format("format"),
+ References("references"),
+ Occurrences("occurrences"),
+ Configure("configure"),
+ ProjectInfo("projectInfo"),
+ Rename("rename"),
+ NavTo("navto"),
+
+ // 2.0.0
+ SemanticDiagnosticsSync("semanticDiagnosticsSync", "2.0.0"),
+ SyntacticDiagnosticsSync("syntacticDiagnosticsSync", "2.0.0"),
+
+ // 2.0.5
+ CompileOnSaveAffectedFileList("compileOnSaveAffectedFileList", "2.0.5"),
+ CompileOnSaveEmitFile("compileOnSaveEmitFile", "2.0.5"),
+
+ // 2.0.6
+ NavTree("navtree", "2.0.6"),
+ DocCommentTemplate("docCommentTemplate", "2.0.6"),
+
+ // 2.1.0
+ Implementation("implementation", "2.1.0"),
+ GetSupportedCodeFixes("getSupportedCodeFixes", "2.1.0"),
+ GetCodeFixes("getCodeFixes", "2.1.0"),
+
+ // 2.4.0
+ GetApplicableRefactors("getApplicableRefactors", "2.4.0"),
+ GetEditsForRefactor("getEditsForRefactor", "2.4.0"),
+
+ OpenExternalProject("openExternalProject"),
+ CloseExternalProject("closeExternalProject");
+
+ private final String name;
+ private final String sinceVersion;
+
+ private CommandNames(String name) {
+ this(name, null);
+ }
+
+ private CommandNames(String name, String sinceVersion) {
+ this.name = name;
+ this.sinceVersion = sinceVersion;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * Return true if the tsserver command support the given version and false
+ * otherwise.
+ *
+ * @param version
+ * @return true if the tsserver command support the given version and false
+ * otherwise.
+ */
+ public boolean canSupport(String version) {
+ return VersionHelper.canSupport(version, sinceVersion);
+ }
+
+}
diff --git a/typescript.java-ts.core/src/main/java/ts/client/Event.java b/typescript.java-ts.core/src/main/java/ts/client/Event.java
new file mode 100644
index 00000000..34507183
--- /dev/null
+++ b/typescript.java-ts.core/src/main/java/ts/client/Event.java
@@ -0,0 +1,29 @@
+package ts.client;
+
+import ts.internal.client.protocol.Message;
+
+/**
+ * Server-initiated event message
+ *
+ * @param
+ */
+public class Event extends Message {
+
+ /**
+ * Name fo event.
+ */
+ private String event;
+
+ /**
+ * Event-specific information
+ */
+ private T body;
+
+ public String getEvent() {
+ return event;
+ }
+
+ public T getBody() {
+ return body;
+ }
+}
diff --git a/typescript.java-ts.core/src/main/java/ts/client/ExternalFile.java b/typescript.java-ts.core/src/main/java/ts/client/ExternalFile.java
new file mode 100644
index 00000000..705971c6
--- /dev/null
+++ b/typescript.java-ts.core/src/main/java/ts/client/ExternalFile.java
@@ -0,0 +1,29 @@
+package ts.client;
+
+public class ExternalFile {
+ /**
+ * Name of file file
+ */
+ String fileName;
+ /**
+ * Script kind of the file
+ */
+ ScriptKindName scriptKind;
+ /**
+ * Whether file has mixed content (i.e. .cshtml file that combines html markup
+ * with C#/JavaScript)
+ */
+ Boolean hasMixedContent;
+ /**
+ * Content of the file
+ */
+ String content;
+
+ public ExternalFile(String fileName, ScriptKindName scriptKind, Boolean hasMixedContent, String content) {
+ this.fileName = fileName;
+ this.scriptKind = scriptKind;
+ this.hasMixedContent = hasMixedContent;
+ this.content = content;
+ }
+
+}
\ No newline at end of file
diff --git a/typescript.java-ts.core/src/main/java/ts/client/FileSpan.java b/typescript.java-ts.core/src/main/java/ts/client/FileSpan.java
new file mode 100644
index 00000000..c2db635a
--- /dev/null
+++ b/typescript.java-ts.core/src/main/java/ts/client/FileSpan.java
@@ -0,0 +1,29 @@
+/**
+ * Copyright (c) 2015-2017 Angelo ZERR.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Angelo Zerr - initial API and implementation
+ */
+package ts.client;
+
+/**
+ * Object found in response messages defining a span of text in a specific
+ * source file.
+ *
+ * @see https://github.com/Microsoft/TypeScript/blob/master/src/server/protocol.ts
+ */
+public class FileSpan extends TextSpan {
+
+ /**
+ * File containing text span.
+ */
+ private String file;
+
+ public String getFile() {
+ return file;
+ }
+}
diff --git a/typescript.java-ts.core/src/main/java/ts/client/IInterceptor.java b/typescript.java-ts.core/src/main/java/ts/client/IInterceptor.java
new file mode 100644
index 00000000..8a2a87e0
--- /dev/null
+++ b/typescript.java-ts.core/src/main/java/ts/client/IInterceptor.java
@@ -0,0 +1,25 @@
+/**
+ * Copyright (c) 2015-2016 Angelo ZERR.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Angelo Zerr - initial API and implementation
+ */
+package ts.client;
+
+import ts.internal.client.protocol.Response;
+import ts.internal.client.protocol.Request;
+
+public interface IInterceptor {
+
+ void handleRequest(Request> request, String json, ITypeScriptServiceClient client);
+
+ void handleResponse(Response> response, String json,
+ long ellapsedTime, TypeScriptServiceClient typeScriptServiceClient);
+
+ void handleError(Throwable error, ITypeScriptServiceClient client, String methodName,
+ long ellapsedTime);
+}
diff --git a/typescript.java-ts.core/src/main/java/ts/client/IKindProvider.java b/typescript.java-ts.core/src/main/java/ts/client/IKindProvider.java
new file mode 100644
index 00000000..495f1616
--- /dev/null
+++ b/typescript.java-ts.core/src/main/java/ts/client/IKindProvider.java
@@ -0,0 +1,8 @@
+package ts.client;
+
+public interface IKindProvider {
+
+ String getKind();
+
+ String getKindModifiers();
+}
diff --git a/typescript.java-ts.core/src/main/java/ts/client/IPositionProvider.java b/typescript.java-ts.core/src/main/java/ts/client/IPositionProvider.java
new file mode 100644
index 00000000..0906e704
--- /dev/null
+++ b/typescript.java-ts.core/src/main/java/ts/client/IPositionProvider.java
@@ -0,0 +1,49 @@
+/**
+ * Copyright (c) 2015-2016 Angelo ZERR.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Angelo Zerr - initial API and implementation
+ */
+package ts.client;
+
+import ts.TypeScriptException;
+
+/**
+ * Position provider.
+ *
+ */
+public interface IPositionProvider {
+
+ /**
+ * Returns the location (line/offset) from the given position.
+ *
+ * @param position
+ * @return the location (line/offset) from the given position.
+ * @throws TypeScriptException
+ */
+ Location getLocation(int position) throws TypeScriptException;
+
+ /**
+ * Returns the position from the given line, offset.
+ *
+ * @param line
+ * @param offset
+ * @return the position from the given line, offset.
+ * @throws TypeScriptException
+ */
+ int getPosition(int line, int offset) throws TypeScriptException;
+
+ /**
+ * Returns the position from the given location (line/offset).
+ *
+ * @param loc
+ * @return the position from the given location (line/offset)
+ * @throws TypeScriptException
+ */
+ int getPosition(Location loc) throws TypeScriptException;
+
+}
diff --git a/typescript.java-ts.core/src/main/java/ts/client/ISupportable.java b/typescript.java-ts.core/src/main/java/ts/client/ISupportable.java
new file mode 100644
index 00000000..456a571e
--- /dev/null
+++ b/typescript.java-ts.core/src/main/java/ts/client/ISupportable.java
@@ -0,0 +1,30 @@
+/**
+ * Copyright (c) 2015-2017 Angelo ZERR.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Angelo Zerr - initial API and implementation
+ */
+package ts.client;
+
+/**
+ * Supportable API.
+ *
+ */
+public interface ISupportable {
+
+ /**
+ * Returns true if the given tsserver command can be supported by the
+ * TypeScript version configured for the project and false otherwise.
+ *
+ * @param command
+ * @return true if the given tsserver command can be supported by the
+ * TypeScript version configured for the project and false
+ * otherwise.
+ */
+ boolean canSupport(String version);
+
+}
diff --git a/typescript.java-ts.core/src/main/java/ts/client/ITypeScriptClientListener.java b/typescript.java-ts.core/src/main/java/ts/client/ITypeScriptClientListener.java
new file mode 100644
index 00000000..623205fd
--- /dev/null
+++ b/typescript.java-ts.core/src/main/java/ts/client/ITypeScriptClientListener.java
@@ -0,0 +1,18 @@
+package ts.client;
+
+public interface ITypeScriptClientListener {
+
+ /**
+ * Method called when the given tsserver starts.
+ *
+ * @param server
+ */
+ void onStart(ITypeScriptServiceClient client);
+
+ /**
+ * Method called when the given tsserver stops.
+ *
+ * @param server
+ */
+ void onStop(ITypeScriptServiceClient client);
+}
diff --git a/typescript.java-ts.core/src/main/java/ts/client/ITypeScriptServiceClient.java b/typescript.java-ts.core/src/main/java/ts/client/ITypeScriptServiceClient.java
new file mode 100644
index 00000000..0bd01841
--- /dev/null
+++ b/typescript.java-ts.core/src/main/java/ts/client/ITypeScriptServiceClient.java
@@ -0,0 +1,335 @@
+/**
+ * Copyright (c) 2015-2017 Angelo ZERR.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Angelo Zerr - initial API and implementation
+ */
+package ts.client;
+
+import java.util.List;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.TimeUnit;
+
+import ts.TypeScriptException;
+import ts.client.codefixes.CodeAction;
+import ts.client.compileonsave.CompileOnSaveAffectedFileListSingleProject;
+import ts.client.completions.CompletionEntry;
+import ts.client.completions.CompletionEntryDetails;
+import ts.client.completions.ICompletionEntryFactory;
+import ts.client.configure.ConfigureRequestArguments;
+import ts.client.diagnostics.DiagnosticEvent;
+import ts.client.diagnostics.DiagnosticEventBody;
+import ts.client.installtypes.IInstallTypesListener;
+import ts.client.jsdoc.TextInsertion;
+import ts.client.navbar.NavigationBarItem;
+import ts.client.navto.NavtoItem;
+import ts.client.occurrences.OccurrencesResponseItem;
+import ts.client.projectinfo.ProjectInfo;
+import ts.client.quickinfo.QuickInfo;
+import ts.client.refactors.ApplicableRefactorInfo;
+import ts.client.refactors.RefactorEditInfo;
+import ts.client.references.ReferencesResponseBody;
+import ts.client.rename.RenameResponseBody;
+import ts.client.signaturehelp.SignatureHelpItems;
+import ts.cmd.tsc.CompilerOptions;
+
+/**
+ * TypeScript client API which communicates with tsserver.
+ *
+ * @see https://github.com/Microsoft/TypeScript/blob/master/src/server/client.ts
+ *
+ */
+public interface ITypeScriptServiceClient {
+
+ /**
+ * Open the given file name.
+ *
+ * @param fileName
+ * @param content
+ * @throws TypeScriptException
+ */
+ void openFile(String fileName, String content) throws TypeScriptException;
+
+ /**
+ * Open the given file name.
+ *
+ * @param fileName
+ * @param content
+ * @param scriptKindName
+ * @throws TypeScriptException
+ */
+ void openFile(String fileName, String content, ScriptKindName scriptKindName) throws TypeScriptException;
+
+ /**
+ * Open an external project based on a project name and its files with explicit
+ * options
+ *
+ * @param projectFileName
+ * @param rootFiles
+ * @param options
+ * @throws TypeScriptException
+ */
+ void openExternalProject(String projectFileName, List rootFiles, CompilerOptions options)
+ throws TypeScriptException;
+
+ /**
+ * Closes a previously opened external project
+ *
+ * @see #openExternalProject(String, List, CompilerOptions)
+ *
+ * @param projectFileName
+ * @throws TypeScriptException
+ */
+ void closeExternalProject(String projectFileName) throws TypeScriptException;
+
+ /**
+ * Close the given file name.
+ *
+ * @param fileName
+ * @param content
+ * @throws TypeScriptException
+ */
+ void closeFile(String fileName) throws TypeScriptException;
+
+ /**
+ * Change file content at the given positions.
+ *
+ * @param fileName
+ * @param position
+ * @param endPosition
+ * @param insertString
+ * @throws TypeScriptException
+ */
+ // void changeFile(String fileName, int position, int endPosition, String
+ // insertString) throws TypeScriptException;
+
+ /**
+ * Change file content at the given lines/offsets.
+ *
+ * @param fileName
+ * @param line
+ * @param offset
+ * @param endLine
+ * @param endOffset
+ * @param insertString
+ * @throws TypeScriptException
+ */
+ void changeFile(String fileName, int line, int offset, int endLine, int endOffset, String insertString)
+ throws TypeScriptException;
+
+ void updateFile(String fileName, String newText) throws TypeScriptException;
+
+ void updateFile(String fileName, String newText, long timeout, TimeUnit timeoutUnit) throws TypeScriptException;
+
+ /**
+ * Completion for the given fileName at the given position.
+ *
+ * @param fileName
+ * @param position
+ * @return completion for the given fileName at the given position.
+ * @throws TypeScriptException
+ */
+ // CompletableFuture> completions(String fileName, int
+ // position) throws TypeScriptException;
+
+ /**
+ * Completion for the given fileName at the given line/offset.
+ *
+ * @param fileName
+ * @param line
+ * @param offset
+ * @return completion for the given fileName at the given line/offset
+ * @throws TypeScriptException
+ */
+ CompletableFuture> completions(String fileName, int line, int offset)
+ throws TypeScriptException;
+
+ CompletableFuture> completions(String name, int line, int offset,
+ ICompletionEntryFactory instanceCreator) throws TypeScriptException;
+
+ CompletableFuture> completionEntryDetails(String fileName, int line, int offset,
+ String[] entryNames, CompletionEntry completionEntry) throws TypeScriptException;
+
+ /**
+ * Definition for the given fileName at the given line/offset.
+ *
+ * @param fileName
+ * @param line
+ * @param offset
+ * @return
+ * @throws TypeScriptException
+ */
+ CompletableFuture> definition(String fileName, int line, int offset) throws TypeScriptException;
+
+ /**
+ * Signature help for the given fileName at the given line/offset.
+ *
+ * @param fileName
+ * @param line
+ * @param offset
+ * @return
+ * @throws TypeScriptException
+ */
+ CompletableFuture signatureHelp(String fileName, int line, int offset)
+ throws TypeScriptException;
+
+ /**
+ * Quick info for the given fileName at the given line/offset.
+ *
+ * @param fileName
+ * @param line
+ * @param offset
+ * @return
+ * @throws TypeScriptException
+ */
+ CompletableFuture quickInfo(String fileName, int line, int offset) throws TypeScriptException;
+
+ CompletableFuture> geterr(String[] files, int delay) throws TypeScriptException;
+
+ CompletableFuture> geterrForProject(String file, int delay, ProjectInfo projectInfo)
+ throws TypeScriptException;
+
+ /**
+ * Format for the given fileName at the given line/offset.
+ *
+ * @param fileName
+ * @param line
+ * @param offset
+ * @param endLine
+ * @param endOffset
+ * @return
+ * @throws TypeScriptException
+ */
+ CompletableFuture> format(String fileName, int line, int offset, int endLine, int endOffset)
+ throws TypeScriptException;
+
+ /**
+ * Find references for the given fileName at the given line/offset.
+ *
+ * @param fileName
+ * @param line
+ * @param offset
+ * @return
+ * @throws TypeScriptException
+ */
+ CompletableFuture references(String fileName, int line, int offset)
+ throws TypeScriptException;
+
+ /**
+ * Find occurrences for the given fileName at the given line/offset.
+ *
+ * @param fileName
+ * @param line
+ * @param offset
+ * @return
+ * @throws TypeScriptException
+ */
+ CompletableFuture> occurrences(String fileName, int line, int offset)
+ throws TypeScriptException;
+
+ CompletableFuture rename(String file, int line, int offset, Boolean findInComments,
+ Boolean findInStrings) throws TypeScriptException;
+
+ CompletableFuture> navto(String fileName, String searchValue, Integer maxResultCount,
+ Boolean currentFileOnly, String projectFileName) throws TypeScriptException;
+
+ CompletableFuture> navbar(String fileName, IPositionProvider positionProvider)
+ throws TypeScriptException;
+
+ void configure(ConfigureRequestArguments arguments) throws TypeScriptException;
+
+ CompletableFuture projectInfo(String file, String projectFileName, boolean needFileNameList)
+ throws TypeScriptException;
+
+ // Since 2.0.3
+
+ /**
+ * Execute semantic diagnostics for the given file.
+ *
+ * @param includeLinePosition
+ * @return
+ * @throws TypeScriptException
+ */
+ CompletableFuture semanticDiagnosticsSync(String file, Boolean includeLinePosition)
+ throws TypeScriptException;
+
+ /**
+ * Execute syntactic diagnostics for the given file.
+ *
+ * @param includeLinePosition
+ * @return
+ * @throws TypeScriptException
+ */
+ CompletableFuture syntacticDiagnosticsSync(String file, Boolean includeLinePosition)
+ throws TypeScriptException;
+
+ // Since 2.0.5
+
+ CompletableFuture compileOnSaveEmitFile(String fileName, Boolean forced) throws TypeScriptException;
+
+ CompletableFuture> compileOnSaveAffectedFileList(String fileName)
+ throws TypeScriptException;
+
+ // Since 2.0.6
+
+ CompletableFuture navtree(String fileName, IPositionProvider positionProvider)
+ throws TypeScriptException;
+
+ CompletableFuture docCommentTemplate(String fileName, int line, int offset)
+ throws TypeScriptException;
+
+ // Since 2.1.0
+
+ CompletableFuture> getCodeFixes(String fileName, IPositionProvider positionProvider, int startLine,
+ int startOffset, int endLine, int endOffset, List errorCodes) throws TypeScriptException;
+
+ CompletableFuture> getSupportedCodeFixes() throws TypeScriptException;
+
+ /**
+ * Definition for the given fileName at the given line/offset.
+ *
+ * @param fileName
+ * @param line
+ * @param offset
+ * @return
+ * @throws TypeScriptException
+ */
+ CompletableFuture> implementation(String fileName, int line, int offset) throws TypeScriptException;
+
+ // Since 2.4.0
+
+ CompletableFuture> getApplicableRefactors(String fileName, int line, int offset)
+ throws TypeScriptException;
+
+ CompletableFuture> getApplicableRefactors(String fileName, int startLine,
+ int startOffset, int endLine, int endOffset) throws TypeScriptException;
+
+ CompletableFuture getEditsForRefactor(String fileName, int line, int offset, String refactor,
+ String action) throws TypeScriptException;
+
+ CompletableFuture getEditsForRefactor(String fileName, int startLine, int startOffset,
+ int endLine, int endOffset, String refactor, String action) throws TypeScriptException;
+
+ void addClientListener(ITypeScriptClientListener listener);
+
+ void removeClientListener(ITypeScriptClientListener listener);
+
+ void addInstallTypesListener(IInstallTypesListener listener);
+
+ void removeInstallTypesListener(IInstallTypesListener listener);
+
+ void addInterceptor(IInterceptor interceptor);
+
+ void removeInterceptor(IInterceptor interceptor);
+
+ void join() throws InterruptedException;
+
+ boolean isDisposed();
+
+ void dispose();
+
+}
diff --git a/typescript.java-ts.core/src/main/java/ts/client/Location.java b/typescript.java-ts.core/src/main/java/ts/client/Location.java
new file mode 100644
index 00000000..d46597e4
--- /dev/null
+++ b/typescript.java-ts.core/src/main/java/ts/client/Location.java
@@ -0,0 +1,80 @@
+/**
+ * Copyright (c) 2015-2016 Angelo ZERR.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Angelo Zerr - initial API and implementation
+ */
+package ts.client;
+
+import ts.TypeScriptException;
+
+/**
+ * Bean for location line/offset used by tsserver.
+ *
+ */
+public class Location {
+
+ private static final int NO_POSITION = -1;
+
+ private final IPositionProvider positionProvider;
+ private int line;
+ private int offset;
+ private int position;
+
+ public Location(IPositionProvider positionProvider) {
+ this.positionProvider = positionProvider;
+ this.position = NO_POSITION;
+ }
+
+ public Location() {
+ this(null);
+ }
+
+ public Location(int line, int offset, int position) {
+ this();
+ this.line = line;
+ this.offset = offset;
+ this.position = position;
+ }
+
+ public Location(int line, int offset) {
+ this(line, offset, NO_POSITION);
+ }
+
+ /**
+ * Returns the line location.
+ *
+ * @return the line location.
+ */
+ public int getLine() {
+ return line;
+ }
+
+ /**
+ * Returns the offset location.
+ *
+ * @return the offset location.
+ */
+ public int getOffset() {
+ return offset;
+ }
+
+ public int getPosition() {
+ if (position == NO_POSITION && positionProvider != null) {
+ try {
+ position = positionProvider.getPosition(line, offset);
+ } catch (TypeScriptException e) {
+ e.printStackTrace();
+ }
+ }
+ return position;
+ }
+
+ public void setPosition(int position) {
+ this.position = position;
+ }
+}
diff --git a/typescript.java-ts.core/src/main/java/ts/client/LoggingInterceptor.java b/typescript.java-ts.core/src/main/java/ts/client/LoggingInterceptor.java
new file mode 100644
index 00000000..bf557e38
--- /dev/null
+++ b/typescript.java-ts.core/src/main/java/ts/client/LoggingInterceptor.java
@@ -0,0 +1,60 @@
+/**
+ * Copyright (c) 2015-2016 Angelo ZERR.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Angelo Zerr - initial API and implementation
+ */
+package ts.client;
+
+import ts.internal.client.protocol.Request;
+import ts.internal.client.protocol.Response;
+
+public class LoggingInterceptor implements IInterceptor {
+
+ private static final IInterceptor INSTANCE = new LoggingInterceptor();
+
+ public static IInterceptor getInstance() {
+ return INSTANCE;
+ }
+
+ @Override
+ public void handleRequest(Request> request, String json, ITypeScriptServiceClient client) {
+ outPrintln("-----------------------------------");
+ outPrintln("TypeScript request#" + request.getCommand() + ": ");
+ outPrintln(json);
+ }
+
+ @Override
+ public void handleResponse(Response> response, String json, long ellapsedTime,
+ TypeScriptServiceClient typeScriptServiceClient) {
+ outPrintln("");
+ outPrintln("TypeScript response#" + response.getCommand() + " with " + ellapsedTime + "ms: ");
+ outPrintln(json);
+ outPrintln("-----------------------------------");
+ }
+
+ @Override
+ public void handleError(Throwable error, ITypeScriptServiceClient server, String methodName, long ellapsedTime) {
+ errPrintln("");
+ errPrintln("TypeScript error#" + methodName + " with " + ellapsedTime + "ms: ");
+ printStackTrace(error);
+ errPrintln("-----------------------------------");
+ }
+
+ protected void outPrintln(String line) {
+ System.out.println(line);
+ }
+
+ protected void errPrintln(String line) {
+ System.err.println(line);
+ }
+
+ protected void printStackTrace(Throwable error) {
+ error.printStackTrace(System.err);
+ }
+
+}
diff --git a/typescript.java-ts.core/src/main/java/ts/client/ScriptKindName.java b/typescript.java-ts.core/src/main/java/ts/client/ScriptKindName.java
new file mode 100644
index 00000000..12999be0
--- /dev/null
+++ b/typescript.java-ts.core/src/main/java/ts/client/ScriptKindName.java
@@ -0,0 +1,6 @@
+package ts.client;
+
+public enum ScriptKindName {
+
+ TS ,JS ,TSX ,JSX
+}
diff --git a/typescript.java-ts.core/src/main/java/ts/client/TextSpan.java b/typescript.java-ts.core/src/main/java/ts/client/TextSpan.java
new file mode 100644
index 00000000..038d481f
--- /dev/null
+++ b/typescript.java-ts.core/src/main/java/ts/client/TextSpan.java
@@ -0,0 +1,51 @@
+/**
+ * Copyright (c) 2015-2017 Angelo ZERR.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Angelo Zerr - initial API and implementation
+ */
+package ts.client;
+
+import ts.TypeScriptException;
+
+/**
+ * Object found in response messages defining a span of text in source code.
+ *
+ * @see https://github.com/Microsoft/TypeScript/blob/master/src/server/protocol.ts
+ *
+ */
+public class TextSpan {
+
+ /**
+ * First character of the definition.
+ */
+ private Location start;
+
+ /**
+ * One character past last character of the definition.
+ */
+ private Location end;
+
+ public Location getStart() {
+ return start;
+ }
+
+ public Location getEnd() {
+ return end;
+ }
+
+ public boolean contains(int position) throws TypeScriptException {
+ int positionStart = start.getPosition();
+ return positionStart <= position && position < (positionStart + getLength());
+ }
+
+ public int getLength() throws TypeScriptException {
+ int positionStart = start.getPosition();
+ int positionEnd = end.getPosition();
+ return positionEnd - positionStart;
+ }
+}
diff --git a/typescript.java-ts.core/src/main/java/ts/client/TypeScriptServerAdapter.java b/typescript.java-ts.core/src/main/java/ts/client/TypeScriptServerAdapter.java
new file mode 100644
index 00000000..eb765463
--- /dev/null
+++ b/typescript.java-ts.core/src/main/java/ts/client/TypeScriptServerAdapter.java
@@ -0,0 +1,33 @@
+/**
+ * Copyright (c) 2015-2016 Angelo ZERR.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Angelo Zerr - initial API and implementation
+ */
+package ts.client;
+
+/**
+ * This adapter class provides default implementations for the methods described
+ * by the {@link ITypeScriptClientListener} interface.
+ *
+ * Classes that wish to deal with event can extend this class and override only
+ * the methods which they are interested in.
+ *
+ */
+public class TypeScriptServerAdapter implements ITypeScriptClientListener {
+
+ @Override
+ public void onStart(ITypeScriptServiceClient server) {
+
+ }
+
+ @Override
+ public void onStop(ITypeScriptServiceClient server) {
+
+ }
+
+}
diff --git a/typescript.java-ts.core/src/main/java/ts/client/TypeScriptServiceClient.java b/typescript.java-ts.core/src/main/java/ts/client/TypeScriptServiceClient.java
new file mode 100644
index 00000000..28bc9b4d
--- /dev/null
+++ b/typescript.java-ts.core/src/main/java/ts/client/TypeScriptServiceClient.java
@@ -0,0 +1,934 @@
+/**
+ * Copyright (c) 2015-2017 Angelo ZERR.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Angelo Zerr - initial API and implementation
+ */
+package ts.client;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.locks.ReentrantReadWriteLock;
+import java.util.function.Consumer;
+
+import com.google.gson.JsonElement;
+import com.google.gson.JsonObject;
+
+import ts.TypeScriptException;
+import ts.TypeScriptNoContentAvailableException;
+import ts.client.codefixes.CodeAction;
+import ts.client.compileonsave.CompileOnSaveAffectedFileListSingleProject;
+import ts.client.completions.CompletionEntry;
+import ts.client.completions.CompletionEntryDetails;
+import ts.client.completions.ICompletionEntryFactory;
+import ts.client.completions.ICompletionEntryMatcherProvider;
+import ts.client.configure.ConfigureRequestArguments;
+import ts.client.diagnostics.DiagnosticEvent;
+import ts.client.diagnostics.DiagnosticEventBody;
+import ts.client.diagnostics.IDiagnostic;
+import ts.client.installtypes.BeginInstallTypesEventBody;
+import ts.client.installtypes.EndInstallTypesEventBody;
+import ts.client.installtypes.IInstallTypesListener;
+import ts.client.jsdoc.TextInsertion;
+import ts.client.navbar.NavigationBarItem;
+import ts.client.navto.NavtoItem;
+import ts.client.occurrences.OccurrencesResponseItem;
+import ts.client.projectinfo.ProjectInfo;
+import ts.client.quickinfo.QuickInfo;
+import ts.client.refactors.ApplicableRefactorInfo;
+import ts.client.refactors.RefactorEditInfo;
+import ts.client.references.ReferencesResponseBody;
+import ts.client.rename.RenameResponseBody;
+import ts.client.signaturehelp.SignatureHelpItems;
+import ts.cmd.tsc.CompilerOptions;
+import ts.internal.FileTempHelper;
+import ts.internal.SequenceHelper;
+import ts.internal.client.protocol.ChangeRequest;
+import ts.internal.client.protocol.CloseExternalProjectRequest;
+import ts.internal.client.protocol.CloseRequest;
+import ts.internal.client.protocol.CodeFixRequest;
+import ts.internal.client.protocol.CompileOnSaveAffectedFileListRequest;
+import ts.internal.client.protocol.CompileOnSaveEmitFileRequest;
+import ts.internal.client.protocol.CompletionDetailsRequest;
+import ts.internal.client.protocol.CompletionsRequest;
+import ts.internal.client.protocol.ConfigureRequest;
+import ts.internal.client.protocol.DefinitionRequest;
+import ts.internal.client.protocol.DocCommentTemplateRequest;
+import ts.internal.client.protocol.FormatRequest;
+import ts.internal.client.protocol.GetApplicableRefactorsRequest;
+import ts.internal.client.protocol.GetEditsForRefactorRequest;
+import ts.internal.client.protocol.GetSupportedCodeFixesRequest;
+import ts.internal.client.protocol.GeterrForProjectRequest;
+import ts.internal.client.protocol.GeterrRequest;
+import ts.internal.client.protocol.GsonHelper;
+import ts.internal.client.protocol.IRequestEventable;
+import ts.internal.client.protocol.ImplementationRequest;
+import ts.internal.client.protocol.MessageType;
+import ts.internal.client.protocol.NavBarRequest;
+import ts.internal.client.protocol.NavToRequest;
+import ts.internal.client.protocol.NavTreeRequest;
+import ts.internal.client.protocol.OccurrencesRequest;
+import ts.internal.client.protocol.OpenExternalProjectRequest;
+import ts.internal.client.protocol.OpenRequest;
+import ts.internal.client.protocol.ProjectInfoRequest;
+import ts.internal.client.protocol.QuickInfoRequest;
+import ts.internal.client.protocol.ReferencesRequest;
+import ts.internal.client.protocol.ReloadRequest;
+import ts.internal.client.protocol.RenameRequest;
+import ts.internal.client.protocol.Request;
+import ts.internal.client.protocol.Response;
+import ts.internal.client.protocol.SemanticDiagnosticsSyncRequest;
+import ts.internal.client.protocol.SignatureHelpRequest;
+import ts.internal.client.protocol.SyntacticDiagnosticsSyncRequest;
+import ts.nodejs.INodejsLaunchConfiguration;
+import ts.nodejs.INodejsProcess;
+import ts.nodejs.INodejsProcessListener;
+import ts.nodejs.NodejsProcess;
+import ts.nodejs.NodejsProcessAdapter;
+import ts.nodejs.NodejsProcessManager;
+import ts.repository.TypeScriptRepositoryManager;
+import ts.utils.FileUtils;
+
+/**
+ * TypeScript service client implementation.
+ *
+ */
+public class TypeScriptServiceClient implements ITypeScriptServiceClient {
+
+ private static final String NO_CONTENT_AVAILABLE = "No content available.";
+ private static final String TSSERVER_FILE_TYPE = "tsserver";
+
+ private INodejsProcess process;
+ private List nodeListeners;
+ private final List listeners;
+ private final List installTypesListener;
+ private final ReentrantReadWriteLock stateLock;
+ private boolean dispose;
+
+ private final Map sentRequestMap;
+ private final Map receivedRequestMap;
+ private List interceptors;
+
+ private ICompletionEntryMatcherProvider completionEntryMatcherProvider;
+
+ private final INodejsProcessListener listener = new NodejsProcessAdapter() {
+
+ @Override
+ public void onStart(INodejsProcess process) {
+ TypeScriptServiceClient.this.fireStartServer();
+ }
+
+ @Override
+ public void onStop(INodejsProcess process) {
+ dispose();
+ fireEndServer();
+ }
+
+ public void onMessage(INodejsProcess process, String message) {
+ if (message.startsWith("{")) {
+ TypeScriptServiceClient.this.dispatchMessage(message);
+ }
+ };
+
+ };
+ private String cancellationPipeName;
+
+ private static class PendingRequestInfo {
+ Request> requestMessage;
+ Consumer> responseHandler;
+ long startTime;
+
+ PendingRequestInfo(Request> requestMessage, Consumer> responseHandler) {
+ this.requestMessage = requestMessage;
+ this.responseHandler = responseHandler;
+ this.startTime = System.nanoTime();
+ }
+ }
+
+ private static class PendingRequestEventInfo {
+ Request> requestMessage;
+ Consumer> eventHandler;
+ long startTime;
+
+ PendingRequestEventInfo(Request> requestMessage, Consumer> eventHandler) {
+ this.requestMessage = requestMessage;
+ this.eventHandler = eventHandler;
+ this.startTime = System.nanoTime();
+ }
+ }
+
+ public TypeScriptServiceClient(final File projectDir, File tsserverFile, File nodeFile) throws TypeScriptException {
+ this(projectDir, tsserverFile, nodeFile, false, false, null, null, null);
+ }
+
+ public TypeScriptServiceClient(final File projectDir, File typescriptDir, File nodeFile, boolean enableTelemetry,
+ boolean disableAutomaticTypingAcquisition, String cancellationPipeName, File tsserverPluginsFile,
+ TypeScriptServiceLogConfiguration logConfiguration) throws TypeScriptException {
+ this(NodejsProcessManager.getInstance().create(projectDir,
+ tsserverPluginsFile != null ? tsserverPluginsFile
+ : TypeScriptRepositoryManager.getTsserverFile(typescriptDir),
+ nodeFile, new INodejsLaunchConfiguration() {
+
+ @Override
+ public List createNodeArgs() {
+ List args = new ArrayList();
+ // args.add("-p");
+ // args.add(FileUtils.getPath(projectDir));
+ if (enableTelemetry) {
+ args.add("--enableTelemetry");
+ }
+ if (disableAutomaticTypingAcquisition) {
+ args.add("--disableAutomaticTypingAcquisition");
+ }
+ if (tsserverPluginsFile != null) {
+ args.add("--typescriptDir");
+ args.add(FileUtils.getPath(typescriptDir));
+ }
+ if (cancellationPipeName != null) {
+ args.add("--cancellationPipeName");
+ args.add(cancellationPipeName + "*");
+ }
+ // args.add("--useSingleInferredProject");
+ return args;
+ }
+
+ @Override
+ public Map createNodeEnvironmentVariables() {
+ Map environmentVariables = new HashMap<>();
+ if (logConfiguration != null) {
+ environmentVariables.put("TSS_LOG",
+ "-level " + logConfiguration.level.name() + " -file " + logConfiguration.file);
+ }
+ return environmentVariables;
+ }
+ }, TSSERVER_FILE_TYPE), cancellationPipeName);
+ }
+
+ public TypeScriptServiceClient(INodejsProcess process, String cancellationPipeName) {
+ this.listeners = new ArrayList<>();
+ this.installTypesListener = new ArrayList<>();
+ this.stateLock = new ReentrantReadWriteLock();
+ this.dispose = false;
+ this.sentRequestMap = new LinkedHashMap<>();
+ this.receivedRequestMap = new LinkedHashMap<>();
+ this.process = process;
+ process.addProcessListener(listener);
+ setCompletionEntryMatcherProvider(ICompletionEntryMatcherProvider.LCS_PROVIDER);
+ this.cancellationPipeName = cancellationPipeName;
+ }
+
+ public static enum TypeScriptServiceLogLevel {
+ verbose, normal, terse, requestTime
+ }
+
+ public static class TypeScriptServiceLogConfiguration {
+ String file;
+ TypeScriptServiceLogLevel level;
+
+ public TypeScriptServiceLogConfiguration(String file, TypeScriptServiceLogLevel level) {
+ this.file = file;
+ this.level = level;
+ }
+ }
+
+ private void dispatchMessage(String message) {
+ JsonObject json = GsonHelper.parse(message).getAsJsonObject();
+ JsonElement typeElement = json.get("type");
+ if (typeElement != null) {
+ MessageType messageType = MessageType.getType(typeElement.getAsString());
+ if (messageType == null) {
+ throw new IllegalStateException("Unknown response type message " + json);
+ }
+ switch (messageType) {
+ case response:
+ int seq = json.get("request_seq").getAsInt();
+ PendingRequestInfo pendingRequestInfo;
+ synchronized (sentRequestMap) {
+ pendingRequestInfo = sentRequestMap.remove(seq);
+ }
+ if (pendingRequestInfo == null) {
+ // throw new IllegalStateException("Unmatched response
+ // message " + json);
+ return;
+ }
+ Response responseMessage = pendingRequestInfo.requestMessage.parseResponse(json);
+ try {
+ handleResponse(responseMessage, message, pendingRequestInfo.startTime);
+ pendingRequestInfo.responseHandler.accept(responseMessage);
+ } catch (RuntimeException e) {
+ // LOG.log(Level.WARNING, "Handling repsonse
+ // "+responseMessage+" threw an exception.", e);
+ }
+
+ break;
+ case event:
+ String event = json.get("event").getAsString();
+ if ("syntaxDiag".equals(event) || "semanticDiag".equals(event)) {
+ DiagnosticEvent response = GsonHelper.DEFAULT_GSON.fromJson(json, DiagnosticEvent.class);
+ PendingRequestEventInfo pendingRequestEventInfo;
+ synchronized (receivedRequestMap) {
+ pendingRequestEventInfo = receivedRequestMap.remove(response.getKey());
+ }
+ if (pendingRequestEventInfo != null) {
+ pendingRequestEventInfo.eventHandler.accept(response);
+ }
+ } else if ("telemetry".equals(event)) {
+ // TelemetryEventBody telemetryData =
+ // GsonHelper.DEFAULT_GSON.fromJson(json,
+ // TelemetryEvent.class)
+ // .getBody();
+ //
+ JsonObject telemetryData = json.get("body").getAsJsonObject();
+ JsonObject payload = telemetryData.has("payload") ? telemetryData.get("payload").getAsJsonObject()
+ : null;
+ if (payload != null) {
+ String telemetryEventName = telemetryData.get("telemetryEventName").getAsString();
+ fireLogTelemetry(telemetryEventName, payload);
+ }
+ } else if ("beginInstallTypes".equals(event)) {
+ BeginInstallTypesEventBody data = GsonHelper.DEFAULT_GSON.fromJson(json,
+ BeginInstallTypesEventBody.class);
+ fireBeginInstallTypes(data);
+ } else if ("endInstallTypes".equals(event)) {
+ EndInstallTypesEventBody data = GsonHelper.DEFAULT_GSON.fromJson(json,
+ EndInstallTypesEventBody.class);
+ fireEndInstallTypes(data);
+ }
+ break;
+ default:
+ // Do nothing
+ }
+ }
+ }
+
+ @Override
+ public void openFile(String fileName, String content) throws TypeScriptException {
+ openFile(fileName, content, null);
+ }
+
+ @Override
+ public void openFile(String fileName, String content, ScriptKindName scriptKindName) throws TypeScriptException {
+ execute(new OpenRequest(fileName, null, content, scriptKindName), false);
+ }
+
+ @Override
+ public void openExternalProject(String projectFileName, List rootFiles, CompilerOptions options)
+ throws TypeScriptException {
+ execute(new OpenExternalProjectRequest(projectFileName, rootFiles, options), false);
+ }
+
+ @Override
+ public void closeExternalProject(String projectFileName) throws TypeScriptException {
+ execute(new CloseExternalProjectRequest(projectFileName), false);
+ }
+
+ @Override
+ public void closeFile(String fileName) throws TypeScriptException {
+ execute(new CloseRequest(fileName), false);
+ }
+
+ @Override
+ public void changeFile(String fileName, int line, int offset, int endLine, int endOffset, String insertString)
+ throws TypeScriptException {
+ execute(new ChangeRequest(fileName, line, offset, endLine, endOffset, insertString), false);
+ }
+
+ /**
+ * Write the buffer of editor content to a temporary file and have the server
+ * reload it
+ *
+ * @param fileName
+ * @param newText
+ */
+ @Override
+ public void updateFile(String fileName, String newText) throws TypeScriptException {
+ updateFile(fileName, newText,10,TimeUnit.SECONDS);
+ }
+ /**
+ * Write the buffer of editor content to a temporary file and have the server
+ * reload it
+ *
+ * @param fileName
+ * @param newText
+ * @param timeout
+ * @param timeoutUnit
+ */
+ @Override
+ public void updateFile(String fileName, String newText, long timeout, TimeUnit timeoutUnit) throws TypeScriptException {
+ int seq = SequenceHelper.getRequestSeq();
+ String tempFileName = null;
+ if (newText != null) {
+ tempFileName = FileTempHelper.updateTempFile(newText, seq);
+ }
+ try {
+ execute(new ReloadRequest(fileName, tempFileName, seq), true).get(timeout, timeoutUnit);
+ } catch (Exception e) {
+ if (e instanceof TypeScriptException) {
+ throw (TypeScriptException) e;
+ }
+ throw new TypeScriptException(e);
+ }
+ }
+
+ @Override
+ public CompletableFuture> completions(String fileName, int line, int offset)
+ throws TypeScriptException {
+ return completions(fileName, line, offset, ICompletionEntryFactory.DEFAULT);
+ }
+
+ @Override
+ public CompletableFuture> completions(String fileName, int line, int offset,
+ ICompletionEntryFactory factory) throws TypeScriptException {
+ return execute(
+ new CompletionsRequest(fileName, line, offset, getCompletionEntryMatcherProvider(), this, factory),
+ true);
+ }
+
+ @Override
+ public CompletableFuture> completionEntryDetails(String fileName, int line, int offset,
+ String[] entryNames, CompletionEntry completionEntry) throws TypeScriptException {
+ return execute(new CompletionDetailsRequest(fileName, line, offset, null, entryNames), true);
+ }
+
+ @Override
+ public CompletableFuture> definition(String fileName, int line, int offset)
+ throws TypeScriptException {
+ return execute(new DefinitionRequest(fileName, line, offset), true);
+ }
+
+ @Override
+ public CompletableFuture signatureHelp(String fileName, int line, int offset)
+ throws TypeScriptException {
+ return execute(new SignatureHelpRequest(fileName, line, offset), true);
+ }
+
+ @Override
+ public CompletableFuture quickInfo(String fileName, int line, int offset) throws TypeScriptException {
+ return execute(new QuickInfoRequest(fileName, line, offset), true);
+ }
+
+ @Override
+ public CompletableFuture> geterr(String[] files, int delay) throws TypeScriptException {
+ return execute(new GeterrRequest(files, delay), true);
+ }
+
+ @Override
+ public CompletableFuture> geterrForProject(String file, int delay, ProjectInfo projectInfo)
+ throws TypeScriptException {
+ return execute(new GeterrForProjectRequest(file, delay, projectInfo), true);
+ }
+
+ @Override
+ public CompletableFuture> format(String fileName, int line, int offset, int endLine, int endOffset)
+ throws TypeScriptException {
+ return execute(new FormatRequest(fileName, line, offset, endLine, endOffset), true);
+ }
+
+ @Override
+ public CompletableFuture references(String fileName, int line, int offset)
+ throws TypeScriptException {
+ return execute(new ReferencesRequest(fileName, line, offset), true);
+ }
+
+ @Override
+ public CompletableFuture> occurrences(String fileName, int line, int offset)
+ throws TypeScriptException {
+ return execute(new OccurrencesRequest(fileName, line, offset), true);
+ }
+
+ @Override
+ public CompletableFuture rename(String file, int line, int offset, Boolean findInComments,
+ Boolean findInStrings) throws TypeScriptException {
+ return execute(new RenameRequest(file, line, offset, findInComments, findInStrings), true);
+ }
+
+ @Override
+ public CompletableFuture> navto(String fileName, String searchValue, Integer maxResultCount,
+ Boolean currentFileOnly, String projectFileName) throws TypeScriptException {
+ return execute(new NavToRequest(fileName, searchValue, maxResultCount, currentFileOnly, projectFileName), true);
+ }
+
+ @Override
+ public CompletableFuture> navbar(String fileName, IPositionProvider positionProvider)
+ throws TypeScriptException {
+ return execute(new NavBarRequest(fileName, positionProvider), true);
+ }
+
+ @Override
+ public void configure(ConfigureRequestArguments arguments) throws TypeScriptException {
+ execute(new ConfigureRequest(arguments), true);
+ }
+
+ @Override
+ public CompletableFuture projectInfo(String file, String projectFileName, boolean needFileNameList)
+ throws TypeScriptException {
+ return execute(new ProjectInfoRequest(file, needFileNameList), true);
+ }
+
+ // Since 2.0.3
+
+ @Override
+ public CompletableFuture semanticDiagnosticsSync(String file, Boolean includeLinePosition)
+ throws TypeScriptException {
+ return execute(new SemanticDiagnosticsSyncRequest(file, includeLinePosition), true).thenApply(d -> {
+ return new DiagnosticEventBody(file, (List) d);
+ });
+ }
+
+ @Override
+ public CompletableFuture syntacticDiagnosticsSync(String file, Boolean includeLinePosition)
+ throws TypeScriptException {
+ return execute(new SyntacticDiagnosticsSyncRequest(file, includeLinePosition), true).thenApply(d -> {
+ return new DiagnosticEventBody(file, (List) d);
+ });
+ }
+
+ // Since 2.0.5
+
+ @Override
+ public CompletableFuture compileOnSaveEmitFile(String fileName, Boolean forced)
+ throws TypeScriptException {
+ return execute(new CompileOnSaveEmitFileRequest(fileName, forced), true);
+ }
+
+ @Override
+ public CompletableFuture> compileOnSaveAffectedFileList(
+ String fileName) throws TypeScriptException {
+ return execute(new CompileOnSaveAffectedFileListRequest(fileName), true);
+ }
+
+ // Since 2.0.6
+
+ @Override
+ public CompletableFuture navtree(String fileName, IPositionProvider positionProvider)
+ throws TypeScriptException {
+ return execute(new NavTreeRequest(fileName, positionProvider), true);
+ }
+
+ @Override
+ public CompletableFuture docCommentTemplate(String fileName, int line, int offset)
+ throws TypeScriptException {
+ return execute(new DocCommentTemplateRequest(fileName, line, offset), true);
+ }
+
+ // Since 2.1.0
+
+ @Override
+ public CompletableFuture> getCodeFixes(String fileName, IPositionProvider positionProvider,
+ int startLine, int startOffset, int endLine, int endOffset, List errorCodes)
+ throws TypeScriptException {
+ return execute(new CodeFixRequest(fileName, startLine, startOffset, endLine, endOffset, errorCodes), true);
+ }
+
+ @Override
+ public CompletableFuture> getSupportedCodeFixes() throws TypeScriptException {
+ return execute(new GetSupportedCodeFixesRequest(), true);
+ }
+
+ @Override
+ public CompletableFuture> implementation(String fileName, int line, int offset)
+ throws TypeScriptException {
+ return execute(new ImplementationRequest(fileName, line, offset), true);
+ }
+
+ // Since 2.4.0
+
+ @Override
+ public CompletableFuture> getApplicableRefactors(String fileName, int line, int offset)
+ throws TypeScriptException {
+ return execute(new GetApplicableRefactorsRequest(fileName, line, offset), true);
+ }
+
+ @Override
+ public CompletableFuture> getApplicableRefactors(String fileName, int startLine,
+ int startOffset, int endLine, int endOffset) throws TypeScriptException {
+ return execute(new GetApplicableRefactorsRequest(fileName, startLine, startOffset, endLine, endOffset), true);
+ }
+
+ @Override
+ public CompletableFuture getEditsForRefactor(String fileName, int line, int offset,
+ String refactor, String action) throws TypeScriptException {
+ return execute(new GetEditsForRefactorRequest(fileName, line, offset, refactor, action), true);
+ }
+
+ @Override
+ public CompletableFuture getEditsForRefactor(String fileName, int startLine, int startOffset,
+ int endLine, int endOffset, String refactor, String action) throws TypeScriptException {
+ return execute(
+ new GetEditsForRefactorRequest(fileName, startLine, startOffset, endLine, endOffset, refactor, action),
+ true);
+ }
+
+ private CompletableFuture execute(Request> request, boolean expectsResult) throws TypeScriptException {
+ if (!expectsResult) {
+ sendRequest(request);
+ return null;
+ }
+ final CompletableFuture result = new CompletableFuture() {
+
+ @Override
+ public boolean cancel(boolean mayInterruptIfRunning) {
+ tryCancelRequest(request);
+ return super.cancel(mayInterruptIfRunning);
+ }
+
+ /**
+ * Try to cancel the given request:
+ *
+ *
+ * - on client side : remove request from the received request queue.
+ * - on server side (tsserver) : cancel the request.
+ *
+ *
+ * @param request
+ */
+ private void tryCancelRequest(Request> request) {
+ try {
+ cancelServerRequest(request);
+ } finally {
+ cancelClientRequest(request);
+ }
+ }
+
+ private void cancelClientRequest(Request> request) {
+ if (request instanceof IRequestEventable) {
+ List keys = ((IRequestEventable) request).getKeys();
+ synchronized (receivedRequestMap) {
+ for (String key : keys) {
+ receivedRequestMap.remove(key);
+ }
+ }
+ } else {
+ synchronized (sentRequestMap) {
+ sentRequestMap.remove(request.getSeq());
+ }
+ }
+ }
+
+ private void cancelServerRequest(Request> request) {
+ // Generate en empty file in the temp directory (ex:
+ // $TMP_DIR/eclipse-tscancellation-4df2438b-ca7a-4ef3-9a46-83e8afef61b3.sock844
+ // where 844 is request sequence)
+ // for the given request sequence waited by tsserver
+ // typescript/lib/cancellationToken.js.
+ // to cancel request from tsserver.
+ if (cancellationPipeName != null) {
+ File tempFile = new File(TypeScriptServiceClient.this.cancellationPipeName + request.getSeq());
+ try {
+ tempFile.createNewFile();
+ tempFile.deleteOnExit();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ };
+ if (request instanceof IRequestEventable) {
+ Consumer> responseHandler = (event) -> {
+ if (((IRequestEventable) request).accept(event)) {
+ result.complete((T) ((IRequestEventable) request).getEvents());
+ }
+ };
+ List keys = ((IRequestEventable) request).getKeys();
+ PendingRequestEventInfo info = new PendingRequestEventInfo(request, responseHandler);
+ synchronized (receivedRequestMap) {
+ for (String key : keys) {
+ receivedRequestMap.put(key, info);
+ }
+ }
+ } else {
+ Consumer> responseHandler = (response) -> {
+ if (response.isSuccess()) {
+ // tsserver response with success
+ result.complete((T) response.getBody());
+ } else {
+ // tsserver response with error
+ result.completeExceptionally(createException(response.getMessage()));
+ }
+ };
+ int seq = request.getSeq();
+ synchronized (sentRequestMap) {
+ sentRequestMap.put(seq, new PendingRequestInfo(request, responseHandler));
+ }
+ }
+ sendRequest(request);
+ return result;
+ }
+
+ private TypeScriptException createException(String message) {
+ if (NO_CONTENT_AVAILABLE.equals(message)) {
+ return new TypeScriptNoContentAvailableException(message);
+ }
+ return new TypeScriptException(message);
+ }
+
+ private void sendRequest(Request> request) throws TypeScriptException {
+ String req = GsonHelper.DEFAULT_GSON.toJson(request);
+ handleRequest(request, req);
+ getProcess().sendRequest(req);
+ }
+
+ private INodejsProcess getProcess() throws TypeScriptException {
+ if (process == null) {
+ throw new RuntimeException("unexpected error: process was stopped/killed before trying to use it again");
+ }
+
+ if (!process.isStarted()) {
+ process.start();
+ }
+ return process;
+ }
+
+ @Override
+ public void addClientListener(ITypeScriptClientListener listener) {
+ synchronized (listeners) {
+ listeners.add(listener);
+ }
+ }
+
+ @Override
+ public void removeClientListener(ITypeScriptClientListener listener) {
+ synchronized (listeners) {
+ listeners.remove(listener);
+ }
+ }
+
+ private void fireStartServer() {
+ synchronized (listeners) {
+ for (ITypeScriptClientListener listener : listeners) {
+ listener.onStart(this);
+ }
+ }
+ }
+
+ private void fireEndServer() {
+ synchronized (listeners) {
+ for (ITypeScriptClientListener listener : listeners) {
+ listener.onStop(this);
+ }
+ }
+ }
+
+ @Override
+ public void addInstallTypesListener(IInstallTypesListener listener) {
+ synchronized (installTypesListener) {
+ installTypesListener.add(listener);
+ }
+ }
+
+ @Override
+ public void removeInstallTypesListener(IInstallTypesListener listener) {
+ synchronized (installTypesListener) {
+ installTypesListener.remove(listener);
+ }
+ }
+
+ private void fireBeginInstallTypes(BeginInstallTypesEventBody body) {
+ synchronized (installTypesListener) {
+ for (IInstallTypesListener listener : installTypesListener) {
+ listener.onBegin(body);
+ }
+ }
+ }
+
+ private void fireEndInstallTypes(EndInstallTypesEventBody body) {
+ synchronized (installTypesListener) {
+ for (IInstallTypesListener listener : installTypesListener) {
+ listener.onEnd(body);
+ }
+ }
+ }
+
+ private void fireLogTelemetry(String telemetryEventName, JsonObject payload) {
+ synchronized (installTypesListener) {
+ for (IInstallTypesListener listener : installTypesListener) {
+ listener.logTelemetry(telemetryEventName, payload);
+ }
+ }
+ }
+
+ @Override
+ public void addInterceptor(IInterceptor interceptor) {
+ beginWriteState();
+ try {
+ if (interceptors == null) {
+ interceptors = new ArrayList();
+ }
+ interceptors.add(interceptor);
+ } finally {
+ endWriteState();
+ }
+ }
+
+ @Override
+ public void removeInterceptor(IInterceptor interceptor) {
+ beginWriteState();
+ try {
+ if (interceptors != null) {
+ interceptors.remove(interceptor);
+ }
+ } finally {
+ endWriteState();
+ }
+ }
+
+ public void addProcessListener(INodejsProcessListener listener) {
+ beginWriteState();
+ try {
+ if (nodeListeners == null) {
+ nodeListeners = new ArrayList();
+ }
+ nodeListeners.add(listener);
+ if (process != null) {
+ process.addProcessListener(listener);
+ }
+ } finally {
+ endWriteState();
+ }
+ }
+
+ public void removeProcessListener(INodejsProcessListener listener) {
+ beginWriteState();
+ try {
+ if (nodeListeners != null && listener != null) {
+ nodeListeners.remove(listener);
+ }
+ if (process != null) {
+ process.removeProcessListener(listener);
+ }
+ } finally {
+ endWriteState();
+ }
+ }
+
+ @Override
+ public void join() throws InterruptedException {
+ if (process != null) {
+ this.process.join();
+ }
+ }
+
+ @Override
+ public boolean isDisposed() {
+ return dispose;
+ }
+
+ @Override
+ public final void dispose() {
+ beginWriteState();
+ try {
+ if (!isDisposed()) {
+ this.dispose = true;
+ System.out.println("dispose client - process=" + process);
+ if (NodejsProcess.logProcessStopStack) {
+ Thread.dumpStack();
+ }
+ if (process != null) {
+ process.kill();
+ }
+ this.process = null;
+ }
+ } finally {
+ endWriteState();
+ }
+ }
+
+ private void beginReadState() {
+ stateLock.readLock().lock();
+ }
+
+ private void endReadState() {
+ stateLock.readLock().unlock();
+ }
+
+ private void beginWriteState() {
+ stateLock.writeLock().lock();
+ }
+
+ private void endWriteState() {
+ stateLock.writeLock().unlock();
+ }
+
+ public void setCompletionEntryMatcherProvider(ICompletionEntryMatcherProvider completionEntryMatcherProvider) {
+ this.completionEntryMatcherProvider = completionEntryMatcherProvider;
+ }
+
+ public ICompletionEntryMatcherProvider getCompletionEntryMatcherProvider() {
+ return completionEntryMatcherProvider;
+ }
+
+ // --------------------------- Handler for Request/response/Error
+ // ------------------------------------
+
+ /**
+ * Handle the given request.
+ *
+ * @param request
+ */
+ private void handleRequest(Request> request, String json) {
+ if (interceptors == null) {
+ return;
+ }
+ for (IInterceptor interceptor : interceptors) {
+ interceptor.handleRequest(request, json, this);
+ }
+ }
+
+ /**
+ * Handle the given reponse.
+ *
+ * @param request
+ * @param response
+ * @param startTime
+ */
+ private void handleResponse(Response> response, String json, long startTime) {
+ if (interceptors == null) {
+ return;
+ }
+ long ellapsedTime = getElapsedTimeInMs(startTime);
+ for (IInterceptor interceptor : interceptors) {
+ interceptor.handleResponse(response, json, ellapsedTime, this);
+ }
+ }
+
+ /**
+ * Handle the given error.
+ *
+ * @param request
+ * @param e
+ * @param startTime
+ */
+ private void handleError(String command, Throwable e, long startTime) {
+ if (interceptors == null) {
+ return;
+ }
+ long ellapsedTime = getElapsedTimeInMs(startTime);
+ for (IInterceptor interceptor : interceptors) {
+ interceptor.handleError(e, this, command, ellapsedTime);
+ }
+ }
+
+ /**
+ * Returns the elappsed time in ms.
+ *
+ * @param startTime
+ * in nano time.
+ * @return the elappsed time in ms.
+ */
+ private static long getElapsedTimeInMs(long startTime) {
+ return ((System.nanoTime() - startTime) / 1000000L);
+ }
+
+}
diff --git a/typescript.java-ts.core/src/main/java/ts/client/codefixes/CodeAction.java b/typescript.java-ts.core/src/main/java/ts/client/codefixes/CodeAction.java
new file mode 100644
index 00000000..dca92894
--- /dev/null
+++ b/typescript.java-ts.core/src/main/java/ts/client/codefixes/CodeAction.java
@@ -0,0 +1,29 @@
+/**
+ * Copyright (c) 2015-2016 Angelo ZERR.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Angelo Zerr - initial API and implementation
+ */
+package ts.client.codefixes;
+
+import java.util.List;
+
+public class CodeAction {
+
+ /** Description of the code action to display in the UI of the editor */
+ private String description;
+ /** Text changes to apply to each file as part of the code action */
+ private List changes;
+
+ public String getDescription() {
+ return description;
+ }
+
+ public List getChanges() {
+ return changes;
+ }
+}
diff --git a/typescript.java-ts.core/src/main/java/ts/client/codefixes/FileCodeEdits.java b/typescript.java-ts.core/src/main/java/ts/client/codefixes/FileCodeEdits.java
new file mode 100644
index 00000000..71c7f440
--- /dev/null
+++ b/typescript.java-ts.core/src/main/java/ts/client/codefixes/FileCodeEdits.java
@@ -0,0 +1,29 @@
+/**
+ * Copyright (c) 2015-2016 Angelo ZERR.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Angelo Zerr - initial API and implementation
+ */
+package ts.client.codefixes;
+
+import java.util.List;
+
+import ts.client.CodeEdit;
+
+public class FileCodeEdits {
+
+ private String fileName;
+ private List textChanges;
+
+ public String getFileName() {
+ return fileName;
+ }
+
+ public List getTextChanges() {
+ return textChanges;
+ }
+}
diff --git a/typescript.java-ts.core/src/main/java/ts/client/compileonsave/CompileOnSaveAffectedFileListSingleProject.java b/typescript.java-ts.core/src/main/java/ts/client/compileonsave/CompileOnSaveAffectedFileListSingleProject.java
new file mode 100644
index 00000000..64b39bc0
--- /dev/null
+++ b/typescript.java-ts.core/src/main/java/ts/client/compileonsave/CompileOnSaveAffectedFileListSingleProject.java
@@ -0,0 +1,37 @@
+/**
+ * Copyright (c) 2015-2016 Angelo ZERR.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Angelo Zerr - initial API and implementation
+ */
+package ts.client.compileonsave;
+
+import java.util.List;
+
+/**
+ * Contains a list of files that should be regenerated in a project
+ *
+ */
+public class CompileOnSaveAffectedFileListSingleProject {
+
+ /**
+ * Project name
+ */
+ private String projectFileName;
+ /**
+ * List of files names that should be recompiled
+ */
+ private List fileNames;
+
+ public String getProjectFileName() {
+ return projectFileName;
+ }
+
+ public List getFileNames() {
+ return fileNames;
+ }
+}
diff --git a/typescript.java-ts.core/src/main/java/ts/client/completions/CompletionEntry.java b/typescript.java-ts.core/src/main/java/ts/client/completions/CompletionEntry.java
new file mode 100644
index 00000000..c7eb6023
--- /dev/null
+++ b/typescript.java-ts.core/src/main/java/ts/client/completions/CompletionEntry.java
@@ -0,0 +1,208 @@
+/**
+ * Copyright (c) 2015-2017 Angelo ZERR.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Angelo Zerr - initial API and implementation
+ */
+package ts.client.completions;
+
+import java.util.List;
+import java.util.concurrent.TimeUnit;
+
+import ts.TypeScriptException;
+import ts.ScriptElementKind;
+import ts.client.IKindProvider;
+import ts.client.ITypeScriptServiceClient;
+import ts.client.TextSpan;
+import ts.internal.matcher.LCSS;
+import ts.utils.StringUtils;
+
+/**
+ *
+ * @see https://github.com/Microsoft/TypeScript/blob/master/src/server/protocol.ts
+ *
+ */
+public class CompletionEntry implements IKindProvider {
+
+ // Negative value ensures subsequence matches have a lower relevance than
+ // standard JDT or template proposals
+ private static final int SUBWORDS_RANGE_START = -9000;
+ private static final int minPrefixLengthForTypes = 1;
+
+ /**
+ * The symbol's name.
+ */
+ private String name;
+ /**
+ * The symbol's kind (such as 'className' or 'parameterName').
+ */
+ private String kind;
+ /**
+ * Optional modifiers for the kind (such as 'public').
+ */
+ private String kindModifiers;
+ /**
+ * A string that is used for comparing completion items so that they can be
+ * ordered. This is often the same as the name but may be different in
+ * certain circumstances.
+ */
+ private String sortText;
+ /**
+ * An optional span that indicates the text to be replaced by this
+ * completion item. If present, this span should be used instead of the
+ * default one.
+ */
+ private TextSpan replacementSpan;
+
+ /**
+ * Indicating if commiting this completion entry will require additional
+ * code action to be made to avoid errors. The code action is normally
+ * adding an additional import statement.
+ */
+ private Boolean hasAction;
+
+ private Boolean isFunction;
+
+ private int relevance;
+
+ private final String fileName;
+ private final int line;
+ private final int offset;
+
+ private final transient ICompletionEntryMatcher matcher;
+
+ private final transient ITypeScriptServiceClient client;
+
+ private List entryDetails;
+
+ public CompletionEntry(ICompletionEntryMatcher matcher, String fileName, int line, int offset,
+ ITypeScriptServiceClient client) {
+ this.matcher = matcher;
+ this.fileName = fileName;
+ this.line = line;
+ this.offset = offset;
+ this.client = client;
+ }
+
+ /**
+ * Returns the file name where completion was done.
+ *
+ * @return the file name where completion was done.
+ */
+ public String getFileName() {
+ return fileName;
+ }
+
+ /**
+ * Returns the line number where completion was done.
+ *
+ * @return the line number where completion was done.
+ */
+ public int getLine() {
+ return line;
+ }
+
+ /**
+ * Returns the offset where completion was done.
+ *
+ * @return the offset where completion was done.
+ */
+ public int getOffset() {
+ return offset;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public String getKind() {
+ return kind;
+ }
+
+ public String getKindModifiers() {
+ return kindModifiers;
+ }
+
+ public String getSortText() {
+ return sortText;
+ }
+
+ public TextSpan getReplacementSpan() {
+ return replacementSpan;
+ }
+
+ public boolean isFunction() {
+ if (isFunction == null) {
+ ScriptElementKind tsKind = ScriptElementKind.getKind(getKind());
+ isFunction = (tsKind != null && (ScriptElementKind.CONSTRUCTOR == tsKind || ScriptElementKind.FUNCTION == tsKind
+ || ScriptElementKind.METHOD == tsKind));
+ }
+ return isFunction;
+ }
+
+ public int getRelevance() {
+ return relevance;
+ }
+
+ public boolean updatePrefix(String prefix) {
+ Integer relevanceBoost = null;
+ int[] bestSequence = null;
+ if (StringUtils.isEmpty(prefix)) {
+ relevanceBoost = 0;
+ } else {
+ bestSequence = matcher.bestSubsequence(name, prefix);
+ if ((bestSequence != null && bestSequence.length > 0)) {
+ relevanceBoost = 0;
+ if (name.equals(prefix)) {
+ if (minPrefixLengthForTypes < prefix.length()) {
+ relevanceBoost = 16 * (RelevanceConstants.R_EXACT_NAME + RelevanceConstants.R_CASE);
+ }
+ } else if (name.equalsIgnoreCase(prefix)) {
+ if (minPrefixLengthForTypes < prefix.length()) {
+ relevanceBoost = 16 * RelevanceConstants.R_EXACT_NAME;
+ }
+ } else if (startsWithIgnoreCase(prefix, name)) {
+ // Don't adjust score
+ } else {
+ int score = LCSS.scoreSubsequence(bestSequence);
+ relevanceBoost = SUBWORDS_RANGE_START + score;
+ }
+ }
+ }
+ if (relevanceBoost != null) {
+ relevance = relevanceBoost;
+ return true;
+ }
+ return false;
+ }
+
+ private boolean startsWithIgnoreCase(String prefix, String name) {
+ return prefix.toUpperCase().startsWith(name.toUpperCase());
+ }
+
+ public ICompletionEntryMatcher getMatcher() {
+ return matcher;
+ }
+
+ public List getEntryDetails() throws TypeScriptException {
+ if (entryDetails != null) {
+ return entryDetails;
+ }
+ try {
+ this.entryDetails = client.completionEntryDetails(fileName, line, offset, new String[] { name }, this)
+ .get(5000, TimeUnit.MILLISECONDS);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return this.entryDetails;
+ }
+
+ public boolean hasActions() {
+ return hasAction != null && hasAction;
+ }
+
+}
diff --git a/typescript.java-ts.core/src/main/java/ts/client/completions/CompletionEntryDetails.java b/typescript.java-ts.core/src/main/java/ts/client/completions/CompletionEntryDetails.java
new file mode 100644
index 00000000..6f1863b1
--- /dev/null
+++ b/typescript.java-ts.core/src/main/java/ts/client/completions/CompletionEntryDetails.java
@@ -0,0 +1,81 @@
+/**
+ * Copyright (c) 2015-2017 Angelo ZERR.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Angelo Zerr - initial API and implementation
+ */
+package ts.client.completions;
+
+import java.util.List;
+
+import ts.client.codefixes.CodeAction;
+
+/**
+ * Additional completion entry details, available on demand
+ */
+public class CompletionEntryDetails {
+
+ /**
+ * The symbol's name.
+ */
+ String name;
+ /**
+ * The symbol's kind (such as 'className' or 'parameterName').
+ */
+ String kind;
+ /**
+ * Optional modifiers for the kind (such as 'public').
+ */
+ String kindModifiers;
+ /**
+ * Display parts of the symbol (similar to quick info).
+ */
+ List displayParts;
+
+ /**
+ * Documentation strings for the symbol.
+ */
+ List documentation;
+
+ /**
+ * JSDoc tags for the symbol.
+ */
+ List tags;
+
+ /**
+ * The associated code actions for this entry
+ */
+ List codeActions;
+
+ public String getName() {
+ return name;
+ }
+
+ public String getKind() {
+ return kind;
+ }
+
+ public String getKindModifiers() {
+ return kindModifiers;
+ }
+
+ public List getDisplayParts() {
+ return displayParts;
+ }
+
+ public List getDocumentation() {
+ return documentation;
+ }
+
+ public List getTags() {
+ return tags;
+ }
+
+ public List getCodeActions() {
+ return codeActions;
+ }
+}
diff --git a/typescript.java-ts.core/src/main/java/ts/client/completions/ICompletionEntryFactory.java b/typescript.java-ts.core/src/main/java/ts/client/completions/ICompletionEntryFactory.java
new file mode 100644
index 00000000..639cf824
--- /dev/null
+++ b/typescript.java-ts.core/src/main/java/ts/client/completions/ICompletionEntryFactory.java
@@ -0,0 +1,46 @@
+/**
+ * Copyright (c) 2015-2017 Angelo ZERR.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Angelo Zerr - initial API and implementation
+ */
+package ts.client.completions;
+
+import ts.client.ITypeScriptServiceClient;
+
+/**
+ * TypeScript {@link CompletionEntry} factory.
+ *
+ */
+public interface ICompletionEntryFactory {
+
+ /**
+ * Default factory.
+ */
+ public static final ICompletionEntryFactory DEFAULT = new ICompletionEntryFactory() {
+
+ @Override
+ public CompletionEntry create(ICompletionEntryMatcher matcher, String fileName, int line, int offset,
+ ITypeScriptServiceClient client) {
+ return new CompletionEntry(matcher, fileName, line, offset, client);
+ }
+ };
+
+ /**
+ * Create {@link CompletionEntry} instance.
+ *
+ * @param matcher
+ * @param fileName
+ * @param line
+ * @param offset
+ * @param client
+ * @return
+ */
+ public CompletionEntry create(ICompletionEntryMatcher matcher, String fileName, int line, int offset,
+ ITypeScriptServiceClient client);
+
+}
diff --git a/typescript.java-ts.core/src/main/java/ts/client/completions/ICompletionEntryMatcher.java b/typescript.java-ts.core/src/main/java/ts/client/completions/ICompletionEntryMatcher.java
new file mode 100644
index 00000000..7f147d4d
--- /dev/null
+++ b/typescript.java-ts.core/src/main/java/ts/client/completions/ICompletionEntryMatcher.java
@@ -0,0 +1,43 @@
+/**
+ * Copyright (c) 2015-2016 Angelo ZERR.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Angelo Zerr - initial API and implementation
+ */
+package ts.client.completions;
+
+import ts.internal.matcher.LCSS;
+
+/**
+ * Matcher for completion entry.
+ *
+ */
+public interface ICompletionEntryMatcher {
+
+ public static ICompletionEntryMatcher LCS = new ICompletionEntryMatcher() {
+
+ @Override
+ public int[] bestSubsequence(String completion, String token) {
+ return LCSS.bestSubsequence(completion, token);
+ }
+
+ };
+
+ public static ICompletionEntryMatcher START_WITH_MATCHER = new ICompletionEntryMatcher() {
+
+ @Override
+ public int[] bestSubsequence(String completion, String token) {
+ if (!completion.startsWith(token)) {
+ return null;
+ }
+ return new int[] { 0, token.length() - 1 };
+ }
+ };
+
+ int[] bestSubsequence(String completion, String token);
+
+}
diff --git a/typescript.java-ts.core/src/main/java/ts/client/completions/ICompletionEntryMatcherProvider.java b/typescript.java-ts.core/src/main/java/ts/client/completions/ICompletionEntryMatcherProvider.java
new file mode 100644
index 00000000..c20a3d37
--- /dev/null
+++ b/typescript.java-ts.core/src/main/java/ts/client/completions/ICompletionEntryMatcherProvider.java
@@ -0,0 +1,20 @@
+package ts.client.completions;
+
+public interface ICompletionEntryMatcherProvider {
+
+ public static ICompletionEntryMatcherProvider LCS_PROVIDER = new ICompletionEntryMatcherProvider() {
+ @Override
+ public ICompletionEntryMatcher getMatcher() {
+ return ICompletionEntryMatcher.LCS;
+ }
+ };
+
+ public static ICompletionEntryMatcherProvider START_WITH_MATCHER_PROVIDER = new ICompletionEntryMatcherProvider() {
+ @Override
+ public ICompletionEntryMatcher getMatcher() {
+ return ICompletionEntryMatcher.START_WITH_MATCHER;
+ }
+ };
+
+ ICompletionEntryMatcher getMatcher();
+}
diff --git a/typescript.java-ts.core/src/main/java/ts/client/completions/JSDocTagInfo.java b/typescript.java-ts.core/src/main/java/ts/client/completions/JSDocTagInfo.java
new file mode 100644
index 00000000..cb5102d3
--- /dev/null
+++ b/typescript.java-ts.core/src/main/java/ts/client/completions/JSDocTagInfo.java
@@ -0,0 +1,16 @@
+package ts.client.completions;
+
+public class JSDocTagInfo {
+
+ private String name;
+
+ private String text;
+
+ public String getName() {
+ return name;
+ }
+
+ public String getText() {
+ return text;
+ }
+}
diff --git a/typescript.java-ts.core/src/main/java/ts/client/completions/RelevanceConstants.java b/typescript.java-ts.core/src/main/java/ts/client/completions/RelevanceConstants.java
new file mode 100644
index 00000000..ba35b7db
--- /dev/null
+++ b/typescript.java-ts.core/src/main/java/ts/client/completions/RelevanceConstants.java
@@ -0,0 +1,8 @@
+package ts.client.completions;
+
+public interface RelevanceConstants {
+
+ public static final int R_EXACT_NAME = 4;
+
+ public static final int R_CASE = 10;
+}
diff --git a/typescript.java-ts.core/src/main/java/ts/client/completions/SymbolDisplayPart.java b/typescript.java-ts.core/src/main/java/ts/client/completions/SymbolDisplayPart.java
new file mode 100644
index 00000000..36fd8447
--- /dev/null
+++ b/typescript.java-ts.core/src/main/java/ts/client/completions/SymbolDisplayPart.java
@@ -0,0 +1,44 @@
+/**
+ * Copyright (c) 2015-2017 Angelo ZERR.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Angelo Zerr - initial API and implementation
+ */
+package ts.client.completions;
+
+/**
+ * Part of a symbol description.
+ *
+ */
+public class SymbolDisplayPart {
+
+ private static final String PARAMETER_NAME_KIND = "parameterName";
+
+ /**
+ * Text of an item describing the symbol.
+ */
+ private String text;
+
+ /**
+ * The symbol's kind (such as 'className' or 'parameterName' or plain
+ * 'text').
+ */
+ private String kind;
+
+ public String getText() {
+ return text;
+ }
+
+ public String getKind() {
+ return kind;
+ }
+
+ public boolean isParameterName() {
+ return PARAMETER_NAME_KIND.equals(kind);
+ }
+
+}
diff --git a/typescript.java-ts.core/src/main/java/ts/client/configure/ConfigureRequestArguments.java b/typescript.java-ts.core/src/main/java/ts/client/configure/ConfigureRequestArguments.java
new file mode 100644
index 00000000..15480949
--- /dev/null
+++ b/typescript.java-ts.core/src/main/java/ts/client/configure/ConfigureRequestArguments.java
@@ -0,0 +1,59 @@
+package ts.client.configure;
+
+import ts.client.format.FormatCodeSettings;
+
+/**
+ * Information found in a configure request.
+ */
+public class ConfigureRequestArguments {
+
+ /**
+ * Information about the host, for example 'Emacs 24.4' or 'Sublime Text
+ * version 3075'
+ */
+ private String hostInfo;
+
+ /**
+ * If present, tab settings apply only to this file.
+ */
+ private String file;
+
+ /**
+ * The format options to use during formatting and other code editing
+ * features.
+ */
+ private FormatCodeSettings formatOptions;
+
+ /**
+ * The host's additional supported file extensions
+ */
+ // extraFileExtensions?: FileExtensionInfo[];
+
+ public String getHostInfo() {
+ return hostInfo;
+ }
+
+ public ConfigureRequestArguments setHostInfo(String hostInfo) {
+ this.hostInfo = hostInfo;
+ return this;
+ }
+
+ public String getFile() {
+ return file;
+ }
+
+ public ConfigureRequestArguments setFile(String file) {
+ this.file = file;
+ return this;
+ }
+
+ public FormatCodeSettings getFormatOptions() {
+ return formatOptions;
+ }
+
+ public ConfigureRequestArguments setFormatOptions(FormatCodeSettings formatOptions) {
+ this.formatOptions = formatOptions;
+ return this;
+ }
+
+}
diff --git a/typescript.java-ts.core/src/main/java/ts/client/diagnostics/AbstractDiagnostic.java b/typescript.java-ts.core/src/main/java/ts/client/diagnostics/AbstractDiagnostic.java
new file mode 100644
index 00000000..b7b876ed
--- /dev/null
+++ b/typescript.java-ts.core/src/main/java/ts/client/diagnostics/AbstractDiagnostic.java
@@ -0,0 +1,64 @@
+/**
+ * Copyright (c) 2015-2017 Angelo ZERR.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Angelo Zerr - initial API and implementation
+ */
+package ts.client.diagnostics;
+
+/**
+ * Item of diagnostic information found in a DiagnosticEvent message.
+ *
+ */
+public abstract class AbstractDiagnostic implements IDiagnostic {
+
+ private static final String TS_SOURCE = "ts";
+
+ /**
+ * Text of diagnostic message.
+ */
+ private String text;
+
+ /**
+ * The error code of the diagnostic message.
+ */
+ private Integer code;
+
+ private String category;
+
+ /**
+ * The name of the plugin reporting the message.
+ */
+ private String source;
+
+ @Override
+ public String getText() {
+ return text;
+ }
+
+ @Override
+ public String getFullText() {
+ String text = getText();
+ String source = getSource();
+ return new StringBuilder("[").append(source).append("] ").append(text != null ? text : "").toString();
+ }
+
+ @Override
+ public Integer getCode() {
+ return code;
+ }
+
+ @Override
+ public DiagnosticCategory getCategory() {
+ return DiagnosticCategory.getCategory(category);
+ }
+
+ @Override
+ public String getSource() {
+ return source != null ? source : TS_SOURCE;
+ }
+}
diff --git a/typescript.java-ts.core/src/main/java/ts/client/diagnostics/Diagnostic.java b/typescript.java-ts.core/src/main/java/ts/client/diagnostics/Diagnostic.java
new file mode 100644
index 00000000..e519e10c
--- /dev/null
+++ b/typescript.java-ts.core/src/main/java/ts/client/diagnostics/Diagnostic.java
@@ -0,0 +1,39 @@
+/**
+ * Copyright (c) 2015-2017 Angelo ZERR.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Angelo Zerr - initial API and implementation
+ */
+package ts.client.diagnostics;
+
+import ts.client.Location;
+
+/**
+ * Item of diagnostic information found in a DiagnosticEvent message.
+ *
+ */
+public class Diagnostic extends AbstractDiagnostic {
+
+ /**
+ * Starting file location at which text applies.
+ */
+ private Location start;
+
+ /**
+ * The last file location at which the text applies.
+ */
+ private Location end;
+
+ public Location getStartLocation() {
+ return start;
+ }
+
+ public Location getEndLocation() {
+ return end;
+ }
+
+}
diff --git a/typescript.java-ts.core/src/main/java/ts/client/diagnostics/DiagnosticEvent.java b/typescript.java-ts.core/src/main/java/ts/client/diagnostics/DiagnosticEvent.java
new file mode 100644
index 00000000..23774147
--- /dev/null
+++ b/typescript.java-ts.core/src/main/java/ts/client/diagnostics/DiagnosticEvent.java
@@ -0,0 +1,26 @@
+/**
+ * Copyright (c) 2015-2017 Angelo ZERR.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Angelo Zerr - initial API and implementation
+ */
+package ts.client.diagnostics;
+
+import ts.client.Event;
+
+/**
+ * Event message for "syntaxDiag" and "semanticDiag" event types. These events
+ * provide syntactic and semantic errors for a file.
+ *
+ * @see https://github.com/Microsoft/TypeScript/blob/master/src/server/protocol.ts
+ */
+public class DiagnosticEvent extends Event {
+
+ public String getKey() {
+ return getEvent() + "_" + getBody().getFile();
+ }
+}
diff --git a/typescript.java-ts.core/src/main/java/ts/client/diagnostics/DiagnosticEventBody.java b/typescript.java-ts.core/src/main/java/ts/client/diagnostics/DiagnosticEventBody.java
new file mode 100644
index 00000000..4dbb1e80
--- /dev/null
+++ b/typescript.java-ts.core/src/main/java/ts/client/diagnostics/DiagnosticEventBody.java
@@ -0,0 +1,42 @@
+/**
+ * Copyright (c) 2015-2017 Angelo ZERR.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Angelo Zerr - initial API and implementation
+ */
+package ts.client.diagnostics;
+
+import java.util.List;
+
+public class DiagnosticEventBody {
+
+ /**
+ * The file for which diagnostic information is reported.
+ */
+ private String file;
+
+ /**
+ * An array of diagnostic informatdiion items.
+ */
+ private List diagnostics;
+
+ public DiagnosticEventBody() {
+ }
+
+ public DiagnosticEventBody(String file, List diagnostics) {
+ this.file = file;
+ this.diagnostics = diagnostics;
+ }
+
+ public String getFile() {
+ return file;
+ }
+
+ public List getDiagnostics() {
+ return diagnostics;
+ }
+}
diff --git a/typescript.java-ts.core/src/main/java/ts/client/diagnostics/DiagnosticWithLinePosition.java b/typescript.java-ts.core/src/main/java/ts/client/diagnostics/DiagnosticWithLinePosition.java
new file mode 100644
index 00000000..6da51307
--- /dev/null
+++ b/typescript.java-ts.core/src/main/java/ts/client/diagnostics/DiagnosticWithLinePosition.java
@@ -0,0 +1,65 @@
+/**
+ * Copyright (c) 2015-2017 Angelo ZERR.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Angelo Zerr - initial API and implementation
+ */
+package ts.client.diagnostics;
+
+import ts.client.Location;
+
+/**
+ * Represents diagnostic info that includes location of diagnostic in two forms
+ * - start position and length of the error span - startLocation and endLocation
+ * - a pair of Location objects that store start/end line and offset of the
+ * error span.
+ */
+public class DiagnosticWithLinePosition extends AbstractDiagnostic {
+
+ private Integer start;
+
+ private Integer end;
+
+ /**
+ * Starting file location at which text applies.
+ */
+ private Location startLocation;
+
+ /**
+ * The last file location at which the text applies.
+ */
+ private Location endLocation;
+
+ /**
+ * Text of diagnostic message.
+ */
+ private String message;
+
+ @Override
+ public Location getStartLocation() {
+ return startLocation;
+ }
+
+ @Override
+ public Location getEndLocation() {
+ return endLocation;
+ }
+
+ public Integer getStart() {
+ return start;
+ }
+
+ public Integer getEnd() {
+ return end;
+ }
+
+ @Override
+ public String getText() {
+ return message != null ? message : super.getText();
+ }
+
+}
diff --git a/typescript.java-ts.core/src/main/java/ts/client/diagnostics/IDiagnostic.java b/typescript.java-ts.core/src/main/java/ts/client/diagnostics/IDiagnostic.java
new file mode 100644
index 00000000..4b1d8867
--- /dev/null
+++ b/typescript.java-ts.core/src/main/java/ts/client/diagnostics/IDiagnostic.java
@@ -0,0 +1,71 @@
+/**
+ * Copyright (c) 2015-2017 Angelo ZERR.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Angelo Zerr - initial API and implementation
+ */
+package ts.client.diagnostics;
+
+import ts.client.Location;
+import ts.utils.StringUtils;
+
+/**
+ * Diagnostic API.
+ *
+ */
+public interface IDiagnostic {
+
+ public enum DiagnosticCategory {
+ Warning, Error, Message;
+
+ public static DiagnosticCategory getCategory(String category) {
+ if (!StringUtils.isEmpty(category)) {
+ DiagnosticCategory[] values = DiagnosticCategory.values();
+ for (int i = 0; i < values.length; i++) {
+ DiagnosticCategory c = values[i];
+ if (category.equalsIgnoreCase(c.name())) {
+ return c;
+ }
+ }
+ }
+ return Error;
+ }
+ }
+
+ /**
+ * Return text of diagnostic message.
+ *
+ * @return text of diagnostic message.
+ */
+ String getText();
+
+ String getFullText();
+
+ Location getStartLocation();
+
+ Location getEndLocation();
+
+ /**
+ * Returns the error code of the diagnostic message.
+ *
+ * @return the error code of the diagnostic message.
+ */
+ Integer getCode();
+
+ /**
+ *
+ * @return
+ */
+ DiagnosticCategory getCategory();
+
+ /**
+ * Return the name of the plugin reporting the message.
+ *
+ * @return the name of the plugin reporting the message.
+ */
+ String getSource();
+}
diff --git a/typescript.java-ts.core/src/main/java/ts/client/format/EditorSettings.java b/typescript.java-ts.core/src/main/java/ts/client/format/EditorSettings.java
new file mode 100644
index 00000000..4b9e73f3
--- /dev/null
+++ b/typescript.java-ts.core/src/main/java/ts/client/format/EditorSettings.java
@@ -0,0 +1,61 @@
+package ts.client.format;
+
+public class EditorSettings {
+
+ private Integer baseIndentSize;
+
+ private Integer indentSize;
+ private Integer tabSize;
+ private String newLineCharacter;
+ private Boolean convertTabsToSpaces;
+ private IndentStyle indentStyle;
+
+ public Integer getBaseIndentSize() {
+ return baseIndentSize;
+ }
+
+ public void setBaseIndentSize(Integer baseIndentSize) {
+ this.baseIndentSize = baseIndentSize;
+ }
+
+ public Integer getIndentSize() {
+ return indentSize;
+ }
+
+ public void setIndentSize(Integer indentSize) {
+ this.indentSize = indentSize;
+ }
+
+ public Integer getTabSize() {
+ return tabSize;
+ }
+
+ public void setTabSize(Integer tabSize) {
+ this.tabSize = tabSize;
+ }
+
+ public String getNewLineCharacter() {
+ return newLineCharacter;
+ }
+
+ public void setNewLineCharacter(String newLineCharacter) {
+ this.newLineCharacter = newLineCharacter;
+ }
+
+ public Boolean getConvertTabsToSpaces() {
+ return convertTabsToSpaces;
+ }
+
+ public void setConvertTabsToSpaces(Boolean convertTabsToSpaces) {
+ this.convertTabsToSpaces = convertTabsToSpaces;
+ }
+
+ public IndentStyle getIndentStyle() {
+ return indentStyle;
+ }
+
+ public void setIndentStyle(IndentStyle indentStyle) {
+ this.indentStyle = indentStyle;
+ }
+
+}
diff --git a/typescript.java-ts.core/src/main/java/ts/client/format/FormatCodeSettings.java b/typescript.java-ts.core/src/main/java/ts/client/format/FormatCodeSettings.java
new file mode 100644
index 00000000..3dc9a969
--- /dev/null
+++ b/typescript.java-ts.core/src/main/java/ts/client/format/FormatCodeSettings.java
@@ -0,0 +1,144 @@
+/**
+ * Copyright (c) 2015-2017 Angelo ZERR.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Angelo Zerr - initial API and implementation
+ */
+package ts.client.format;
+
+/**
+ *
+ * @see https://github.com/Microsoft/TypeScript/blob/master/src/server/protocol.ts
+ *
+ */
+public class FormatCodeSettings extends EditorSettings {
+
+ private Boolean insertSpaceAfterCommaDelimiter;
+ private Boolean insertSpaceAfterSemicolonInForStatements;
+ private Boolean insertSpaceBeforeAndAfterBinaryOperators;
+ private Boolean insertSpaceAfterConstructor;
+ private Boolean insertSpaceAfterKeywordsInControlFlowStatements;
+ private Boolean insertSpaceAfterFunctionKeywordForAnonymousFunctions;
+ private Boolean insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis;
+ private Boolean insertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets;
+ private Boolean insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces;
+ private Boolean insertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces;
+ private Boolean insertSpaceBeforeFunctionParenthesis;
+ private Boolean placeOpenBraceOnNewLineForFunctions;
+ private Boolean placeOpenBraceOnNewLineForControlBlocks;
+
+ public Boolean getInsertSpaceAfterCommaDelimiter() {
+ return insertSpaceAfterCommaDelimiter;
+ }
+
+ public void setInsertSpaceAfterCommaDelimiter(Boolean insertSpaceAfterCommaDelimiter) {
+ this.insertSpaceAfterCommaDelimiter = insertSpaceAfterCommaDelimiter;
+ }
+
+ public Boolean getInsertSpaceAfterSemicolonInForStatements() {
+ return insertSpaceAfterSemicolonInForStatements;
+ }
+
+ public void setInsertSpaceAfterSemicolonInForStatements(Boolean insertSpaceAfterSemicolonInForStatements) {
+ this.insertSpaceAfterSemicolonInForStatements = insertSpaceAfterSemicolonInForStatements;
+ }
+
+ public Boolean getInsertSpaceBeforeAndAfterBinaryOperators() {
+ return insertSpaceBeforeAndAfterBinaryOperators;
+ }
+
+ public void setInsertSpaceBeforeAndAfterBinaryOperators(Boolean insertSpaceBeforeAndAfterBinaryOperators) {
+ this.insertSpaceBeforeAndAfterBinaryOperators = insertSpaceBeforeAndAfterBinaryOperators;
+ }
+
+ public Boolean getInsertSpaceAfterConstructor() {
+ return insertSpaceAfterConstructor;
+ }
+
+ public void setInsertSpaceAfterConstructor(Boolean insertSpaceAfterConstructor) {
+ this.insertSpaceAfterConstructor = insertSpaceAfterConstructor;
+ }
+
+ public Boolean getInsertSpaceAfterKeywordsInControlFlowStatements() {
+ return insertSpaceAfterKeywordsInControlFlowStatements;
+ }
+
+ public void setInsertSpaceAfterKeywordsInControlFlowStatements(
+ Boolean insertSpaceAfterKeywordsInControlFlowStatements) {
+ this.insertSpaceAfterKeywordsInControlFlowStatements = insertSpaceAfterKeywordsInControlFlowStatements;
+ }
+
+ public Boolean getInsertSpaceAfterFunctionKeywordForAnonymousFunctions() {
+ return insertSpaceAfterFunctionKeywordForAnonymousFunctions;
+ }
+
+ public void setInsertSpaceAfterFunctionKeywordForAnonymousFunctions(
+ Boolean insertSpaceAfterFunctionKeywordForAnonymousFunctions) {
+ this.insertSpaceAfterFunctionKeywordForAnonymousFunctions = insertSpaceAfterFunctionKeywordForAnonymousFunctions;
+ }
+
+ public Boolean getInsertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis() {
+ return insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis;
+ }
+
+ public void setInsertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis(
+ Boolean insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis) {
+ this.insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis = insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis;
+ }
+
+ public Boolean getInsertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets() {
+ return insertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets;
+ }
+
+ public void setInsertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets(
+ Boolean insertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets) {
+ this.insertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets = insertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets;
+ }
+
+ public Boolean getInsertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces() {
+ return insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces;
+ }
+
+ public void setInsertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces(
+ Boolean insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces) {
+ this.insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces = insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces;
+ }
+
+ public Boolean getInsertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces() {
+ return insertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces;
+ }
+
+ public void setInsertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces(
+ Boolean insertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces) {
+ this.insertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces = insertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces;
+ }
+
+ public Boolean getInsertSpaceBeforeFunctionParenthesis() {
+ return insertSpaceBeforeFunctionParenthesis;
+ }
+
+ public void setInsertSpaceBeforeFunctionParenthesis(Boolean insertSpaceBeforeFunctionParenthesis) {
+ this.insertSpaceBeforeFunctionParenthesis = insertSpaceBeforeFunctionParenthesis;
+ }
+
+ public Boolean getPlaceOpenBraceOnNewLineForFunctions() {
+ return placeOpenBraceOnNewLineForFunctions;
+ }
+
+ public void setPlaceOpenBraceOnNewLineForFunctions(Boolean placeOpenBraceOnNewLineForFunctions) {
+ this.placeOpenBraceOnNewLineForFunctions = placeOpenBraceOnNewLineForFunctions;
+ }
+
+ public Boolean getPlaceOpenBraceOnNewLineForControlBlocks() {
+ return placeOpenBraceOnNewLineForControlBlocks;
+ }
+
+ public void setPlaceOpenBraceOnNewLineForControlBlocks(Boolean placeOpenBraceOnNewLineForControlBlocks) {
+ this.placeOpenBraceOnNewLineForControlBlocks = placeOpenBraceOnNewLineForControlBlocks;
+ }
+
+}
diff --git a/typescript.java-ts.core/src/main/java/ts/client/format/IndentStyle.java b/typescript.java-ts.core/src/main/java/ts/client/format/IndentStyle.java
new file mode 100644
index 00000000..b4873734
--- /dev/null
+++ b/typescript.java-ts.core/src/main/java/ts/client/format/IndentStyle.java
@@ -0,0 +1,6 @@
+package ts.client.format;
+
+public enum IndentStyle {
+
+ None, Block, Smart;
+}
diff --git a/typescript.java-ts.core/src/main/java/ts/client/installtypes/BeginInstallTypesEventBody.java b/typescript.java-ts.core/src/main/java/ts/client/installtypes/BeginInstallTypesEventBody.java
new file mode 100644
index 00000000..7919e9f9
--- /dev/null
+++ b/typescript.java-ts.core/src/main/java/ts/client/installtypes/BeginInstallTypesEventBody.java
@@ -0,0 +1,5 @@
+package ts.client.installtypes;
+
+public class BeginInstallTypesEventBody extends InstallTypesEventBody {
+
+}
diff --git a/typescript.java-ts.core/src/main/java/ts/client/installtypes/EndInstallTypesEventBody.java b/typescript.java-ts.core/src/main/java/ts/client/installtypes/EndInstallTypesEventBody.java
new file mode 100644
index 00000000..bd7dd1f6
--- /dev/null
+++ b/typescript.java-ts.core/src/main/java/ts/client/installtypes/EndInstallTypesEventBody.java
@@ -0,0 +1,13 @@
+package ts.client.installtypes;
+
+public class EndInstallTypesEventBody extends InstallTypesEventBody {
+
+ /**
+ * true if installation succeeded, otherwise false
+ */
+ private boolean success;
+
+ public boolean isSuccess() {
+ return success;
+ }
+}
diff --git a/typescript.java-ts.core/src/main/java/ts/client/installtypes/IInstallTypesListener.java b/typescript.java-ts.core/src/main/java/ts/client/installtypes/IInstallTypesListener.java
new file mode 100644
index 00000000..aa9d9c3e
--- /dev/null
+++ b/typescript.java-ts.core/src/main/java/ts/client/installtypes/IInstallTypesListener.java
@@ -0,0 +1,13 @@
+package ts.client.installtypes;
+
+import com.google.gson.JsonObject;
+
+public interface IInstallTypesListener {
+
+ void onBegin(BeginInstallTypesEventBody body);
+
+ void logTelemetry(String telemetryEventName, JsonObject payload);
+
+ void onEnd(EndInstallTypesEventBody body);
+
+}
diff --git a/typescript.java-ts.core/src/main/java/ts/client/installtypes/InstallTypesEventBody.java b/typescript.java-ts.core/src/main/java/ts/client/installtypes/InstallTypesEventBody.java
new file mode 100644
index 00000000..19256d7c
--- /dev/null
+++ b/typescript.java-ts.core/src/main/java/ts/client/installtypes/InstallTypesEventBody.java
@@ -0,0 +1,24 @@
+package ts.client.installtypes;
+
+import java.util.List;
+
+public class InstallTypesEventBody {
+
+ /**
+ * correlation id to match begin and end events
+ */
+ int eventId;
+
+ /**
+ * list of packages to install
+ */
+ List packages;
+
+ public int getEventId() {
+ return eventId;
+ }
+
+ public List getPackages() {
+ return packages;
+ }
+}
diff --git a/typescript.java-ts.core/src/main/java/ts/client/jsdoc/TextInsertion.java b/typescript.java-ts.core/src/main/java/ts/client/jsdoc/TextInsertion.java
new file mode 100644
index 00000000..f1454183
--- /dev/null
+++ b/typescript.java-ts.core/src/main/java/ts/client/jsdoc/TextInsertion.java
@@ -0,0 +1,23 @@
+package ts.client.jsdoc;
+
+/**
+ * @see https://github.com/Microsoft/TypeScript/blob/master/src/services/types.ts
+ *
+ */
+public class TextInsertion {
+
+ private String newText;
+
+ /**
+ * The position in newText the caret should point to after the insertion.
+ */
+ private int caretOffset;
+
+ public String getNewText() {
+ return newText;
+ }
+
+ public int getCaretOffset() {
+ return caretOffset;
+ }
+}
diff --git a/typescript.java-ts.core/src/main/java/ts/client/navbar/NavigationBarItem.java b/typescript.java-ts.core/src/main/java/ts/client/navbar/NavigationBarItem.java
new file mode 100644
index 00000000..38520bac
--- /dev/null
+++ b/typescript.java-ts.core/src/main/java/ts/client/navbar/NavigationBarItem.java
@@ -0,0 +1,107 @@
+/**
+ * Copyright (c) 2015-2016 Angelo ZERR.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Angelo Zerr - initial API and implementation
+ */
+package ts.client.navbar;
+
+import java.util.List;
+
+import ts.client.IKindProvider;
+
+/**
+ * Navigation bar item.
+ *
+ */
+public class NavigationBarItem implements IKindProvider {
+
+ /**
+ * The item's display text.
+ */
+ private String text;
+
+ /**
+ * The symbol's kind (such as 'className' or 'parameterName').
+ */
+ private String kind;
+
+ /**
+ * Optional modifiers for the kind (such as 'public').
+ */
+ private String kindModifiers;
+ private List spans;
+ private List childItems;
+ private boolean parentAlreadyUpdated;
+ NavigationBarItem parent;
+
+ public String getText() {
+ return text;
+ }
+
+ @Override
+ public String getKind() {
+ return kind;
+ }
+
+ @Override
+ public String getKindModifiers() {
+ return kindModifiers;
+ }
+
+ public void setText(String text) {
+ this.text = text;
+ }
+
+ public void setSpans(List spans) {
+ this.spans = spans;
+ this.parentAlreadyUpdated = false;
+ }
+
+ public List getSpans() {
+ updateParentIfNeeded();
+ return spans;
+ }
+
+ public boolean hasSpans() {
+ return spans != null && spans.size() > 0;
+ }
+
+ public List getChildItems() {
+ updateParentIfNeeded();
+ return childItems;
+ }
+
+ private void updateParentIfNeeded() {
+ if (!parentAlreadyUpdated) {
+ if (childItems != null) {
+ for (NavigationBarItem item : childItems) {
+ item.parent = this;
+ }
+ }
+ if (spans != null) {
+ for (NavigationTextSpan span : spans) {
+ span.parent = this;
+ }
+ }
+ parentAlreadyUpdated = true;
+ }
+ }
+
+ public void setChildItems(List childItems) {
+ this.childItems = childItems;
+ this.parentAlreadyUpdated = false;
+ }
+
+ public boolean hasChildItems() {
+ return childItems != null && childItems.size() > 0;
+ }
+
+ public NavigationBarItem getParent() {
+ return parent;
+ }
+}
diff --git a/typescript.java-ts.core/src/main/java/ts/client/navbar/NavigationBarItemRoot.java b/typescript.java-ts.core/src/main/java/ts/client/navbar/NavigationBarItemRoot.java
new file mode 100644
index 00000000..cb5dc8f6
--- /dev/null
+++ b/typescript.java-ts.core/src/main/java/ts/client/navbar/NavigationBarItemRoot.java
@@ -0,0 +1,38 @@
+/**
+ * Copyright (c) 2015-2016 Angelo ZERR.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Angelo Zerr - initial API and implementation
+ */
+package ts.client.navbar;
+
+import java.util.Arrays;
+import java.util.List;
+
+/**
+ * Root of the list of navigation bar items.
+ *
+ */
+public class NavigationBarItemRoot extends NavigationBarItem {
+
+ private boolean navtree;
+
+ public NavigationBarItemRoot(NavigationBarItem item) {
+ this(Arrays.asList(item));
+ this.navtree = true;
+ }
+
+ public NavigationBarItemRoot(List items) {
+ setChildItems(items);
+ this.navtree = false;
+ }
+
+ public boolean isNavTree() {
+ return navtree;
+ }
+
+}
diff --git a/typescript.java-ts.core/src/main/java/ts/client/navbar/NavigationTextSpan.java b/typescript.java-ts.core/src/main/java/ts/client/navbar/NavigationTextSpan.java
new file mode 100644
index 00000000..310a0eb7
--- /dev/null
+++ b/typescript.java-ts.core/src/main/java/ts/client/navbar/NavigationTextSpan.java
@@ -0,0 +1,23 @@
+/**
+ * Copyright (c) 2015-2016 Angelo ZERR.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Angelo Zerr - initial API and implementation
+ */
+package ts.client.navbar;
+
+import ts.client.TextSpan;
+
+public class NavigationTextSpan extends TextSpan {
+
+ NavigationBarItem parent;
+
+ public NavigationBarItem getParent() {
+ return parent;
+ }
+
+}
diff --git a/typescript.java-ts.core/src/main/java/ts/client/navto/NavtoItem.java b/typescript.java-ts.core/src/main/java/ts/client/navto/NavtoItem.java
new file mode 100644
index 00000000..5a1e7e1f
--- /dev/null
+++ b/typescript.java-ts.core/src/main/java/ts/client/navto/NavtoItem.java
@@ -0,0 +1,87 @@
+/**
+ * Copyright (c) 2015-2017 Angelo ZERR.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Angelo Zerr - initial API and implementation
+ */
+package ts.client.navto;
+
+import ts.client.FileSpan;
+import ts.client.IKindProvider;
+
+/**
+ * An item found in a navto response.
+ */
+public class NavtoItem extends FileSpan implements IKindProvider {
+
+ /**
+ * The symbol's name.
+ */
+ private String name;
+
+ /**
+ * The symbol's kind (such as 'className' or 'parameterName').
+ */
+ private String kind;
+
+ /**
+ * exact, substring, or prefix.
+ */
+ private String matchKind;
+
+ /**
+ * If this was a case sensitive or insensitive match.
+ */
+ private Boolean isCaseSensitive;
+
+ /**
+ * Optional modifiers for the kind (such as 'public').
+ */
+ private String kindModifiers;
+
+ /**
+ * Name of symbol's container symbol (if any); for example, the class name if
+ * symbol is a class member.
+ */
+ private String containerName;
+
+ /**
+ * Kind of symbol's container symbol (if any).
+ */
+ private String containerKind;
+
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public String getKind() {
+ return kind;
+ }
+
+ public String getMatchKind() {
+ return matchKind;
+ }
+
+ public Boolean getIsCaseSensitive() {
+ return isCaseSensitive;
+ }
+
+ @Override
+ public String getKindModifiers() {
+ return kindModifiers;
+ }
+
+ public String getContainerName() {
+ return containerName;
+ }
+
+ public String getContainerKind() {
+ return containerKind;
+ }
+
+}
diff --git a/typescript.java-ts.core/src/main/java/ts/client/occurrences/OccurrencesResponseItem.java b/typescript.java-ts.core/src/main/java/ts/client/occurrences/OccurrencesResponseItem.java
new file mode 100644
index 00000000..cd04014e
--- /dev/null
+++ b/typescript.java-ts.core/src/main/java/ts/client/occurrences/OccurrencesResponseItem.java
@@ -0,0 +1,25 @@
+/**
+ * Copyright (c) 2015-2017 Angelo ZERR.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Angelo Zerr - initial API and implementation
+ */
+package ts.client.occurrences;
+
+import ts.client.FileSpan;
+
+public class OccurrencesResponseItem extends FileSpan {
+ /**
+ * True if the occurrence is a write location, false otherwise.
+ */
+ private boolean isWriteAccess;
+
+ public boolean isWriteAccess() {
+ return isWriteAccess;
+ }
+
+}
diff --git a/typescript.java-ts.core/src/main/java/ts/client/projectinfo/ProjectInfo.java b/typescript.java-ts.core/src/main/java/ts/client/projectinfo/ProjectInfo.java
new file mode 100644
index 00000000..7404fcae
--- /dev/null
+++ b/typescript.java-ts.core/src/main/java/ts/client/projectinfo/ProjectInfo.java
@@ -0,0 +1,47 @@
+/**
+ * Copyright (c) 2015-2017 Angelo ZERR.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Angelo Zerr - initial API and implementation
+ */
+package ts.client.projectinfo;
+
+import java.util.List;
+
+/**
+ * Response message body for "projectInfo" request
+ *
+ */
+public class ProjectInfo {
+
+ /**
+ * For configured project, this is the normalized path of the
+ * 'tsconfig.json' file For inferred project, this is undefined
+ */
+ private String configFileName;
+ /**
+ * The list of normalized file name in the project, including 'lib.d.ts'
+ */
+ private List fileNames;
+ /**
+ * Indicates if the project has a active language service instance
+ */
+ private Boolean languageServiceDisabled;
+
+ public String getConfigFileName() {
+ return configFileName;
+ }
+
+ public List getFileNames() {
+ return fileNames;
+ }
+
+ public Boolean getLanguageServiceDisabled() {
+ return languageServiceDisabled;
+ }
+
+}
diff --git a/typescript.java-ts.core/src/main/java/ts/client/quickinfo/QuickInfo.java b/typescript.java-ts.core/src/main/java/ts/client/quickinfo/QuickInfo.java
new file mode 100644
index 00000000..663c457a
--- /dev/null
+++ b/typescript.java-ts.core/src/main/java/ts/client/quickinfo/QuickInfo.java
@@ -0,0 +1,71 @@
+/**
+ * Copyright (c) 2015-2017 Angelo ZERR.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Angelo Zerr - initial API and implementation
+ */
+package ts.client.quickinfo;
+
+import ts.client.Location;
+
+public class QuickInfo {
+
+ /**
+ * The symbol's kind (such as 'className' or 'parameterName' or plain
+ * 'text').
+ */
+ private String kind;
+
+ /**
+ * Optional modifiers for the kind (such as 'public').
+ */
+ private String kindModifiers;
+
+ /**
+ * Starting file location of symbol.
+ */
+ private Location start;
+
+ /**
+ * One past last character of symbol.
+ */
+ private Location end;
+
+ /**
+ * Type and kind of symbol.
+ */
+ private String displayString;
+
+ /**
+ * Documentation associated with symbol.
+ */
+ private String documentation;
+
+ public String getKind() {
+ return kind;
+ }
+
+ public String getKindModifiers() {
+ return kindModifiers;
+ }
+
+ public Location getStart() {
+ return start;
+ }
+
+ public Location getEnd() {
+ return end;
+ }
+
+ public String getDisplayString() {
+ return displayString;
+ }
+
+ public String getDocumentation() {
+ return documentation;
+ }
+}
diff --git a/typescript.java-ts.core/src/main/java/ts/client/refactors/ApplicableRefactorInfo.java b/typescript.java-ts.core/src/main/java/ts/client/refactors/ApplicableRefactorInfo.java
new file mode 100644
index 00000000..6f35245a
--- /dev/null
+++ b/typescript.java-ts.core/src/main/java/ts/client/refactors/ApplicableRefactorInfo.java
@@ -0,0 +1,52 @@
+package ts.client.refactors;
+
+import java.util.List;
+
+/**
+ * A set of one or more available refactoring actions, grouped under a parent
+ * refactoring.
+ */
+public class ApplicableRefactorInfo {
+
+ /**
+ * The programmatic name of the refactoring
+ */
+ private String name;
+
+ /**
+ * A description of this refactoring category to show to the user. If the
+ * refactoring gets inlined (see below), this text will not be visible.
+ */
+ private String description;
+
+ /**
+ * Inlineable refactorings can have their actions hoisted out to the top level
+ * of a context menu. Non-inlineanable refactorings should always be shown
+ * inside their parent grouping.
+ *
+ * If not specified, this value is assumed to be 'true'
+ */
+ private Boolean inlineable;
+
+ private List actions;
+
+ public String getName() {
+ return name;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public Boolean getInlineable() {
+ return inlineable;
+ }
+
+ public List getActions() {
+ return actions;
+ }
+
+ public boolean isInlineable() {
+ return inlineable == null ? true : inlineable;
+ }
+}
diff --git a/typescript.java-ts.core/src/main/java/ts/client/refactors/RefactorActionInfo.java b/typescript.java-ts.core/src/main/java/ts/client/refactors/RefactorActionInfo.java
new file mode 100644
index 00000000..bdf15b08
--- /dev/null
+++ b/typescript.java-ts.core/src/main/java/ts/client/refactors/RefactorActionInfo.java
@@ -0,0 +1,29 @@
+package ts.client.refactors;
+
+/**
+ * Represents a single refactoring action - for example, the "Extract Method..."
+ * refactor might offer several actions, each corresponding to a surround class
+ * or closure to extract into.
+ */
+public class RefactorActionInfo {
+
+ /**
+ * The programmatic name of the refactoring action
+ */
+ private String name;
+
+ /**
+ * A description of this refactoring action to show to the user. If the parent
+ * refactoring is inlined away, this will be the only text shown, so this
+ * description should make sense by itself if the parent is inlineable=true
+ */
+ private String description;
+
+ public String getName() {
+ return name;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+}
diff --git a/typescript.java-ts.core/src/main/java/ts/client/refactors/RefactorEditInfo.java b/typescript.java-ts.core/src/main/java/ts/client/refactors/RefactorEditInfo.java
new file mode 100644
index 00000000..4f427e4f
--- /dev/null
+++ b/typescript.java-ts.core/src/main/java/ts/client/refactors/RefactorEditInfo.java
@@ -0,0 +1,31 @@
+package ts.client.refactors;
+
+import java.util.List;
+
+import ts.client.Location;
+import ts.client.codefixes.FileCodeEdits;
+
+public class RefactorEditInfo {
+
+ private List edits;
+
+ /**
+ * An optional location where the editor should start a rename operation once
+ * the refactoring edits have been applied
+ */
+ private Location renameLocation;
+
+ private String renameFilename;
+
+ public List getEdits() {
+ return edits;
+ }
+
+ public Location getRenameLocation() {
+ return renameLocation;
+ }
+
+ public String getRenameFilename() {
+ return renameFilename;
+ }
+}
diff --git a/typescript.java-ts.core/src/main/java/ts/client/references/ReferencesResponseBody.java b/typescript.java-ts.core/src/main/java/ts/client/references/ReferencesResponseBody.java
new file mode 100644
index 00000000..3cf9044c
--- /dev/null
+++ b/typescript.java-ts.core/src/main/java/ts/client/references/ReferencesResponseBody.java
@@ -0,0 +1,58 @@
+/**
+ * Copyright (c) 2015-2017 Angelo ZERR.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Angelo Zerr - initial API and implementation
+ */
+package ts.client.references;
+
+import java.util.List;
+
+/**
+ *
+ * The body of a "references" response message.
+ *
+ */
+public class ReferencesResponseBody {
+
+ /**
+ * The file locations referencing the symbol.
+ */
+ private List refs;
+
+ /**
+ * The name of the symbol.
+ */
+ private String symbolName;
+
+ /**
+ * The start character offset of the symbol (on the line provided by the
+ * references request).
+ */
+ private int symbolStartOffset;
+
+ /**
+ * The full display name of the symbol.
+ */
+ private String symbolDisplayString;
+
+ public List getRefs() {
+ return refs;
+ }
+
+ public String getSymbolName() {
+ return symbolName;
+ }
+
+ public int getSymbolStartOffset() {
+ return symbolStartOffset;
+ }
+
+ public String getSymbolDisplayString() {
+ return symbolDisplayString;
+ }
+}
diff --git a/typescript.java-ts.core/src/main/java/ts/client/references/ReferencesResponseItem.java b/typescript.java-ts.core/src/main/java/ts/client/references/ReferencesResponseItem.java
new file mode 100644
index 00000000..9756a7d0
--- /dev/null
+++ b/typescript.java-ts.core/src/main/java/ts/client/references/ReferencesResponseItem.java
@@ -0,0 +1,45 @@
+/**
+ * Copyright (c) 2015-2017 Angelo ZERR.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Angelo Zerr - initial API and implementation
+ */
+package ts.client.references;
+
+import ts.client.FileSpan;
+
+public class ReferencesResponseItem extends FileSpan {
+ /**
+ * Text of line containing the reference. Including this with the response
+ * avoids latency of editor loading files to show text of reference line
+ * (the server already has loaded the referencing files).
+ */
+ private String lineText;
+
+ /**
+ * True if reference is a write location, false otherwise.
+ */
+ private boolean isWriteAccess;
+
+ /**
+ * True if reference is a definition, false otherwise.
+ */
+ private boolean isDefinition;
+
+ public String getLineText() {
+ return lineText;
+ }
+
+ public boolean isWriteAccess() {
+ return isWriteAccess;
+ }
+
+ public boolean isDefinition() {
+ return isDefinition;
+ }
+
+}
diff --git a/typescript.java-ts.core/src/main/java/ts/client/rename/RenameInfo.java b/typescript.java-ts.core/src/main/java/ts/client/rename/RenameInfo.java
new file mode 100644
index 00000000..fcda54a1
--- /dev/null
+++ b/typescript.java-ts.core/src/main/java/ts/client/rename/RenameInfo.java
@@ -0,0 +1,74 @@
+/**
+ * Copyright (c) 2015-2017 Angelo ZERR.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Angelo Zerr - initial API and implementation
+ */
+package ts.client.rename;
+
+/**
+ * Information about the item to be renamed.
+ *
+ */
+public class RenameInfo {
+
+ /**
+ * True if item can be renamed.
+ */
+ private boolean canRename;
+
+ /**
+ * Error message if item can not be renamed.
+ */
+ private String localizedErrorMessage;
+
+ /**
+ * Display name of the item to be renamed.
+ */
+ private String displayName;
+
+ /**
+ * Full display name of item to be renamed.
+ */
+ private String fullDisplayName;
+
+ /**
+ * The items's kind (such as 'className' or 'parameterName' or plain
+ * 'text').
+ */
+ private String kind;
+
+ /**
+ * Optional modifiers for the kind (such as 'public').
+ */
+ private String kindModifiers;
+
+ public boolean isCanRename() {
+ return canRename;
+ }
+
+ public String getLocalizedErrorMessage() {
+ return localizedErrorMessage;
+ }
+
+ public String getDisplayName() {
+ return displayName;
+ }
+
+ public String getFullDisplayName() {
+ return fullDisplayName;
+ }
+
+ public String getKind() {
+ return kind;
+ }
+
+ public String getKindModifiers() {
+ return kindModifiers;
+ }
+
+}
diff --git a/typescript.java-ts.core/src/main/java/ts/client/rename/RenameResponseBody.java b/typescript.java-ts.core/src/main/java/ts/client/rename/RenameResponseBody.java
new file mode 100644
index 00000000..2ab4eb8a
--- /dev/null
+++ b/typescript.java-ts.core/src/main/java/ts/client/rename/RenameResponseBody.java
@@ -0,0 +1,35 @@
+/**
+ * Copyright (c) 2015-2017 Angelo ZERR.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Angelo Zerr - initial API and implementation
+ */
+package ts.client.rename;
+
+import java.util.List;
+
+public class RenameResponseBody {
+
+ /**
+ * Information about the item to be renamed.
+ */
+ private RenameInfo info;
+
+ /**
+ * An array of span groups (one per file) that refer to the item to be
+ * renamed.
+ */
+ private List locs;
+
+ public RenameInfo getInfo() {
+ return info;
+ }
+
+ public List getLocs() {
+ return locs;
+ }
+}
diff --git a/typescript.java-ts.core/src/main/java/ts/client/rename/SpanGroup.java b/typescript.java-ts.core/src/main/java/ts/client/rename/SpanGroup.java
new file mode 100644
index 00000000..16e70592
--- /dev/null
+++ b/typescript.java-ts.core/src/main/java/ts/client/rename/SpanGroup.java
@@ -0,0 +1,41 @@
+/**
+ * Copyright (c) 2015-2017 Angelo ZERR.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Angelo Zerr - initial API and implementation
+ */
+package ts.client.rename;
+
+import java.util.List;
+
+import ts.client.TextSpan;
+
+/**
+ * A group of text spans, all in 'file'.
+ *
+ */
+public class SpanGroup {
+
+ /**
+ * The file to which the spans apply
+ */
+ private String file;
+
+ /**
+ * The text spans in this group
+ */
+ private List locs;
+
+ public String getFile() {
+ return file;
+ }
+
+ public List getLocs() {
+ return locs;
+ }
+
+}
diff --git a/typescript.java-ts.core/src/main/java/ts/client/signaturehelp/SignatureHelpItems.java b/typescript.java-ts.core/src/main/java/ts/client/signaturehelp/SignatureHelpItems.java
new file mode 100644
index 00000000..2421d4c9
--- /dev/null
+++ b/typescript.java-ts.core/src/main/java/ts/client/signaturehelp/SignatureHelpItems.java
@@ -0,0 +1,18 @@
+/**
+ * Copyright (c) 2015-2017 Angelo ZERR.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Angelo Zerr - initial API and implementation
+ */
+package ts.client.signaturehelp;
+
+/**
+ * Signature help items found in the response of a signature help request.
+ */
+public class SignatureHelpItems {
+
+}
\ No newline at end of file
diff --git a/typescript.java-ts.core/src/main/java/ts/cmd/AbstractCmd.java b/typescript.java-ts.core/src/main/java/ts/cmd/AbstractCmd.java
new file mode 100644
index 00000000..f21d4b05
--- /dev/null
+++ b/typescript.java-ts.core/src/main/java/ts/cmd/AbstractCmd.java
@@ -0,0 +1,71 @@
+package ts.cmd;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import ts.TypeScriptException;
+import ts.nodejs.INodejsLaunchConfiguration;
+import ts.nodejs.INodejsProcess;
+import ts.nodejs.INodejsProcessListener;
+import ts.nodejs.NodejsProcess;
+import ts.nodejs.NodejsProcessManager;
+
+public class AbstractCmd {
+
+ private final File binFile;
+ private final File nodejsFile;
+ private final String binFileType;
+
+ public AbstractCmd(File binFile, File nodejsFile, String binFileType) {
+ this.binFile = binFile;
+ this.nodejsFile = nodejsFile;
+ this.binFileType = binFileType;
+ }
+
+ public List createCommands(T options, List filenames) {
+ List cmds = NodejsProcess.createNodeCommands(nodejsFile, binFile);
+ fillOptions(options, filenames, cmds);
+ return cmds;
+ }
+
+ public INodejsProcess execute(File baseDir, final T options, final List filenames,
+ INodejsProcessListener listener) throws TypeScriptException {
+ INodejsProcess process = NodejsProcessManager.getInstance().create(baseDir, binFile, nodejsFile,
+ new INodejsLaunchConfiguration() {
+
+ @Override
+ public List createNodeArgs() {
+ List args = new ArrayList();
+ fillOptions(options, filenames, args);
+ return args;
+ }
+
+ @Override
+ public Map createNodeEnvironmentVariables() {
+ return null;
+ }
+ }, binFileType);
+
+ if (listener != null) {
+ process.addProcessListener(listener);
+ }
+ process.start();
+ try {
+ process.join();
+ } catch (InterruptedException e) {
+ throw new TypeScriptException(e);
+ }
+ return process;
+ }
+
+ private void fillOptions(T options, List filenames, List args) {
+ if (filenames != null) {
+ args.addAll(filenames);
+ }
+ if (options != null) {
+ options.fillOptions(args);
+ }
+ }
+}
diff --git a/typescript.java-ts.core/src/main/java/ts/cmd/AbstractOptions.java b/typescript.java-ts.core/src/main/java/ts/cmd/AbstractOptions.java
new file mode 100644
index 00000000..d392836c
--- /dev/null
+++ b/typescript.java-ts.core/src/main/java/ts/cmd/AbstractOptions.java
@@ -0,0 +1,22 @@
+package ts.cmd;
+
+import java.util.List;
+
+import ts.utils.StringUtils;
+
+public abstract class AbstractOptions implements IOptions{
+
+ protected void fillOption(String name, Boolean value, List args) {
+ if (value != null && value) {
+ args.add(name);
+ }
+ }
+
+ protected void fillOption(String name, String value, List args) {
+ if (!StringUtils.isEmpty(value)) {
+ args.add(name);
+ args.add(value);
+ }
+ }
+
+}
diff --git a/typescript.java-ts.core/src/main/java/ts/cmd/IOptions.java b/typescript.java-ts.core/src/main/java/ts/cmd/IOptions.java
new file mode 100644
index 00000000..343414f1
--- /dev/null
+++ b/typescript.java-ts.core/src/main/java/ts/cmd/IOptions.java
@@ -0,0 +1,9 @@
+package ts.cmd;
+
+import java.util.List;
+
+public interface IOptions {
+
+ void fillOptions(List args);
+
+}
diff --git a/typescript.java-ts.core/src/main/java/ts/cmd/ITypeScriptLinterHandler.java b/typescript.java-ts.core/src/main/java/ts/cmd/ITypeScriptLinterHandler.java
new file mode 100644
index 00000000..bcb14cec
--- /dev/null
+++ b/typescript.java-ts.core/src/main/java/ts/cmd/ITypeScriptLinterHandler.java
@@ -0,0 +1,9 @@
+package ts.cmd;
+
+import ts.client.Location;
+
+public interface ITypeScriptLinterHandler {
+
+ void addError(String file, Location startLoc, Location endLoc,
+ Severity severity, String code, String message);
+}
diff --git a/typescript.java-ts.core/src/main/java/ts/cmd/Severity.java b/typescript.java-ts.core/src/main/java/ts/cmd/Severity.java
new file mode 100644
index 00000000..f075475e
--- /dev/null
+++ b/typescript.java-ts.core/src/main/java/ts/cmd/Severity.java
@@ -0,0 +1,7 @@
+package ts.cmd;
+
+public enum Severity {
+
+ error, warning, info;
+
+}
diff --git a/typescript.java-ts.core/src/main/java/ts/cmd/tsc/CompilerOptionCapability.java b/typescript.java-ts.core/src/main/java/ts/cmd/tsc/CompilerOptionCapability.java
new file mode 100644
index 00000000..33b88f03
--- /dev/null
+++ b/typescript.java-ts.core/src/main/java/ts/cmd/tsc/CompilerOptionCapability.java
@@ -0,0 +1,26 @@
+package ts.cmd.tsc;
+
+import ts.utils.VersionHelper;
+
+public enum CompilerOptionCapability {
+
+ listEmittedFiles("2.0.0");
+
+ private String sinceVersion;
+
+ private CompilerOptionCapability(String version) {
+ this.sinceVersion = version;
+ }
+
+ /**
+ * Return true if the tsc compiler option support the given version and
+ * false otherwise.
+ *
+ * @param version
+ * @return true if the tsc compiler option support the given version and
+ * false otherwise.
+ */
+ public boolean canSupport(String version) {
+ return VersionHelper.canSupport(version, sinceVersion);
+ }
+}
diff --git a/typescript.java-ts.core/src/main/java/ts/cmd/tsc/CompilerOptions.java b/typescript.java-ts.core/src/main/java/ts/cmd/tsc/CompilerOptions.java
new file mode 100644
index 00000000..262a9464
--- /dev/null
+++ b/typescript.java-ts.core/src/main/java/ts/cmd/tsc/CompilerOptions.java
@@ -0,0 +1,1305 @@
+package ts.cmd.tsc;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import ts.cmd.AbstractOptions;
+import ts.utils.BooleanUtils;
+
+/**
+ * Instructs the TypeScript compiler how to compile .ts files.
+ *
+ * @see http://json.schemastore.org/tsconfig
+ * @se https://www.typescriptlang.org/docs/handbook/compiler-html
+ *
+ */
+public class CompilerOptions extends AbstractOptions {
+
+ private Boolean allowJs;
+ private Boolean allowSyntheticDefaultImports;
+ private Boolean allowUnreachableCode;
+ private Boolean allowUnusedLabels;
+ private String charset;
+ private Boolean declaration;
+ private Boolean diagnostics;
+ private Boolean emitBOM;
+ private Boolean emitDecoratorMetadata;
+ private Boolean experimentalDecorators;
+ private Boolean forceConsistentCasingInFileNames;
+ private Boolean help;
+ private Boolean inlineSourceMap;
+ private Boolean inlineSources;
+ private Boolean init;
+ private Boolean isolatedModules;
+ private String jsx;
+ private Boolean listEmittedFiles;
+ private Boolean listFiles;
+ private String locale;
+ private String mapRoot;
+ private String module;
+ private String moduleResolution;
+ private String newLine;
+ private Boolean noEmit;
+ private Boolean noEmitHelpers;
+ private Boolean noEmitOnError;
+ private Boolean noFallthroughCasesInSwitch;
+ private Boolean noImplicitAny;
+ private Boolean noImplicitReturns;
+ private Boolean noImplicitUseStrict;
+ private Boolean noLib;
+ private Boolean noResolve;
+ private String out;
+ private String outDir;
+ private String outFile;
+ private Map> paths;
+ private Boolean preserveConstEnums;
+ private Boolean pretty;
+ private String project;
+ private String reactNamespace;
+ private Boolean removeComments;
+ private String rootDir;
+ private List rootDirs;
+ private Boolean skipDefaultLibCheck;
+ private Boolean sourceMap;
+ private String sourceRoot;
+ private Boolean strictNullChecks;
+ private Boolean stripInternal;
+ private Boolean suppressExcessPropertyErrors;
+ private Boolean suppressImplicitAnyIndexErrors;
+ private String target;
+ private Boolean traceResolution;
+ private Boolean version;
+ private Boolean watch;
+
+ private List plugins;
+
+ public CompilerOptions() {
+ }
+
+ public CompilerOptions(CompilerOptions options) {
+ this.setAllowJs(options.allowJs);
+ this.setAllowSyntheticDefaultImports(options.allowSyntheticDefaultImports);
+ this.setAllowUnreachableCode(options.allowUnreachableCode);
+ this.setAllowUnusedLabels(options.allowUnusedLabels);
+ this.setCharset(options.charset);
+ this.setDeclaration(options.declaration);
+ this.setDiagnostics(options.diagnostics);
+ this.setEmitBOM(options.emitBOM);
+ this.setEmitDecoratorMetadata(options.emitDecoratorMetadata);
+ this.setExperimentalDecorators(options.experimentalDecorators);
+ this.setForceConsistentCasingInFileNames(options.forceConsistentCasingInFileNames);
+ this.setHelp(options.help);
+ this.setInlineSourceMap(options.inlineSourceMap);
+ this.setInlineSources(options.inlineSources);
+ this.setInit(options.init);
+ this.setIsolatedModules(options.isolatedModules);
+ this.setJsx(options.jsx);
+ this.setListEmittedFiles(options.listEmittedFiles);
+ this.setListFiles(options.listFiles);
+ this.setLocale(options.locale);
+ this.setMapRoot(options.mapRoot);
+ this.setModule(options.module);
+ this.setModuleResolution(options.moduleResolution);
+ this.setNewLine(options.newLine);
+ this.setNoEmit(options.noEmit);
+ this.setNoEmitHelpers(options.noEmitHelpers);
+ this.setNoEmitOnError(options.noEmitOnError);
+ this.setNoFallthroughCasesInSwitch(options.noFallthroughCasesInSwitch);
+ this.setNoImplicitAny(options.noImplicitAny);
+ this.setNoImplicitReturns(options.noImplicitReturns);
+ this.setNoImplicitUseStrict(options.noImplicitUseStrict);
+ this.setNoLib(options.noLib);
+ this.setNoResolve(options.noResolve);
+ this.setOut(options.out);
+ this.setOutDir(options.outDir);
+ this.setOutFile(options.outFile);
+ this.setPreserveConstEnums(options.preserveConstEnums);
+ this.setPretty(options.pretty);
+ this.setProject(options.project);
+ this.setReactNamespace(options.reactNamespace);
+ this.setRemoveComments(options.removeComments);
+ this.setRootDir(options.rootDir);
+ this.setSkipDefaultLibCheck(options.skipDefaultLibCheck);
+ this.setSourceMap(options.sourceMap);
+ this.setSourceRoot(options.sourceRoot);
+ this.setStrictNullChecks(options.strictNullChecks);
+ this.setStripInternal(options.stripInternal);
+ this.setSuppressExcessPropertyErrors(options.suppressExcessPropertyErrors);
+ this.setSuppressImplicitAnyIndexErrors(options.suppressImplicitAnyIndexErrors);
+ this.setTarget(options.target);
+ this.setTraceResolution(options.traceResolution);
+ this.setVersion(options.version);
+ this.setWatch(options.watch);
+ }
+
+ /**
+ * Returns true if allow JavaScript files to be compiled and false
+ * otherwise.
+ *
+ * @return true if allow JavaScript files to be compiled and false
+ * otherwise.
+ */
+ public Boolean isAllowJs() {
+ return BooleanUtils.toBoolean(allowJs);
+ }
+
+ /**
+ * Allow JavaScript files to be compiled.
+ *
+ * @param allowJs
+ */
+ public void setAllowJs(Boolean allowJs) {
+ this.allowJs = allowJs;
+ }
+
+ /**
+ * Allow default imports from modules with no default export. This does not
+ * affect code emit, just typechecking.
+ *
+ * @return
+ */
+ public boolean isAllowSyntheticDefaultImports() {
+ return BooleanUtils.toBoolean(allowSyntheticDefaultImports);
+ }
+
+ /**
+ * Allow default imports from modules with no default export. This does not
+ * affect code emit, just typechecking.
+ *
+ * @param allowSyntheticDefaultImports
+ */
+ public void setAllowSyntheticDefaultImports(Boolean allowSyntheticDefaultImports) {
+ this.allowSyntheticDefaultImports = allowSyntheticDefaultImports;
+ }
+
+ /**
+ * Do not report errors on unreachable code.
+ *
+ * @return
+ */
+ public boolean isAllowUnreachableCode() {
+ return BooleanUtils.toBoolean(allowUnreachableCode);
+ }
+
+ /**
+ * Do not report errors on unreachable code.
+ *
+ * @param allowUnreachableCode
+ */
+ public void setAllowUnreachableCode(Boolean allowUnreachableCode) {
+ this.allowUnreachableCode = allowUnreachableCode;
+ }
+
+ /**
+ * Do not report errors on unused labels.
+ *
+ * @return
+ */
+ public boolean isAllowUnusedLabels() {
+ return BooleanUtils.toBoolean(allowUnusedLabels);
+ }
+
+ /**
+ * Do not report errors on unused labels.
+ *
+ * @param allowUnusedLabels
+ */
+ public void setAllowUnusedLabels(Boolean allowUnusedLabels) {
+ this.allowUnusedLabels = allowUnusedLabels;
+ }
+
+ /**
+ * Returns the character set of the input files.
+ *
+ * @return the character set of the input files.
+ */
+ public String getCharset() {
+ return charset;
+ }
+
+ /**
+ * The character set of the input files.
+ *
+ * @param charset
+ */
+ public void setCharset(String charset) {
+ this.charset = charset;
+ }
+
+ /**
+ * Returns true of generates corresponding d.ts files and false otherwise.
+ *
+ * @return true of generates corresponding d.ts files and false otherwise.
+ */
+ public boolean isDeclaration() {
+ return BooleanUtils.toBoolean(declaration);
+ }
+
+ /**
+ * Set to true of generates corresponding d.ts files and false otherwise.
+ *
+ * @param declaration
+ */
+ public void setDeclaration(Boolean declaration) {
+ this.declaration = declaration;
+ }
+
+ /**
+ * Show diagnostic information.
+ *
+ * @return
+ */
+ public boolean isDiagnostics() {
+ return BooleanUtils.toBoolean(diagnostics);
+ }
+
+ /**
+ * Show diagnostic information.
+ *
+ * @param diagnostics
+ */
+ public void setDiagnostics(Boolean diagnostics) {
+ this.diagnostics = diagnostics;
+ }
+
+ /**
+ * Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files.
+ *
+ * @return
+ */
+ public boolean isEmitBOM() {
+ return BooleanUtils.toBoolean(emitBOM);
+ }
+
+ /**
+ * Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files.
+ *
+ * @param emitBOM
+ */
+ public void setEmitBOM(Boolean emitBOM) {
+ this.emitBOM = emitBOM;
+ }
+
+ /**
+ * Emit design-type metadata for decorated declarations in source. See issue
+ * https://github.com/Microsoft/TypeScript/issues/2577 for details.
+ *
+ * @return
+ */
+ public boolean isEmitDecoratorMetadata() {
+ return BooleanUtils.toBoolean(emitDecoratorMetadata);
+ }
+
+ /**
+ * Emit design-type metadata for decorated declarations in source. See issue
+ * https://github.com/Microsoft/TypeScript/issues/2577 for details.
+ *
+ * @param emitDecoratorMetadata
+ */
+ public void setEmitDecoratorMetadata(Boolean emitDecoratorMetadata) {
+ this.emitDecoratorMetadata = emitDecoratorMetadata;
+ }
+
+ /**
+ * Enables experimental support for ES7 decorators.
+ *
+ * @return
+ */
+ public boolean isExperimentalDecorators() {
+ return BooleanUtils.toBoolean(experimentalDecorators);
+ }
+
+ /**
+ * Enables experimental support for ES7 decorators.
+ *
+ * @param experimentalDecorators
+ */
+ public void setExperimentalDecorators(Boolean experimentalDecorators) {
+ this.experimentalDecorators = experimentalDecorators;
+ }
+
+ /**
+ * Disallow inconsistently-cased references to the same file.
+ *
+ * @return
+ */
+ public boolean isForceConsistentCasingInFileNames() {
+ return BooleanUtils.toBoolean(forceConsistentCasingInFileNames);
+ }
+
+ /**
+ * Disallow inconsistently-cased references to the same file.
+ *
+ * @param forceConsistentCasingInFileNames
+ */
+ public void setForceConsistentCasingInFileNames(Boolean forceConsistentCasingInFileNames) {
+ this.forceConsistentCasingInFileNames = forceConsistentCasingInFileNames;
+ }
+
+ /**
+ * Print help message.
+ *
+ * @return
+ */
+ public boolean isHelp() {
+ return BooleanUtils.toBoolean(help);
+ }
+
+ /**
+ * Print help message.
+ *
+ * @param help
+ */
+ public void setHelp(Boolean help) {
+ this.help = help;
+ }
+
+ /**
+ * Emit a single file with source maps instead of having a separate file.
+ *
+ * @return
+ */
+ public boolean isInlineSourceMap() {
+ return BooleanUtils.toBoolean(inlineSourceMap);
+ }
+
+ /**
+ * Emit a single file with source maps instead of having a separate file.
+ *
+ * @param inlineSourceMap
+ */
+ public void setInlineSourceMap(Boolean inlineSourceMap) {
+ this.inlineSourceMap = inlineSourceMap;
+ }
+
+ /**
+ * Emit the source alongside the sourcemaps within a single file; requires
+ * --inlineSourceMap or --sourceMap to be set.
+ *
+ * @return
+ */
+ public boolean isInlineSources() {
+ return BooleanUtils.toBoolean(inlineSources);
+ }
+
+ /**
+ * Emit the source alongside the sourcemaps within a single file; requires
+ * --inlineSourceMap or --sourceMap to be set.
+ *
+ * @param inlineSources
+ */
+ public void setInlineSources(Boolean inlineSources) {
+ this.inlineSources = inlineSources;
+ }
+
+ /**
+ * Initializes a TypeScript project and creates a tsconfig.json file.
+ *
+ * @return
+ */
+ public boolean isInit() {
+ return BooleanUtils.toBoolean(init);
+ }
+
+ /**
+ * Initializes a TypeScript project and creates a tsconfig.json file.
+ *
+ * @param init
+ */
+ public void setInit(Boolean init) {
+ this.init = init;
+ }
+
+ /**
+ * Unconditionally emit imports for unresolved files.
+ *
+ * @return
+ */
+ public boolean isIsolatedModules() {
+ return BooleanUtils.toBoolean(isolatedModules);
+ }
+
+ /**
+ * Unconditionally emit imports for unresolved files.
+ *
+ * @param isolatedModules
+ */
+ public void setIsolatedModules(Boolean isolatedModules) {
+ this.isolatedModules = isolatedModules;
+ }
+
+ /**
+ * Support JSX in ‘.tsx’ files: 'React' or 'Preserve'.
+ *
+ * @see https://www.typescriptlang.org/docs/handbook/jsx.html
+ *
+ * @return
+ */
+ public String getJsx() {
+ return jsx;
+ }
+
+ /**
+ * Support JSX in ‘.tsx’ files: 'React' or 'Preserve'.
+ *
+ * @see https://www.typescriptlang.org/docs/handbook/jsx.html
+ *
+ * @param jsx
+ */
+ public void setJsx(String jsx) {
+ this.jsx = jsx;
+ }
+
+ /**
+ * Print names of generated files part of the compilation.
+ *
+ * @return
+ */
+ public boolean isListEmittedFiles() {
+ return BooleanUtils.toBoolean(listEmittedFiles);
+ }
+
+ /**
+ * Print names of generated files part of the compilation.
+ *
+ * @param listEmittedFiles
+ */
+ public void setListEmittedFiles(Boolean listEmittedFiles) {
+ this.listEmittedFiles = listEmittedFiles;
+ }
+
+ /**
+ * Returns Print names of files part of the compilation.
+ *
+ * @return
+ *
+ */
+ public boolean isListFiles() {
+ return BooleanUtils.toBoolean(listFiles);
+ }
+
+ /**
+ * Set Print names of files part of the compilation.
+ *
+ * @param listFiles
+ */
+ public void setListFiles(Boolean listFiles) {
+ this.listFiles = listFiles;
+ }
+
+ /**
+ * The locale to use to show error messages, e.g. en-us.
+ *
+ * @return
+ */
+ public String getLocale() {
+ return locale;
+ }
+
+ /**
+ * The locale to use to show error messages, e.g. en-us.
+ *
+ * @param locale
+ */
+ public void setLocale(String locale) {
+ this.locale = locale;
+ }
+
+ /**
+ * Specifies the location where debugger should locate map files instead of
+ * generated locations. Use this flag if the .map files will be located at
+ * run-time in a different location than than the .js files. The location
+ * specified will be embedded in the sourceMap to direct the debugger where
+ * the map files where be located.
+ *
+ * @return
+ */
+ public String getMapRoot() {
+ return mapRoot;
+ }
+
+ /**
+ * Specifies the location where debugger should locate map files instead of
+ * generated locations. Use this flag if the .map files will be located at
+ * run-time in a different location than than the .js files. The location
+ * specified will be embedded in the sourceMap to direct the debugger where
+ * the map files where be located.
+ *
+ * @param mapRoot
+ */
+ public void setMapRoot(String mapRoot) {
+ this.mapRoot = mapRoot;
+ }
+
+ /**
+ * Specify module code generation: 'none', 'commonjs', 'amd', 'system',
+ * 'umd', 'es6', or 'es2015'. ► Only 'amd' and 'system' can be used in
+ * conjunction with --outFile. ► 'es6' and 'es2015' values may not be used
+ * when targeting ES5 or lower.
+ *
+ * @return
+ */
+ public String getModule() {
+ return module;
+ }
+
+ /**
+ * Specify module code generation: 'none', 'commonjs', 'amd', 'system',
+ * 'umd', 'es6', or 'es2015'. ► Only 'amd' and 'system' can be used in
+ * conjunction with --outFile. ► 'es6' and 'es2015' values may not be used
+ * when targeting ES5 or lower.
+ *
+ * @param module
+ */
+ public void setModule(String module) {
+ this.module = module;
+ }
+
+ /**
+ * Determine how modules get resolved. Either 'node' for Node.js/io.js style
+ * resolution, or 'classic' (default). See
+ * https://www.typescriptlang.org/docs/handbook/module-resolution.html
+ * documentation for more details.
+ *
+ * @return
+ */
+ public String getModuleResolution() {
+ return moduleResolution;
+ }
+
+ /**
+ * Determine how modules get resolved. Either 'node' for Node.js/io.js style
+ * resolution, or 'classic' (default). See
+ * https://www.typescriptlang.org/docs/handbook/module-resolution.html
+ * documentation for more details.
+ *
+ * @param moduleResolution
+ */
+ public void setModuleResolution(String moduleResolution) {
+ this.moduleResolution = moduleResolution;
+ }
+
+ /**
+ * Use the specified end of line sequence to be used when emitting files:
+ * 'crlf' (windows) or 'lf' (unix).”
+ *
+ * @return
+ */
+ public String getNewLine() {
+ return newLine;
+ }
+
+ /**
+ * Use the specified end of line sequence to be used when emitting files:
+ * 'crlf' (windows) or 'lf' (unix).”
+ *
+ * @param newLine
+ */
+ public void setNewLine(String newLine) {
+ this.newLine = newLine;
+ }
+
+ /**
+ * Do not emit outputs.
+ *
+ * @return
+ */
+ public boolean isNoEmit() {
+ return BooleanUtils.toBoolean(noEmit);
+ }
+
+ /**
+ * Do not emit outputs.
+ *
+ * @param noEmit
+ */
+ public void setNoEmit(Boolean noEmit) {
+ this.noEmit = noEmit;
+ }
+
+ /**
+ * Do not generate custom helper functions like __extends in compiled
+ * output.
+ *
+ * @return
+ */
+ public boolean isNoEmitHelpers() {
+ return BooleanUtils.toBoolean(noEmitHelpers);
+ }
+
+ /**
+ * Do not generate custom helper functions like __extends in compiled
+ * output.
+ *
+ * @param noEmitHelpers
+ */
+ public void setNoEmitHelpers(Boolean noEmitHelpers) {
+ this.noEmitHelpers = noEmitHelpers;
+ }
+
+ /**
+ * Do not emit outputs if any errors were reported.
+ *
+ * @return
+ */
+ public boolean isNoEmitOnError() {
+ return BooleanUtils.toBoolean(noEmitOnError);
+ }
+
+ /**
+ * Do not emit outputs if any errors were reported.
+ *
+ * @param noEmitOnError
+ */
+ public void setNoEmitOnError(Boolean noEmitOnError) {
+ this.noEmitOnError = noEmitOnError;
+ }
+
+ /**
+ * Report errors for fallthrough cases in switch statement.
+ *
+ * @return
+ */
+ public boolean isNoFallthroughCasesInSwitch() {
+ return BooleanUtils.toBoolean(noFallthroughCasesInSwitch);
+ }
+
+ /**
+ * Report errors for fallthrough cases in switch statement.
+ *
+ * @param noFallthroughCasesInSwitch
+ */
+ public void setNoFallthroughCasesInSwitch(Boolean noFallthroughCasesInSwitch) {
+ this.noFallthroughCasesInSwitch = noFallthroughCasesInSwitch;
+ }
+
+ /**
+ * Raise error on expressions and declarations with an implied ‘any’ type.
+ *
+ * @return
+ */
+ public boolean isNoImplicitAny() {
+ return BooleanUtils.toBoolean(noImplicitAny);
+ }
+
+ /**
+ * Raise error on expressions and declarations with an implied ‘any’ type.
+ *
+ * @param noImplicitAny
+ */
+ public void setNoImplicitAny(Boolean noImplicitAny) {
+ this.noImplicitAny = noImplicitAny;
+ }
+
+ /**
+ * Report error when not all code paths in function return a value.
+ *
+ * @return
+ */
+ public boolean isNoImplicitReturns() {
+ return BooleanUtils.toBoolean(noImplicitReturns);
+ }
+
+ /**
+ * Report error when not all code paths in function return a value.
+ *
+ * @param noImplicitReturns
+ */
+ public void setNoImplicitReturns(Boolean noImplicitReturns) {
+ this.noImplicitReturns = noImplicitReturns;
+ }
+
+ /**
+ * Do not emit "use strict" directives in module output.
+ *
+ * @return
+ */
+ public boolean isNoImplicitUseStrict() {
+ return BooleanUtils.toBoolean(noImplicitUseStrict);
+ }
+
+ /**
+ * Do not emit "use strict" directives in module output.
+ *
+ * @param noImplicitUseStrict
+ */
+ public void setNoImplicitUseStrict(Boolean noImplicitUseStrict) {
+ this.noImplicitUseStrict = noImplicitUseStrict;
+ }
+
+ /**
+ * Do not include the default library file (lib.d.ts).
+ *
+ * @return
+ */
+ public boolean isNoLib() {
+ return BooleanUtils.toBoolean(noLib);
+ }
+
+ /**
+ * Do not include the default library file (lib.d.ts).
+ *
+ * @param noLib
+ */
+ public void setNoLib(Boolean noLib) {
+ this.noLib = noLib;
+ }
+
+ /**
+ * Do not add triple-slash references or module import targets to the list
+ * of compiled files.
+ *
+ * @return
+ */
+ public boolean isNoResolve() {
+ return BooleanUtils.toBoolean(noResolve);
+ }
+
+ /**
+ * Do not add triple-slash references or module import targets to the list
+ * of compiled files.
+ *
+ * @param noResolve
+ */
+ public void setNoResolve(Boolean noResolve) {
+ this.noResolve = noResolve;
+ }
+
+ /**
+ * Same thing than outFile but deprectaed.
+ *
+ * @return
+ */
+ public String getOut() {
+ return out;
+ }
+
+ /**
+ * Same thing than outFile but deprectaed.
+ *
+ * @param out
+ */
+ public void setOut(String out) {
+ this.out = out;
+ }
+
+ /**
+ * Redirect output structure to the directory.
+ *
+ * @return
+ */
+ public String getOutDir() {
+ return outDir;
+ }
+
+ /**
+ * Redirect output structure to the directory.
+ *
+ * @param outDir
+ */
+ public void setOutDir(String outDir) {
+ this.outDir = outDir;
+ }
+
+ /**
+ * Concatenate and emit output to single file. The order of concatenation is
+ * determined by the list of files passed to the compiler on the command
+ * line along with triple-slash references and imports. See output file
+ * order documentation for more details.
+ *
+ * @return
+ */
+ public String getOutFile() {
+ return outFile;
+ }
+
+ /**
+ * Concatenate and emit output to single file. The order of concatenation is
+ * determined by the list of files passed to the compiler on the command
+ * line along with triple-slash references and imports. See output file
+ * order documentation for more details.
+ *
+ * @param outFile
+ */
+ public void setOutFile(String outFile) {
+ this.outFile = outFile;
+ }
+
+ /**
+ * Specify path mapping to be computed relative to baseUrl option.
+ *
+ * @return key patterns to which paths are mapped.
+ */
+ public Set getPathsKeys() {
+ if (paths == null) {
+ return Collections.emptySet();
+ }
+ return Collections.unmodifiableSet(paths.keySet());
+ }
+
+ /**
+ * Specify path mapping to be computed relative to baseUrl option.
+ *
+ * @param pathsKey
+ * a path key pattern.
+ * @return paths mapped to the key pattern.
+ */
+ public List getPathsKeyValues(String pathsKey) {
+ if (paths == null) {
+ return Collections.emptyList();
+ }
+ List values = paths.get(pathsKey);
+ if (values == null) {
+ return Collections.emptyList();
+ }
+ return Collections.unmodifiableList(values);
+ }
+
+ /**
+ * Specify path mapping to be computed relative to baseUrl option.
+ *
+ * @param paths
+ */
+ public void setPaths(Map> paths) {
+ Map> pathsCopy = new HashMap<>(paths.size());
+ for (Map.Entry> entry : paths.entrySet()) {
+ pathsCopy.put(entry.getKey(), new ArrayList<>(entry.getValue()));
+ }
+ this.paths = pathsCopy;
+ }
+
+ /**
+ * Do not erase const enum declarations in generated code. See const enums
+ * https://github.com/Microsoft/TypeScript/blob/master/doc/spec.md#94-constant-enum-declarations
+ * documentation for more details.
+ *
+ * @return
+ */
+ public boolean isPreserveConstEnums() {
+ return BooleanUtils.toBoolean(preserveConstEnums);
+ }
+
+ /**
+ * Do not erase const enum declarations in generated code. See const enums
+ * https://github.com/Microsoft/TypeScript/blob/master/doc/spec.md#94-constant-enum-declarations
+ * documentation for more details.
+ *
+ * @param preserveConstEnums
+ */
+ public void setPreserveConstEnums(Boolean preserveConstEnums) {
+ this.preserveConstEnums = preserveConstEnums;
+ }
+
+ /**
+ * Stylize errors and messages using color and context.
+ *
+ * @return
+ */
+ public boolean isPretty() {
+ return BooleanUtils.toBoolean(pretty);
+ }
+
+ /**
+ * Stylize errors and messages using color and context.
+ *
+ * @param pretty
+ */
+ public void setPretty(Boolean pretty) {
+ this.pretty = pretty;
+ }
+
+ /**
+ * Compile the project in the given directory. The directory needs to
+ * contain a tsconfig.json file to direct compilation. See tsconfig.json
+ * documentation for more details.
+ *
+ * @return
+ */
+ public String getProject() {
+ return project;
+ }
+
+ /**
+ * Compile the project in the given directory. The directory needs to
+ * contain a tsconfig.json file to direct compilation. See tsconfig.json
+ * documentation for more details.
+ *
+ * @param project
+ */
+ public void setProject(String project) {
+ this.project = project;
+ }
+
+ /**
+ * Specifies the object invoked for createElement and __spread when
+ * targeting ‘react’ JSX emit.
+ *
+ * @return
+ */
+ public String getReactNamespace() {
+ return reactNamespace;
+ }
+
+ /**
+ * Specifies the object invoked for createElement and __spread when
+ * targeting ‘react’ JSX emit.
+ *
+ * @param reactNamespace
+ */
+ public void setReactNamespace(String reactNamespace) {
+ this.reactNamespace = reactNamespace;
+ }
+
+ /**
+ * Remove all comments except copy-right header comments beginning with /*!
+ *
+ * @return
+ */
+ public boolean isRemoveComments() {
+ return BooleanUtils.toBoolean(removeComments);
+ }
+
+ /**
+ * Remove all comments except copy-right header comments beginning with /*!
+ *
+ * @param removeComments
+ */
+ public void setRemoveComments(Boolean removeComments) {
+ this.removeComments = removeComments;
+ }
+
+ /**
+ * Specifies the root directory of input files. Only use to control the
+ * output directory structure with --outDir.
+ *
+ * @return
+ */
+ public String getRootDir() {
+ return rootDir;
+ }
+
+ /**
+ * Specifies the root directory of input files. Only use to control the
+ * output directory structure with --outDir.
+ *
+ * @param rootDir
+ */
+ public void setRootDir(String rootDir) {
+ this.rootDir = rootDir;
+ }
+
+ /**
+ * Specify list of root directory to be used when resolving modules.
+ *
+ * @return
+ */
+ public List getRootDirs() {
+ if (rootDirs == null) {
+ return Collections.emptyList();
+ }
+ return Collections.unmodifiableList(rootDirs);
+ }
+
+ /**
+ * Specify list of root directory to be used when resolving modules.
+ *
+ * @param rootDirs
+ */
+ public void setRootDirs(List rootDirs) {
+ this.rootDirs = new ArrayList<>(rootDirs);
+ }
+
+ /**
+ * Don’t check a user-defined default lib file’s valitidy.
+ *
+ * @return
+ */
+ public boolean isSkipDefaultLibCheck() {
+ return BooleanUtils.toBoolean(skipDefaultLibCheck);
+ }
+
+ /**
+ * Don’t check a user-defined default lib file’s valitidy.
+ *
+ * @param skipDefaultLibCheck
+ */
+ public void setSkipDefaultLibCheck(Boolean skipDefaultLibCheck) {
+ this.skipDefaultLibCheck = skipDefaultLibCheck;
+ }
+
+ /**
+ * Generates corresponding '.map' file.
+ *
+ * @return
+ */
+ public boolean isSourceMap() {
+ return BooleanUtils.toBoolean(sourceMap);
+ }
+
+ /**
+ * Generates corresponding '.map' file.
+ *
+ * @param sourceMap
+ */
+ public void setSourceMap(Boolean sourceMap) {
+ this.sourceMap = sourceMap;
+ }
+
+ /**
+ * Specifies the location where debugger should locate TypeScript files
+ * instead of source locations. Use this flag if the sources will be located
+ * at run-time in a different location than that at design-time. The
+ * location specified will be embedded in the sourceMap to direct the
+ * debugger where the source files where be located.
+ *
+ * @return
+ */
+ public String getSourceRoot() {
+ return sourceRoot;
+ }
+
+ /**
+ * Specifies the location where debugger should locate TypeScript files
+ * instead of source locations. Use this flag if the sources will be located
+ * at run-time in a different location than that at design-time. The
+ * location specified will be embedded in the sourceMap to direct the
+ * debugger where the source files where be located.
+ *
+ * @param sourceRoot
+ */
+ public void setSourceRoot(String sourceRoot) {
+ this.sourceRoot = sourceRoot;
+ }
+
+ /**
+ * In strict null checking mode, the null and undefined values are not in
+ * the domain of every type and are only assignable to themselves and any
+ * (the one exception being that undefined is also assignable to void).
+ *
+ * @return
+ */
+ public boolean isStrictNullChecks() {
+ return BooleanUtils.toBoolean(strictNullChecks);
+ }
+
+ /**
+ * In strict null checking mode, the null and undefined values are not in
+ * the domain of every type and are only assignable to themselves and any
+ * (the one exception being that undefined is also assignable to void).
+ *
+ * @param strictNullChecks
+ */
+ public void setStrictNullChecks(Boolean strictNullChecks) {
+ this.strictNullChecks = strictNullChecks;
+ }
+
+ /**
+ * Do not emit declarations for code that has an @internal JSDoc annotation.
+ *
+ * @return
+ */
+ public boolean isStripInternal() {
+ return BooleanUtils.toBoolean(stripInternal);
+ }
+
+ /**
+ * Do not emit declarations for code that has an @internal JSDoc annotation.
+ *
+ * @param stripInternal
+ */
+ public void setStripInternal(Boolean stripInternal) {
+ this.stripInternal = stripInternal;
+ }
+
+ /**
+ * Suppress excess property checks for object literals.
+ *
+ * @return
+ */
+ public boolean isSuppressExcessPropertyErrors() {
+ return BooleanUtils.toBoolean(suppressExcessPropertyErrors);
+ }
+
+ /**
+ * Suppress excess property checks for object literals.
+ *
+ * @param suppressExcessPropertyErrors
+ */
+ public void setSuppressExcessPropertyErrors(Boolean suppressExcessPropertyErrors) {
+ this.suppressExcessPropertyErrors = suppressExcessPropertyErrors;
+ }
+
+ /**
+ * Suppress --noImplicitAny errors for indexing objects lacking index
+ * signatures. See issue #1232
+ * https://github.com/Microsoft/TypeScript/issues/1232#issuecomment-64510362
+ * for more details.
+ *
+ * @return
+ */
+ public boolean isSuppressImplicitAnyIndexErrors() {
+ return BooleanUtils.toBoolean(suppressImplicitAnyIndexErrors);
+ }
+
+ /**
+ * Suppress --noImplicitAny errors for indexing objects lacking index
+ * signatures. See issue #1232
+ * https://github.com/Microsoft/TypeScript/issues/1232#issuecomment-64510362
+ * for more details.
+ *
+ * @param suppressImplicitAnyIndexErrors
+ */
+ public void setSuppressImplicitAnyIndexErrors(Boolean suppressImplicitAnyIndexErrors) {
+ this.suppressImplicitAnyIndexErrors = suppressImplicitAnyIndexErrors;
+ }
+
+ /**
+ * Specify ECMAScript target version: 'es3' (default), 'es5', or 'es6'.
+ *
+ * @return
+ */
+ public String getTarget() {
+ return target;
+ }
+
+ /**
+ * Specify ECMAScript target version: 'es3' (default), 'es5', or 'es6'.
+ *
+ * @param target
+ */
+ public void setTarget(String target) {
+ this.target = target;
+ }
+
+ /**
+ * Report module resolution log messages.
+ *
+ * @return
+ */
+ public boolean isTraceResolution() {
+ return BooleanUtils.toBoolean(traceResolution);
+ }
+
+ /**
+ * Report module resolution log messages.
+ *
+ * @param traceResolution
+ */
+ public void setTraceResolution(Boolean traceResolution) {
+ this.traceResolution = traceResolution;
+ }
+
+ /**
+ * Print the compiler’s version.
+ *
+ * @return
+ */
+ public boolean isVersion() {
+ return BooleanUtils.toBoolean(version);
+ }
+
+ /**
+ * Print the compiler’s version.
+ *
+ * @param version
+ */
+ public void setVersion(Boolean version) {
+ this.version = version;
+ }
+
+ /**
+ * Run the compiler in watch mode. Watch input files and trigger
+ * recompilation on changes.
+ *
+ * @param watch
+ */
+ public void setWatch(Boolean watch) {
+ this.watch = watch;
+ }
+
+ /**
+ * Run the compiler in watch mode. Watch input files and trigger
+ * recompilation on changes.
+ *
+ * @return
+ */
+ public Boolean isWatch() {
+ return BooleanUtils.toBoolean(watch);
+ }
+
+ public List getPlugins() {
+ return plugins;
+ }
+
+ public void setPlugins(List plugins) {
+ this.plugins = plugins;
+ }
+
+ public void fillOptions(List args) {
+ if (isHelp()) {
+ args.add("--help");
+ return;
+ }
+ if (isVersion()) {
+ args.add("--version");
+ return;
+ }
+ fillOption("--allowJs", isAllowJs(), args);
+ fillOption("--allowSyntheticDefaultImports", isAllowSyntheticDefaultImports(), args);
+ fillOption("--allowUnreachableCode", isAllowUnreachableCode(), args);
+ fillOption("--allowUnusedLabels", isAllowUnusedLabels(), args);
+ fillOption("--charset", getCharset(), args);
+ fillOption("--declaration", isDeclaration(), args);
+ fillOption("--diagnostics", isDiagnostics(), args);
+ fillOption("--emitBOM", isEmitBOM(), args);
+ fillOption("--emitDecoratorMetadata", isEmitDecoratorMetadata(), args);
+ fillOption("--experimentalDecorators", isExperimentalDecorators(), args);
+ fillOption("--forceConsistentCasingInFileNames", isForceConsistentCasingInFileNames(), args);
+ fillOption("--inlineSourceMap", isInlineSourceMap(), args);
+ fillOption("--inlineSources", isInlineSources(), args);
+ fillOption("--init", isInit(), args);
+ fillOption("--isolatedModules", isIsolatedModules(), args);
+ fillOption("--jsx", getJsx(), args);
+ fillOption("--listEmittedFiles", isListEmittedFiles(), args);
+ fillOption("--listFiles", isListFiles(), args);
+ fillOption("--locale", getLocale(), args);
+ fillOption("--mapRoot", getMapRoot(), args);
+ fillOption("--module", getModule(), args);
+ fillOption("--moduleResolution", getModuleResolution(), args);
+ fillOption("--newLine", getNewLine(), args);
+ fillOption("--noEmit", isNoEmit(), args);
+ fillOption("--noEmitHelpers", isNoEmitHelpers(), args);
+ fillOption("--noEmitOnError", isNoEmitOnError(), args);
+ fillOption("--noEmitOnError", isNoEmitOnError(), args);
+ fillOption("--noFallthroughCasesInSwitch", isNoFallthroughCasesInSwitch(), args);
+ fillOption("--noImplicitAny", isNoImplicitAny(), args);
+ fillOption("--noImplicitReturns", isNoImplicitReturns(), args);
+ fillOption("--noImplicitUseStrict", isNoImplicitUseStrict(), args);
+ fillOption("--noLib", isNoLib(), args);
+ fillOption("--noResolve", isNoResolve(), args);
+ fillOption("--out", getOut(), args);
+ fillOption("--outDir", getOutDir(), args);
+ fillOption("--outFile", getOutFile(), args);
+ fillOption("--preserveConstEnums", isPreserveConstEnums(), args);
+ fillOption("--pretty", isPretty(), args);
+ fillOption("--project", getProject(), args);
+ fillOption("--reactNamespace", getReactNamespace(), args);
+ fillOption("--removeComments", isRemoveComments(), args);
+ fillOption("--rootDir", getRootDir(), args);
+ fillOption("--skipDefaultLibCheck", isSkipDefaultLibCheck(), args);
+ fillOption("--sourceMap", isSourceMap(), args);
+ fillOption("--strictNullChecks", isStrictNullChecks(), args);
+ fillOption("--stripInternal", isStripInternal(), args);
+ fillOption("--suppressExcessPropertyErrors", isSuppressExcessPropertyErrors(), args);
+ fillOption("--suppressImplicitAnyIndexErrors", isSuppressImplicitAnyIndexErrors(), args);
+ fillOption("--target", getTarget(), args);
+ fillOption("--traceResolution", isTraceResolution(), args);
+ fillOption("--version", isVersion(), args);
+ fillOption("--watch", isWatch(), args);
+ }
+
+}
diff --git a/typescript.java-ts.core/src/main/java/ts/cmd/tsc/ITypeScriptCompiler.java b/typescript.java-ts.core/src/main/java/ts/cmd/tsc/ITypeScriptCompiler.java
new file mode 100644
index 00000000..4ffcf999
--- /dev/null
+++ b/typescript.java-ts.core/src/main/java/ts/cmd/tsc/ITypeScriptCompiler.java
@@ -0,0 +1,43 @@
+/**
+ * Copyright (c) 2015-2016 Angelo ZERR.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Angelo Zerr - initial API and implementation
+ */
+package ts.cmd.tsc;
+
+import java.io.File;
+import java.util.List;
+
+import ts.TypeScriptException;
+import ts.nodejs.INodejsProcess;
+import ts.nodejs.INodejsProcessListener;
+
+/**
+ * API for TypeScript compiler which uses 'tsc'
+ *
+ */
+public interface ITypeScriptCompiler {
+
+ /**
+ * Execute 'tsc' command from the given directory.
+ *
+ * @param baseDir
+ * the directory where 'tsc' must be executed.
+ * @return
+ * @throws TypeScriptException
+ */
+ INodejsProcess execute(File baseDir, CompilerOptions options, List filenames,
+ INodejsProcessListener listener) throws TypeScriptException;
+
+ /**
+ * Dispose the compiler.
+ */
+ void dispose();
+
+ List createCommands(CompilerOptions options, List filenames);
+}
diff --git a/typescript.java-ts.core/src/main/java/ts/cmd/tsc/ITypeScriptCompilerMessageHandler.java b/typescript.java-ts.core/src/main/java/ts/cmd/tsc/ITypeScriptCompilerMessageHandler.java
new file mode 100644
index 00000000..73742bcd
--- /dev/null
+++ b/typescript.java-ts.core/src/main/java/ts/cmd/tsc/ITypeScriptCompilerMessageHandler.java
@@ -0,0 +1,11 @@
+package ts.cmd.tsc;
+
+import ts.cmd.ITypeScriptLinterHandler;
+
+public interface ITypeScriptCompilerMessageHandler extends ITypeScriptLinterHandler {
+
+ void addFile(String file, boolean emitted);
+
+ void onCompilationCompleteWatchingForFileChanges();
+
+}
diff --git a/typescript.java-ts.core/src/main/java/ts/cmd/tsc/Plugin.java b/typescript.java-ts.core/src/main/java/ts/cmd/tsc/Plugin.java
new file mode 100644
index 00000000..c6f63c66
--- /dev/null
+++ b/typescript.java-ts.core/src/main/java/ts/cmd/tsc/Plugin.java
@@ -0,0 +1,29 @@
+/**
+ * Copyright (c) 2015-2017 Angelo ZERR.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Angelo Zerr - initial API and implementation
+ *
+ */
+package ts.cmd.tsc;
+
+/**
+ * TypeScript 2.3 compilerOptions/plugins
+ *
+ */
+public class Plugin {
+
+ private String name;
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getName() {
+ return name;
+ }
+}
diff --git a/typescript.java-ts.core/src/main/java/ts/cmd/tsc/TypeScriptCompiler.java b/typescript.java-ts.core/src/main/java/ts/cmd/tsc/TypeScriptCompiler.java
new file mode 100644
index 00000000..ca1938a5
--- /dev/null
+++ b/typescript.java-ts.core/src/main/java/ts/cmd/tsc/TypeScriptCompiler.java
@@ -0,0 +1,30 @@
+/**
+ * Copyright (c) 2015-2016 Angelo ZERR.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Angelo Zerr - initial API and implementation
+ */
+package ts.cmd.tsc;
+
+import java.io.File;
+
+import ts.cmd.AbstractCmd;
+
+public class TypeScriptCompiler extends AbstractCmd implements ITypeScriptCompiler {
+
+ private static final String TSC_FILE_TYPE = "tsc";
+
+ public TypeScriptCompiler(File tscFile, File nodejsFile) {
+ super(tscFile, nodejsFile, TSC_FILE_TYPE);
+ }
+
+ @Override
+ public void dispose() {
+
+ }
+
+}
diff --git a/typescript.java-ts.core/src/main/java/ts/cmd/tsc/TypeScriptCompilerHelper.java b/typescript.java-ts.core/src/main/java/ts/cmd/tsc/TypeScriptCompilerHelper.java
new file mode 100644
index 00000000..45717696
--- /dev/null
+++ b/typescript.java-ts.core/src/main/java/ts/cmd/tsc/TypeScriptCompilerHelper.java
@@ -0,0 +1,103 @@
+/**
+ * Copyright (c) 2015-2016 Angelo ZERR.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Angelo Zerr - initial API and implementation
+ */
+package ts.cmd.tsc;
+
+import java.util.Scanner;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import ts.client.Location;
+import ts.cmd.Severity;
+import ts.utils.FileUtils;
+import ts.utils.StringUtils;
+
+/**
+ * TypeScript Compiler (tsc) helper.
+ *
+ */
+public class TypeScriptCompilerHelper {
+
+ private static final Pattern TSC_ERROR_PATTERN = Pattern.compile(
+ "^([^\\s].*)\\((\\d+|\\d+,\\d+|\\d+,\\d+,\\d+,\\d+)\\):\\s+(error|warning|info)\\s+(TS\\d+)\\s*:\\s*(.*)$");
+
+ private static final String COMPILATION_COMPLETE_WATCHING_FOR_FILE_CHANGES = "Compilation complete. Watching for file changes.";
+
+ private static final String TSFILE = "TSFILE:";
+
+ /**
+ * Process "tsc" message and call the well
+ * {@link ITypeScriptCompilerMessageHandler} method.
+ *
+ * @param text
+ * @param handler
+ */
+ public static void processMessage(String text, ITypeScriptCompilerMessageHandler handler) {
+ if (StringUtils.isEmpty(text)) {
+ return;
+ }
+
+ Scanner scanner = null;
+ try {
+ scanner = new Scanner(text);
+ while (scanner.hasNextLine()) {
+ String line = scanner.nextLine();
+ line = line.trim(); // remove leading whitespace
+ if (line.endsWith(FileUtils.TS_EXTENSION) || line.endsWith(FileUtils.TSX_EXTENSION)) {
+ // Occurs when tsc is called with --listFiles
+ handler.addFile(line, false);
+ } else if (line.contains(COMPILATION_COMPLETE_WATCHING_FOR_FILE_CHANGES)) {
+ // Occurs when tsc is called with --watch when compilation
+ // is finished.
+ handler.onCompilationCompleteWatchingForFileChanges();
+ } else if (line.startsWith(TSFILE)) {
+ handler.addFile(line.substring(TSFILE.length(), line.length()).trim(), true);
+ } else {
+ Matcher m = TSC_ERROR_PATTERN.matcher(line);
+ if (m.matches()) {
+ // Error in an ts file.
+ String file = m.group(1);
+ String[] location = m.group(2).split(",");
+ Location startLoc = createLocation(location, true);
+ Location endLoc = createLocation(location, false);
+ String severity = m.group(3);
+ String code = m.group(4);
+ String message = m.group(5);
+ handler.addError(file, startLoc, endLoc,
+ StringUtils.isEmpty(severity) ? Severity.info : Severity.valueOf(severity), code,
+ message);
+ }
+ }
+ }
+ } finally
+
+ {
+ if (scanner != null) {
+ scanner.close();
+ }
+ }
+ }
+
+ private static Location createLocation(String[] location, boolean start) {
+ if (start) {
+ int line = getInt(location, 0);
+ int offset = getInt(location, 1);
+ return new Location(line, offset);
+ }
+ return null;
+ }
+
+ private static int getInt(String[] location, int index) {
+ if (index < location.length) {
+ return Integer.parseInt(location[index]);
+ }
+ return 0;
+ }
+}
diff --git a/typescript.java-ts.core/src/main/java/ts/cmd/tslint/ITypeScriptLint.java b/typescript.java-ts.core/src/main/java/ts/cmd/tslint/ITypeScriptLint.java
new file mode 100644
index 00000000..40223779
--- /dev/null
+++ b/typescript.java-ts.core/src/main/java/ts/cmd/tslint/ITypeScriptLint.java
@@ -0,0 +1,34 @@
+/**
+ * Copyright (c) 2015-2016 Angelo ZERR.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Angelo Zerr - initial API and implementation
+ */
+package ts.cmd.tslint;
+
+import java.io.File;
+import java.util.List;
+
+import ts.TypeScriptException;
+import ts.nodejs.INodejsProcess;
+import ts.nodejs.INodejsProcessListener;
+
+public interface ITypeScriptLint {
+
+ /**
+ * Execute 'tslint' command from the given directory.
+ *
+ * @param baseDir
+ * the directory where 'tsc' must be executed.
+ * @return
+ * @throws TypeScriptException
+ */
+ INodejsProcess execute(File baseDir, TSLintOptions options, List filenames, INodejsProcessListener listener)
+ throws TypeScriptException;
+
+ List createCommands(TSLintOptions options, List filenames);
+}
diff --git a/typescript.java-ts.core/src/main/java/ts/cmd/tslint/TSLintOptions.java b/typescript.java-ts.core/src/main/java/ts/cmd/tslint/TSLintOptions.java
new file mode 100644
index 00000000..ca5a00b8
--- /dev/null
+++ b/typescript.java-ts.core/src/main/java/ts/cmd/tslint/TSLintOptions.java
@@ -0,0 +1,61 @@
+/**
+ * Copyright (c) 2015-2016 Angelo ZERR.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Angelo Zerr - initial API and implementation
+ */
+package ts.cmd.tslint;
+
+import java.io.File;
+import java.util.List;
+
+import ts.cmd.AbstractOptions;
+import ts.utils.FileUtils;
+
+/**
+ * tslint options.
+ *
+ * @see http://palantir.github.io/tslint/usage/cli/
+ *
+ */
+public class TSLintOptions extends AbstractOptions {
+
+ private String config;
+ private String format;
+
+ public String getConfig() {
+ return config;
+ }
+
+ public void setConfig(String config) {
+ this.config = config;
+ }
+
+ public void setConfig(File configFile) {
+ if (configFile != null) {
+ setConfig(FileUtils.getPath(configFile));
+ }
+ }
+
+ public String getFormat() {
+ return format;
+ }
+
+ public void setFormat(String format) {
+ this.format = format;
+ }
+
+ public void setFormat(TslintFormat format) {
+ setFormat(format.name());
+ }
+
+ @Override
+ public void fillOptions(List args) {
+ super.fillOption("--config", getConfig(), args);
+ super.fillOption("--format", getFormat(), args);
+ }
+}
diff --git a/typescript.java-ts.core/src/main/java/ts/cmd/tslint/TslintFormat.java b/typescript.java-ts.core/src/main/java/ts/cmd/tslint/TslintFormat.java
new file mode 100644
index 00000000..7136986f
--- /dev/null
+++ b/typescript.java-ts.core/src/main/java/ts/cmd/tslint/TslintFormat.java
@@ -0,0 +1,20 @@
+/**
+ * Copyright (c) 2015-2016 Angelo ZERR.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Angelo Zerr - initial API and implementation
+ */
+package ts.cmd.tslint;
+
+/**
+ * Supported tslint --format.
+ *
+ */
+public enum TslintFormat {
+
+ prose, json, verbose, pmd, msbuild, checkstyle
+}
diff --git a/typescript.java-ts.core/src/main/java/ts/cmd/tslint/TslintHelper.java b/typescript.java-ts.core/src/main/java/ts/cmd/tslint/TslintHelper.java
new file mode 100644
index 00000000..f427de25
--- /dev/null
+++ b/typescript.java-ts.core/src/main/java/ts/cmd/tslint/TslintHelper.java
@@ -0,0 +1,135 @@
+/**
+ * Copyright (c) 2015-2016 Angelo ZERR.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Angelo Zerr - initial API and implementation
+ */
+package ts.cmd.tslint;
+
+import java.util.Scanner;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import com.eclipsesource.json.Json;
+import com.eclipsesource.json.JsonArray;
+import com.eclipsesource.json.JsonObject;
+import com.eclipsesource.json.JsonValue;
+
+import ts.client.Location;
+import ts.cmd.ITypeScriptLinterHandler;
+import ts.cmd.Severity;
+import ts.utils.StringUtils;
+
+/**
+ * TypeScript Compiler (tsc) helper.
+ *
+ */
+public class TslintHelper {
+
+ // ex: "(no-var-keyword) sample.ts[1, 1]: forbidden 'var' keyword, use 'let'
+ // or 'const' instead", errors);
+ // sample.ts(1,14): error TS1003: Identifier expected.
+
+ private static final Pattern TSLINT_PATTERN = Pattern
+ .compile("^\\(\\s*(.*)\\)\\s([^\\s].*)\\[(\\d+,\\s*\\d+)\\]:\\s*(.*)$");
+
+ /**
+ * Process "tslint" message and call the well
+ * {@link ITypeScriptLinterHandler} method.
+ *
+ * @param text
+ * @param handler
+ */
+ public static void processVerboseMessage(String text, ITypeScriptLinterHandler handler) {
+ if (StringUtils.isEmpty(text)) {
+ return;
+ }
+
+ Scanner scanner = null;
+ try {
+ scanner = new Scanner(text);
+ while (scanner.hasNextLine()) {
+ String line = scanner.nextLine();
+ line = line.trim(); // remove leading whitespace
+ Matcher m = TSLINT_PATTERN.matcher(line);
+ if (m.matches()) {
+ // Error in an ts file.
+ String code = m.group(1);
+ String file = m.group(2);
+ String[] location = m.group(3).split(",");
+ Location startLoc = createLocation(location, true);
+ Location endLoc = null; // createLocation(location, false);
+ String message = m.group(4);
+ handler.addError(file, startLoc, endLoc, Severity.error, code, message);
+ }
+ }
+ } finally {
+ if (scanner != null) {
+ scanner.close();
+ }
+ }
+ }
+
+ private static Location createLocation(String[] location, boolean start) {
+ if (start) {
+ int line = getInt(location, 0);
+ int offset = getInt(location, 1);
+ return new Location(line, offset);
+ }
+ return null;
+ }
+
+ private static int getInt(String[] location, int index) {
+ if (index < location.length) {
+ return Integer.parseInt(location[index].trim());
+ }
+ return 0;
+ }
+
+ public static void processJsonMessage(String text, ITypeScriptLinterHandler handler) {
+ if (StringUtils.isEmpty(text)) {
+ return;
+ }
+
+ Scanner scanner = null;
+ try {
+ scanner = new Scanner(text);
+ while (scanner.hasNextLine()) {
+ String line = scanner.nextLine();
+ line = line.trim(); // remove leading whitespace
+ JsonArray array = Json.parse(line).asArray();
+ for (JsonValue value : array) {
+ // [{"endPosition":{"character":3,"line":0,"position":3},"failure":"forbidden
+ // 'var' keyword, use 'let' or 'const'
+ // instead","name":"sample.ts","ruleName":"no-var-keyword","startPosition":{"character":0,"line":0,"position":0}},{"endPosition":{"character":13,"line":0,"position":13},"failure":"missing
+ // semicolon","name":"sample.ts","ruleName":"semicolon","startPosition":{"character":13,"line":0,"position":13}},{"endPosition":{"character":12,"line":0,"position":12},"failure":"missing
+ // whitespace","name":"sample.ts","ruleName":"whitespace","startPosition":{"character":11,"line":0,"position":11}}]
+ JsonObject item = value.asObject();
+ String name = item.getString("name", null);
+ String ruleName = item.getString("ruleName", null);
+ String failure = item.getString("failure", null);
+ Location startLoc = createLocation(item.get("startPosition"));
+ Location endLoc = createLocation(item.get("endPosition"));
+ handler.addError(name, startLoc, endLoc, Severity.error, ruleName, failure);
+ }
+ }
+ } finally {
+ if (scanner != null) {
+ scanner.close();
+ }
+ }
+ }
+
+ private static Location createLocation(JsonValue value) {
+ if (value == null || !value.isObject()) {
+ return null;
+ }
+ JsonObject loc = value.asObject();
+ return new Location(loc.getInt("line", -1), loc.getInt("character", -1), loc.getInt("position", -1));
+ }
+
+}
\ No newline at end of file
diff --git a/typescript.java-ts.core/src/main/java/ts/cmd/tslint/TslintSettingsStrategy.java b/typescript.java-ts.core/src/main/java/ts/cmd/tslint/TslintSettingsStrategy.java
new file mode 100644
index 00000000..598a94ac
--- /dev/null
+++ b/typescript.java-ts.core/src/main/java/ts/cmd/tslint/TslintSettingsStrategy.java
@@ -0,0 +1,7 @@
+package ts.cmd.tslint;
+
+public enum TslintSettingsStrategy {
+
+ DisableTslint, UseDefaultTslintJson, UseCustomTslintJson, SearchForTslintJson
+
+}
diff --git a/typescript.java-ts.core/src/main/java/ts/cmd/tslint/TypeScriptLint.java b/typescript.java-ts.core/src/main/java/ts/cmd/tslint/TypeScriptLint.java
new file mode 100644
index 00000000..8ad02095
--- /dev/null
+++ b/typescript.java-ts.core/src/main/java/ts/cmd/tslint/TypeScriptLint.java
@@ -0,0 +1,22 @@
+package ts.cmd.tslint;
+
+import java.io.File;
+
+import ts.cmd.AbstractCmd;
+
+public class TypeScriptLint extends AbstractCmd implements ITypeScriptLint {
+
+ private static final String TSLINT_FILE_TYPE = "tslint";
+
+ private final File tslintJsonFile;
+
+ public TypeScriptLint(File tslintFile, File tslintJsonFile, File nodejsFile) {
+ super(tslintFile, nodejsFile, TSLINT_FILE_TYPE);
+ this.tslintJsonFile = tslintJsonFile;
+ }
+
+ public File getTslintJsonFile() {
+ return tslintJsonFile;
+ }
+
+}
diff --git a/typescript.java-ts.core/src/main/java/ts/internal/Activator.java b/typescript.java-ts.core/src/main/java/ts/internal/Activator.java
new file mode 100644
index 00000000..ad117f5e
--- /dev/null
+++ b/typescript.java-ts.core/src/main/java/ts/internal/Activator.java
@@ -0,0 +1,30 @@
+package ts.internal;
+
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+
+public class Activator implements BundleActivator {
+
+ private static BundleContext context;
+
+ static BundleContext getContext() {
+ return context;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
+ */
+ public void start(BundleContext bundleContext) throws Exception {
+ Activator.context = bundleContext;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
+ */
+ public void stop(BundleContext bundleContext) throws Exception {
+ Activator.context = null;
+ }
+
+}
diff --git a/typescript.java-ts.core/src/main/java/ts/internal/FileTempHelper.java b/typescript.java-ts.core/src/main/java/ts/internal/FileTempHelper.java
new file mode 100644
index 00000000..4f247030
--- /dev/null
+++ b/typescript.java-ts.core/src/main/java/ts/internal/FileTempHelper.java
@@ -0,0 +1,73 @@
+package ts.internal;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.Writer;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Stack;
+
+import ts.TypeScriptException;
+
+public class FileTempHelper {
+
+ private final static Stack availableTempFileList = new Stack();
+ private final static Map seq_to_tempfile_name = new HashMap();
+
+ public static String updateTempFile(String newText, int seq) throws TypeScriptException {
+ Writer writer = null;
+ try {
+ File tempFile = getTempFile(seq);
+ writer = new FileWriter(tempFile);
+ writer.write(newText);
+ writer.flush();
+ return tempFile.getCanonicalPath();
+ } catch (Exception e) {
+ throw new TypeScriptException(e);
+ } finally {
+ try {
+ if (writer != null) {
+ writer.close();
+ }
+ } catch (IOException e) {
+ throw new TypeScriptException(e);
+ }
+ }
+ }
+
+ /**
+ * Get the first unused temp file name to avoid conflicts.
+ *
+ * @return
+ * @throws IOException
+ */
+ private static File getTempFile(int seq) throws IOException {
+ File tempFile = null;
+ synchronized (availableTempFileList) {
+ if (!availableTempFileList.isEmpty()) {
+ tempFile = availableTempFileList.pop();
+ } else {
+ tempFile = File.createTempFile("tmptsjava." + SequenceHelper.getTempSeq(), null);
+ tempFile.deleteOnExit();
+ }
+ seq_to_tempfile_name.put(seq, tempFile);
+ }
+ return tempFile;
+ }
+
+ /**
+ * Post process after receiving a reload response
+ *
+ * @param seq
+ */
+ public static void freeTempFile(int seq) {
+ synchronized (availableTempFileList) {
+ File tempFile = seq_to_tempfile_name.remove(seq);
+ if (tempFile != null) {
+ availableTempFileList.push(tempFile);
+ }
+ }
+ }
+
+}
diff --git a/typescript.java-ts.core/src/main/java/ts/internal/LocationReader.java b/typescript.java-ts.core/src/main/java/ts/internal/LocationReader.java
new file mode 100644
index 00000000..7772df0d
--- /dev/null
+++ b/typescript.java-ts.core/src/main/java/ts/internal/LocationReader.java
@@ -0,0 +1,57 @@
+package ts.internal;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.StringReader;
+import java.util.ArrayList;
+import java.util.List;
+
+import ts.client.Location;
+
+public class LocationReader {
+
+ private Location loc;
+
+ public LocationReader(String contents, int position) {
+ List lines = readLines(contents);
+ int offset = position;
+ int current = position;
+ int line = 0;
+ for (Integer lineOffset : lines) {
+ if (line > 0) {
+ current -= "\r\n".length();
+ }
+ if (current <= lineOffset) {
+ offset = current;
+ break;
+ } else {
+ current -= lineOffset;
+ }
+ line++;
+ }
+ this.loc = new Location(line + 1, offset + 1);
+ }
+
+ public Location getLineOffset() {
+ return loc;
+ }
+
+ private List readLines(final String input) {
+ final List list = new ArrayList();
+ try {
+ final BufferedReader reader = new BufferedReader(new StringReader(input));
+ String line = reader.readLine();
+ while (line != null) {
+ if (list.size() > 0) {
+ list.add(line.length());// "\r\n".length());
+ } else {
+ list.add(line.length());
+ }
+ line = reader.readLine();
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ return list;
+ }
+}
diff --git a/typescript.java-ts.core/src/main/java/ts/internal/SequenceHelper.java b/typescript.java-ts.core/src/main/java/ts/internal/SequenceHelper.java
new file mode 100644
index 00000000..9eec6d51
--- /dev/null
+++ b/typescript.java-ts.core/src/main/java/ts/internal/SequenceHelper.java
@@ -0,0 +1,17 @@
+package ts.internal;
+
+import java.util.concurrent.atomic.AtomicInteger;
+
+public class SequenceHelper {
+
+ private final static AtomicInteger requestSeq = new AtomicInteger();
+ private final static AtomicInteger tmpSeq = new AtomicInteger();
+
+ public static int getRequestSeq() {
+ return requestSeq.getAndIncrement();
+ }
+
+ public static int getTempSeq() {
+ return tmpSeq.getAndIncrement();
+ }
+}
diff --git a/typescript.java-ts.core/src/main/java/ts/internal/client/protocol/AbstractFormatRequest.java b/typescript.java-ts.core/src/main/java/ts/internal/client/protocol/AbstractFormatRequest.java
new file mode 100644
index 00000000..c9d4c573
--- /dev/null
+++ b/typescript.java-ts.core/src/main/java/ts/internal/client/protocol/AbstractFormatRequest.java
@@ -0,0 +1,28 @@
+/**
+ * Copyright (c) 2015-2017 Angelo ZERR.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Angelo Zerr - initial API and implementation
+ */
+package ts.internal.client.protocol;
+
+/**
+ * Format request; value of command field is "format". Return response giving
+ * zero or more edit instructions. The edit instructions will be sorted in file
+ * order. Applying the edit instructions in reverse to file will result in
+ * correctly reformatted text.
+ *
+ * @see https://github.com/Microsoft/TypeScript/blob/master/src/server/protocol.ts
+ *
+ */
+public abstract class AbstractFormatRequest extends FileLocationRequest {
+
+ public AbstractFormatRequest(String command, T arguments) {
+ super(command, arguments);
+ }
+
+}
diff --git a/typescript.java-ts.core/src/main/java/ts/internal/client/protocol/ChangeRequest.java b/typescript.java-ts.core/src/main/java/ts/internal/client/protocol/ChangeRequest.java
new file mode 100644
index 00000000..ffb1ed2b
--- /dev/null
+++ b/typescript.java-ts.core/src/main/java/ts/internal/client/protocol/ChangeRequest.java
@@ -0,0 +1,42 @@
+/**
+ * Copyright (c) 2015-2017 Angelo ZERR.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Angelo Zerr - initial API and implementation
+ */
+package ts.internal.client.protocol;
+
+import com.google.gson.JsonObject;
+
+import ts.client.CommandNames;
+
+/**
+ * Change request message; value of command field is "change". Update the
+ * server's view of the file named by argument 'file'. Server does not currently
+ * send a response to a change request.
+ *
+ * @see https://github.com/Microsoft/TypeScript/blob/master/src/server/protocol.ts
+ *
+ */
+public class ChangeRequest extends AbstractFormatRequest {
+
+ public ChangeRequest(String fileName, int position, int endPosition, String insertString) {
+ super(CommandNames.Change.getName(), new ChangeRequestArgs(fileName, position, endPosition, insertString));
+ }
+
+ public ChangeRequest(String fileName, int line, int offset, int endLine, int endOffset, String insertString) {
+ super(CommandNames.Change.getName(),
+ new ChangeRequestArgs(fileName, line, offset, endLine, endOffset, insertString));
+ }
+
+ @Override
+ public Response> parseResponse(JsonObject json) {
+ // This request doesn't return response.
+ return null;
+ }
+
+}
diff --git a/typescript.java-ts.core/src/main/java/ts/internal/client/protocol/ChangeRequestArgs.java b/typescript.java-ts.core/src/main/java/ts/internal/client/protocol/ChangeRequestArgs.java
new file mode 100644
index 00000000..c9bd9cea
--- /dev/null
+++ b/typescript.java-ts.core/src/main/java/ts/internal/client/protocol/ChangeRequestArgs.java
@@ -0,0 +1,38 @@
+/**
+ * Copyright (c) 2015-2017 Angelo ZERR.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Angelo Zerr - initial API and implementation
+ */
+package ts.internal.client.protocol;
+
+/**
+ * Arguments for change request message.
+ *
+ * @see https://github.com/Microsoft/TypeScript/blob/master/src/server/protocol.ts
+ */
+public class ChangeRequestArgs extends FormatRequestArgs {
+
+ /**
+ * Optional string to insert at location (file, line, offset).
+ */
+ private final String insertString;
+
+ public ChangeRequestArgs(String file, int position, int endPosition, String insertString) {
+ super(file, position, endPosition);
+ this.insertString = insertString;
+ }
+
+ public ChangeRequestArgs(String file, int line, int offset, int endLine, int endOffset, String insertString) {
+ super(file, line, offset, endLine, endOffset);
+ this.insertString = insertString;
+ }
+
+ public String getInsertString() {
+ return insertString;
+ }
+}
diff --git a/typescript.java-ts.core/src/main/java/ts/internal/client/protocol/CloseExternalProjectRequest.java b/typescript.java-ts.core/src/main/java/ts/internal/client/protocol/CloseExternalProjectRequest.java
new file mode 100644
index 00000000..03d04819
--- /dev/null
+++ b/typescript.java-ts.core/src/main/java/ts/internal/client/protocol/CloseExternalProjectRequest.java
@@ -0,0 +1,25 @@
+package ts.internal.client.protocol;
+
+import com.google.gson.JsonObject;
+
+import ts.client.CommandNames;
+
+/**
+ * Request to open or update external project.
+ *
+ * @see https://github.com/Microsoft/TypeScript/blob/master/src/server/protocol.ts
+ *
+ */
+public class CloseExternalProjectRequest extends Request {
+
+ public CloseExternalProjectRequest(String projectFileName) {
+ super(CommandNames.CloseExternalProject.getName(),
+ new CloseExternalProjectRequestArgs(projectFileName));
+ }
+
+ @Override
+ public Response> parseResponse(JsonObject json) {
+ // This request doesn't return response.
+ return null;
+ }
+}
diff --git a/typescript.java-ts.core/src/main/java/ts/internal/client/protocol/CloseExternalProjectRequestArgs.java b/typescript.java-ts.core/src/main/java/ts/internal/client/protocol/CloseExternalProjectRequestArgs.java
new file mode 100644
index 00000000..bede5844
--- /dev/null
+++ b/typescript.java-ts.core/src/main/java/ts/internal/client/protocol/CloseExternalProjectRequestArgs.java
@@ -0,0 +1,16 @@
+package ts.internal.client.protocol;
+
+/**
+ * @see https://github.com/Microsoft/TypeScript/blob/master/src/server/protocol.ts
+ */
+public class CloseExternalProjectRequestArgs {
+
+ /**
+ * Project name
+ */
+ String projectFileName;
+
+ public CloseExternalProjectRequestArgs(String projectFileName) {
+ this.projectFileName = projectFileName;
+ }
+}
diff --git a/typescript.java-ts.core/src/main/java/ts/internal/client/protocol/CloseRequest.java b/typescript.java-ts.core/src/main/java/ts/internal/client/protocol/CloseRequest.java
new file mode 100644
index 00000000..bbbb1304
--- /dev/null
+++ b/typescript.java-ts.core/src/main/java/ts/internal/client/protocol/CloseRequest.java
@@ -0,0 +1,37 @@
+/**
+ * Copyright (c) 2015-2017 Angelo ZERR.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Angelo Zerr - initial API and implementation
+ */
+package ts.internal.client.protocol;
+
+import com.google.gson.JsonObject;
+
+import ts.client.CommandNames;
+
+/**
+ * Close request; value of command field is "close". Notify the server that the
+ * client has closed a previously open file. If file is still referenced by open
+ * files, the server will resume monitoring the filesystem for changes to file.
+ * Server does not currently send a response to a close request.
+ *
+ * @see https://github.com/Microsoft/TypeScript/blob/master/src/server/protocol.ts
+ */
+public class CloseRequest extends FileRequest {
+
+ public CloseRequest(String fileName) {
+ super(CommandNames.Close.getName(), new FileRequestArgs(fileName, null));
+ }
+
+ @Override
+ public Response> parseResponse(JsonObject json) {
+ // This request doesn't return response.
+ return null;
+ }
+
+}
diff --git a/typescript.java-ts.core/src/main/java/ts/internal/client/protocol/CodeFixRequest.java b/typescript.java-ts.core/src/main/java/ts/internal/client/protocol/CodeFixRequest.java
new file mode 100644
index 00000000..9d9329bf
--- /dev/null
+++ b/typescript.java-ts.core/src/main/java/ts/internal/client/protocol/CodeFixRequest.java
@@ -0,0 +1,39 @@
+/**
+ * Copyright (c) 2015-2017 Angelo ZERR.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Angelo Zerr - initial API and implementation
+ */
+package ts.internal.client.protocol;
+
+import java.util.List;
+
+import com.google.gson.JsonObject;
+
+import ts.client.CommandNames;
+import ts.client.codefixes.CodeAction;
+
+/**
+ * Configure request; value of command field is "configure". Specifies host
+ * information, such as host type, tab size, and indent size.
+ *
+ * @see https://github.com/Microsoft/TypeScript/blob/master/src/server/protocol.ts
+ */
+public class CodeFixRequest extends Request {
+
+ public CodeFixRequest(String file, int startLine, int startOffset, int endLine, int endOffset,
+ List errorCodes) {
+ super(CommandNames.GetCodeFixes.getName(),
+ new CodeFixRequestArgs(file, startLine, startOffset, endLine, endOffset, errorCodes));
+ }
+
+ @Override
+ public Response> parseResponse(JsonObject json) {
+ return GsonHelper.DEFAULT_GSON.fromJson(json, GetCodeFixesResponse.class);
+ }
+
+}
diff --git a/typescript.java-ts.core/src/main/java/ts/internal/client/protocol/CodeFixRequestArgs.java b/typescript.java-ts.core/src/main/java/ts/internal/client/protocol/CodeFixRequestArgs.java
new file mode 100644
index 00000000..a807bba8
--- /dev/null
+++ b/typescript.java-ts.core/src/main/java/ts/internal/client/protocol/CodeFixRequestArgs.java
@@ -0,0 +1,44 @@
+/**
+ * Copyright (c) 2015-2017 Angelo ZERR.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Angelo Zerr - initial API and implementation
+ */
+package ts.internal.client.protocol;
+
+import java.util.List;
+
+/**
+ * Instances of this interface specify errorcodes on a specific location in a
+ * sourcefile.
+ *
+ * @see https://github.com/Microsoft/TypeScript/blob/master/src/server/protocol.ts
+ *
+ */
+public class CodeFixRequestArgs extends FileRangeRequestArgs {
+
+ /**
+ * Errorcodes we want to get the fixes for.
+ */
+ private List errorCodes;
+
+ public CodeFixRequestArgs(String file, int startLine, int startOffset, int endLine, int endOffset,
+ List errorCodes) {
+ this(file, startLine, startOffset, endLine, endOffset, errorCodes, null, null, null);
+ }
+
+ private CodeFixRequestArgs(String file, Integer startLine, Integer startOffset, Integer endLine, Integer endOffset,
+ List errorCodes, Integer startPosition, Integer endPosition, String projectName) {
+ super(file, startLine, startOffset, endLine, endOffset);
+ this.errorCodes = errorCodes;
+ }
+
+ public List getErrorCodes() {
+ return errorCodes;
+ }
+
+}
diff --git a/typescript.java-ts.core/src/main/java/ts/internal/client/protocol/CompileOnSaveAffectedFileListRequest.java b/typescript.java-ts.core/src/main/java/ts/internal/client/protocol/CompileOnSaveAffectedFileListRequest.java
new file mode 100644
index 00000000..0a8319ee
--- /dev/null
+++ b/typescript.java-ts.core/src/main/java/ts/internal/client/protocol/CompileOnSaveAffectedFileListRequest.java
@@ -0,0 +1,38 @@
+/**
+ * Copyright (c) 2015-2017 Angelo ZERR.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Angelo Zerr - initial API and implementation
+ */
+package ts.internal.client.protocol;
+
+import java.util.List;
+
+import com.google.gson.JsonObject;
+
+import ts.client.CommandNames;
+import ts.client.compileonsave.CompileOnSaveAffectedFileListSingleProject;
+
+/**
+ * Request to obtain the list of files that should be regenerated if target file
+ * is recompiled. NOTE: this us query-only operation and does not generate any
+ * output on disk.
+ *
+ * @see https://github.com/Microsoft/TypeScript/blob/master/src/server/protocol.ts
+ */
+public class CompileOnSaveAffectedFileListRequest extends FileRequest {
+
+ public CompileOnSaveAffectedFileListRequest(String fileName) {
+ super(CommandNames.CompileOnSaveAffectedFileList.getName(), new FileRequestArgs(fileName, null));
+ }
+
+ @Override
+ public Response> parseResponse(JsonObject json) {
+ return GsonHelper.DEFAULT_GSON.fromJson(json, CompileOnSaveAffectedFileListResponse.class);
+ }
+
+}
diff --git a/typescript.java-ts.core/src/main/java/ts/internal/client/protocol/CompileOnSaveAffectedFileListResponse.java b/typescript.java-ts.core/src/main/java/ts/internal/client/protocol/CompileOnSaveAffectedFileListResponse.java
new file mode 100644
index 00000000..405c50e5
--- /dev/null
+++ b/typescript.java-ts.core/src/main/java/ts/internal/client/protocol/CompileOnSaveAffectedFileListResponse.java
@@ -0,0 +1,24 @@
+/**
+ * Copyright (c) 2015-2017 Angelo ZERR.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Angelo Zerr - initial API and implementation
+ */
+package ts.internal.client.protocol;
+
+import java.util.List;
+
+import ts.client.compileonsave.CompileOnSaveAffectedFileListSingleProject;
+
+/**
+ * Response for CompileOnSaveAffectedFileListRequest request;
+ *
+ * @see https://github.com/Microsoft/TypeScript/blob/master/src/server/protocol.ts
+ */
+public class CompileOnSaveAffectedFileListResponse extends Response