Skip to content

Commit

Permalink
language-server: code actions result now includes organize imports, a…
Browse files Browse the repository at this point in the history
…nd generate getter/setter type is now RefactorRewrite (closes #289)

language-server: upgrade to eclipse/lsp4j v0.6.0
  • Loading branch information
joshtynjala committed Dec 5, 2018
1 parent a8de004 commit fb9b904
Show file tree
Hide file tree
Showing 8 changed files with 92 additions and 115 deletions.
2 changes: 1 addition & 1 deletion language-server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ limitations under the License.
<dependency>
<groupId>org.eclipse.lsp4j</groupId>
<artifactId>org.eclipse.lsp4j</artifactId>
<version>0.5.0</version>
<version>0.6.0</version>
<scope>compile</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,11 @@
import com.as3mxml.vscode.commands.ICommandConstants;
import com.as3mxml.vscode.project.IProjectConfigStrategyFactory;
import com.as3mxml.vscode.services.ActionScriptLanguageClient;
import com.google.common.collect.Lists;

import org.apache.royale.compiler.tree.as.IASNode;
import org.eclipse.lsp4j.CodeActionKind;
import org.eclipse.lsp4j.CodeActionOptions;
import org.eclipse.lsp4j.CompletionOptions;
import org.eclipse.lsp4j.DidChangeWatchedFilesRegistrationOptions;
import org.eclipse.lsp4j.ExecuteCommandOptions;
Expand Down Expand Up @@ -107,7 +110,13 @@ public CompletableFuture<InitializeResult> initialize(InitializeParams params)
ServerCapabilities serverCapabilities = new ServerCapabilities();
serverCapabilities.setTextDocumentSync(TextDocumentSyncKind.Incremental);

serverCapabilities.setCodeActionProvider(true);
serverCapabilities.setCodeActionProvider(
new CodeActionOptions(
Lists.newArrayList(
CodeActionKind.QuickFix,
CodeActionKind.Refactor,
CodeActionKind.RefactorRewrite,
CodeActionKind.SourceOrganizeImports)));

CompletionOptions completionOptions = new CompletionOptions();
completionOptions.setTriggerCharacters(Arrays.asList(".", ":", " ", "<"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@
import org.apache.royale.compiler.workspaces.IWorkspace;
import org.apache.royale.utils.FilenameNormalization;

import com.google.common.collect.Lists;
import com.google.common.io.Files;
import com.google.gson.JsonObject;
import com.google.gson.JsonPrimitive;
Expand Down Expand Up @@ -1243,6 +1244,7 @@ public CompletableFuture<List<Either<Command, CodeAction>>> codeAction(CodeActio
return Collections.emptyList();
}
List<Either<Command, CodeAction>> codeActions = new ArrayList<>();
findSourceActions(textDocument, codeActions);
findCodeActionsForDiagnostics(textDocument, diagnostics, codeActions);

ICompilationUnit unit = getCompilationUnit(path);
Expand Down Expand Up @@ -1272,6 +1274,24 @@ public CompletableFuture<List<Either<Command, CodeAction>>> codeAction(CodeActio
}
});
}

public void findSourceActions(TextDocumentIdentifier textDocument, List<Either<Command, CodeAction>> codeActions)
{
Command organizeCommand = new Command();
organizeCommand.setTitle("Organize Imports");
organizeCommand.setCommand(ICommandConstants.ORGANIZE_IMPORTS_IN_URI);
JsonObject uri = new JsonObject();
uri.addProperty("external", textDocument.getUri());
organizeCommand.setArguments(Lists.newArrayList(
uri
));
CodeAction organizeImports = new CodeAction();
organizeImports.setKind(CodeActionKind.SourceOrganizeImports);
organizeImports.setTitle(organizeCommand.getTitle());
organizeImports.setCommand(organizeCommand);
codeActions.add(Either.forRight(organizeImports));
}

public void findCodeActionsForDiagnostics(TextDocumentIdentifier textDocument, List<? extends Diagnostic> diagnostics, List<Either<Command, CodeAction>> codeActions)
{
for (Diagnostic diagnostic : diagnostics)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,23 +114,23 @@ private static void createCodeActionsForGenerateGetterAndSetter(IVariableNode va
CodeAction getAndSetCodeAction = new CodeAction();
getAndSetCodeAction.setTitle("Generate 'get' and 'set' accessors");
getAndSetCodeAction.setEdit(getSetEdit);
getAndSetCodeAction.setKind(CodeActionKind.QuickFix);
getAndSetCodeAction.setKind(CodeActionKind.RefactorRewrite);
codeActions.add(Either.forRight(getAndSetCodeAction));

WorkspaceEdit getterEdit = createWorkspaceEditForGenerateGetterAndSetter(
variableNode, uri, fileText, true, false);
CodeAction getterCodeAction = new CodeAction();
getterCodeAction.setTitle("Generate 'get' accessor (make read-only)");
getterCodeAction.setEdit(getterEdit);
getterCodeAction.setKind(CodeActionKind.QuickFix);
getterCodeAction.setKind(CodeActionKind.RefactorRewrite);
codeActions.add(Either.forRight(getterCodeAction));

WorkspaceEdit setterEdit = createWorkspaceEditForGenerateGetterAndSetter(
variableNode, uri, fileText, false, true);
CodeAction setterCodeAction = new CodeAction();
setterCodeAction.setTitle("Generate 'set' accessor (make write-only)");
setterCodeAction.setEdit(setterEdit);
setterCodeAction.setKind(CodeActionKind.QuickFix);
setterCodeAction.setKind(CodeActionKind.RefactorRewrite);
codeActions.add(Either.forRight(setterCodeAction));
}

Expand Down
43 changes: 0 additions & 43 deletions vscode-extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@
"workspaceContains:**/asconfig.*.json",
"onView:actionScriptSourcePaths",
"onCommand:as3mxml.adapterExecutableCommandSWF",
"onCommand:as3mxml.organizeImportsInTextEditor",
"onCommand:as3mxml.organizeImportsInUri",
"onCommand:as3mxml.organizeImportsInDirectory",
"onCommand:as3mxml.selectWorkspaceSDK",
Expand All @@ -77,10 +76,6 @@
"command": "as3mxml.restartServer",
"title": "ActionScript: Restart ActionScript/MXML server"
},
{
"command": "as3mxml.organizeImportsInTextEditor",
"title": "ActionScript: Organize Imports"
},
{
"command": "as3mxml.organizeImportsInUri",
"title": "Organize Imports"
Expand All @@ -103,14 +98,6 @@
],
"menus": {
"commandPalette": [
{
"command": "as3mxml.organizeImportsInTextEditor",
"when": "editorLangId == nextgenas"
},
{
"command": "as3mxml.organizeImportsInTextEditor",
"when": "editorLangId == mxml"
},
{
"command": "as3mxml.organizeImportsInUri",
"when": "false"
Expand All @@ -120,37 +107,7 @@
"when": "false"
}
],
"editor/context": [
{
"command": "as3mxml.organizeImportsInUri",
"when": "editorLangId == nextgenas",
"group": "1_modification"
},
{
"command": "as3mxml.organizeImportsInUri",
"when": "editorLangId == mxml",
"group": "1_modification"
}
],
"editor/title/context": [
{
"command": "as3mxml.organizeImportsInUri",
"when": "resourceLangId == nextgenas"
},
{
"command": "as3mxml.organizeImportsInUri",
"when": "resourceLangId == mxml"
}
],
"explorer/context": [
{
"command": "as3mxml.organizeImportsInUri",
"when": "resourceLangId == nextgenas"
},
{
"command": "as3mxml.organizeImportsInUri",
"when": "resourceLangId == mxml"
},
{
"command": "as3mxml.organizeImportsInDirectory",
"when": "explorerResourceIsFolder"
Expand Down

This file was deleted.

2 changes: 0 additions & 2 deletions vscode-extension/src/main/ts/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
import organizeImportsInTextEditor from "./commands/organizeImportsInTextEditor";
import findJava from "./utils/findJava";
import validateJava from "./utils/validateJava";
import validateEditorSDK from "./utils/validateEditorSDK";
Expand Down Expand Up @@ -232,7 +231,6 @@ export function activate(context: vscode.ExtensionContext)
}
quickCompileAndDebug();
});
vscode.commands.registerTextEditorCommand("as3mxml.organizeImportsInTextEditor", organizeImportsInTextEditor);

//don't activate these things unless we're in a workspace
if(vscode.workspace.workspaceFolders !== undefined)
Expand Down
Loading

0 comments on commit fb9b904

Please sign in to comment.