diff --git a/core/ts.core/src/ts/client/CommandNames.java b/core/ts.core/src/ts/client/CommandNames.java index 9e203bec..8c9f86fa 100644 --- a/core/ts.core/src/ts/client/CommandNames.java +++ b/core/ts.core/src/ts/client/CommandNames.java @@ -52,8 +52,12 @@ public enum CommandNames implements ISupportable { // 2.1.0 Implementation("implementation", "2.1.0"), GetSupportedCodeFixes("getSupportedCodeFixes", "2.1.0"), - GetCodeFixes("getCodeFixes", "2.1.0"); + GetCodeFixes("getCodeFixes", "2.1.0"), + // 2.4.0 + GetApplicableRefactors("getApplicableRefactors", "2.4.0"), + GetRefactorCodeActions("getRefactorCodeActions", "2.4.0"); + private final String name; private final String sinceVersion; diff --git a/core/ts.core/src/ts/client/ITypeScriptServiceClient.java b/core/ts.core/src/ts/client/ITypeScriptServiceClient.java index 4ba26001..5b1cf86b 100644 --- a/core/ts.core/src/ts/client/ITypeScriptServiceClient.java +++ b/core/ts.core/src/ts/client/ITypeScriptServiceClient.java @@ -28,6 +28,8 @@ import ts.client.occurrences.OccurrencesResponseItem; import ts.client.projectinfo.ProjectInfo; import ts.client.quickinfo.QuickInfo; +import ts.client.refactors.ApplicableRefactorInfo; +import ts.client.refactors.RefactorCodeActions; import ts.client.references.ReferencesResponseBody; import ts.client.rename.RenameResponseBody; import ts.client.signaturehelp.SignatureHelpItems; @@ -257,7 +259,6 @@ CompletableFuture> getCodeFixes(String fileName, IPositionProvi CompletableFuture> getSupportedCodeFixes() throws TypeScriptException; - // /** * Definition for the given fileName at the given line/offset. * @@ -269,6 +270,14 @@ CompletableFuture> getCodeFixes(String fileName, IPositionProvi */ 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 getRefactorCodeActions(String fileName, int line, int offset, + String refactorName) throws TypeScriptException; + void addClientListener(ITypeScriptClientListener listener); void removeClientListener(ITypeScriptClientListener listener); diff --git a/core/ts.core/src/ts/client/TypeScriptServiceClient.java b/core/ts.core/src/ts/client/TypeScriptServiceClient.java index 49bd6708..ecd54712 100644 --- a/core/ts.core/src/ts/client/TypeScriptServiceClient.java +++ b/core/ts.core/src/ts/client/TypeScriptServiceClient.java @@ -32,7 +32,6 @@ import ts.client.completions.ICompletionEntryFactory; import ts.client.completions.ICompletionEntryMatcherProvider; import ts.client.configure.ConfigureRequestArguments; -import ts.client.diagnostics.Diagnostic; import ts.client.diagnostics.DiagnosticEvent; import ts.client.diagnostics.DiagnosticEventBody; import ts.client.diagnostics.IDiagnostic; @@ -44,6 +43,8 @@ import ts.client.occurrences.OccurrencesResponseItem; import ts.client.projectinfo.ProjectInfo; import ts.client.quickinfo.QuickInfo; +import ts.client.refactors.ApplicableRefactorInfo; +import ts.client.refactors.RefactorCodeActions; import ts.client.references.ReferencesResponseBody; import ts.client.rename.RenameResponseBody; import ts.client.signaturehelp.SignatureHelpItems; @@ -60,6 +61,8 @@ 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.GetRefactorCodeActionsRequest; import ts.internal.client.protocol.GetSupportedCodeFixesRequest; import ts.internal.client.protocol.GeterrForProjectRequest; import ts.internal.client.protocol.GeterrRequest; @@ -461,7 +464,7 @@ public CompletableFuture docCommentTemplate(String fileName, int throws TypeScriptException { return execute(new DocCommentTemplateRequest(fileName, line, offset), true); } - + // Since 2.1.0 @Override @@ -482,6 +485,20 @@ public CompletableFuture> implementation(String fileName, int lin 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 getRefactorCodeActions(String fileName, int line, int offset, + String refactorName) throws TypeScriptException { + return execute(new GetRefactorCodeActionsRequest(fileName, line, offset, refactorName), true); + } + private CompletableFuture execute(Request request, boolean expectsResult) throws TypeScriptException { if (!expectsResult) { sendRequest(request); diff --git a/core/ts.core/src/ts/client/refactors/ApplicableRefactorInfo.java b/core/ts.core/src/ts/client/refactors/ApplicableRefactorInfo.java new file mode 100644 index 00000000..a9a3d976 --- /dev/null +++ b/core/ts.core/src/ts/client/refactors/ApplicableRefactorInfo.java @@ -0,0 +1,16 @@ +package ts.client.refactors; + +public class ApplicableRefactorInfo { + + private String name; + + private String description; + + public String getName() { + return name; + } + + public String getDescription() { + return description; + } +} diff --git a/core/ts.core/src/ts/client/refactors/RefactorCodeActions.java b/core/ts.core/src/ts/client/refactors/RefactorCodeActions.java new file mode 100644 index 00000000..4cb7c666 --- /dev/null +++ b/core/ts.core/src/ts/client/refactors/RefactorCodeActions.java @@ -0,0 +1,20 @@ +package ts.client.refactors; + +import java.util.List; + +import ts.client.codefixes.CodeAction; + +public class RefactorCodeActions { + + private List actions; + + private Integer renameLocation; + + public List getActions() { + return actions; + } + + public Integer getRenameLocation() { + return renameLocation; + } +} diff --git a/core/ts.core/src/ts/internal/client/protocol/GetApplicableRefactorsRequest.java b/core/ts.core/src/ts/internal/client/protocol/GetApplicableRefactorsRequest.java new file mode 100644 index 00000000..c2f7a054 --- /dev/null +++ b/core/ts.core/src/ts/internal/client/protocol/GetApplicableRefactorsRequest.java @@ -0,0 +1,34 @@ +/** + * 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.refactors.ApplicableRefactorInfo; + +/** + * @see https://github.com/Microsoft/TypeScript/blob/master/src/server/protocol.ts + */ +public class GetApplicableRefactorsRequest extends Request { + + public GetApplicableRefactorsRequest(String file, int line, int offset) { + super(CommandNames.GetApplicableRefactors.getName(), new GetApplicableRefactorsRequestArgs(file, line, offset)); + } + + @Override + public Response> parseResponse(JsonObject json) { + return GsonHelper.DEFAULT_GSON.fromJson(json, GetApplicableRefactorsResponse.class); + } + +} diff --git a/core/ts.core/src/ts/internal/client/protocol/GetApplicableRefactorsRequestArgs.java b/core/ts.core/src/ts/internal/client/protocol/GetApplicableRefactorsRequestArgs.java new file mode 100644 index 00000000..ff22cdeb --- /dev/null +++ b/core/ts.core/src/ts/internal/client/protocol/GetApplicableRefactorsRequestArgs.java @@ -0,0 +1,27 @@ +/** + * 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; + +/** + * + * @see https://github.com/Microsoft/TypeScript/blob/master/src/server/protocol.ts + * + */ +public class GetApplicableRefactorsRequestArgs extends FileLocationRequestArgs { + + public GetApplicableRefactorsRequestArgs(String file, int position) { + super(file, position); + } + + public GetApplicableRefactorsRequestArgs(String file, int line, int offset) { + super(file, line, offset); + } +} diff --git a/core/ts.core/src/ts/internal/client/protocol/GetApplicableRefactorsResponse.java b/core/ts.core/src/ts/internal/client/protocol/GetApplicableRefactorsResponse.java new file mode 100644 index 00000000..5d2d13c3 --- /dev/null +++ b/core/ts.core/src/ts/internal/client/protocol/GetApplicableRefactorsResponse.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.refactors.ApplicableRefactorInfo; + +/** + * Refactors response message. + * + * @see https://github.com/Microsoft/TypeScript/blob/master/src/server/protocol.ts + */ +public class GetApplicableRefactorsResponse extends Response> { + +} diff --git a/core/ts.core/src/ts/internal/client/protocol/GetRefactorCodeActionsRequest.java b/core/ts.core/src/ts/internal/client/protocol/GetRefactorCodeActionsRequest.java new file mode 100644 index 00000000..43d6aaed --- /dev/null +++ b/core/ts.core/src/ts/internal/client/protocol/GetRefactorCodeActionsRequest.java @@ -0,0 +1,33 @@ +/** + * 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; +import ts.client.refactors.RefactorCodeActions; + +/** + * @see https://github.com/Microsoft/TypeScript/blob/master/src/server/protocol.ts + */ +public class GetRefactorCodeActionsRequest extends Request { + + public GetRefactorCodeActionsRequest(String file, int line, int offset, String refactorName) { + super(CommandNames.GetRefactorCodeActions.getName(), + new GetRefactorCodeActionsRequestArgs(file, line, offset, refactorName)); + } + + @Override + public Response parseResponse(JsonObject json) { + return GsonHelper.DEFAULT_GSON.fromJson(json, GetRefactorCodeActionsResponse.class); + } + +} diff --git a/core/ts.core/src/ts/internal/client/protocol/GetRefactorCodeActionsRequestArgs.java b/core/ts.core/src/ts/internal/client/protocol/GetRefactorCodeActionsRequestArgs.java new file mode 100644 index 00000000..426a0e75 --- /dev/null +++ b/core/ts.core/src/ts/internal/client/protocol/GetRefactorCodeActionsRequestArgs.java @@ -0,0 +1,36 @@ +/** + * 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; + +/** + * + * @see https://github.com/Microsoft/TypeScript/blob/master/src/server/protocol.ts + * + */ +public class GetRefactorCodeActionsRequestArgs extends FileLocationRequestArgs { + + /* The kind of the applicable refactor */ + private String refactorName; + + public GetRefactorCodeActionsRequestArgs(String file, int position, String refactorName) { + super(file, position); + this.refactorName = refactorName; + } + + public GetRefactorCodeActionsRequestArgs(String file, int line, int offset, String refactorName) { + super(file, line, offset); + this.refactorName = refactorName; + } + + public String getRefactorName() { + return refactorName; + } +} diff --git a/core/ts.core/src/ts/internal/client/protocol/GetRefactorCodeActionsResponse.java b/core/ts.core/src/ts/internal/client/protocol/GetRefactorCodeActionsResponse.java new file mode 100644 index 00000000..1a927f5d --- /dev/null +++ b/core/ts.core/src/ts/internal/client/protocol/GetRefactorCodeActionsResponse.java @@ -0,0 +1,22 @@ +/** + * 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 ts.client.refactors.RefactorCodeActions; + +/** + * Refactor code actions response message. + * + * @see https://github.com/Microsoft/TypeScript/blob/master/src/server/protocol.ts + */ +public class GetRefactorCodeActionsResponse extends Response { + +}