Java Code Examples for org.eclipse.lsp4j.CodeActionKind#SourceOrganizeImports

The following examples show how to use org.eclipse.lsp4j.CodeActionKind#SourceOrganizeImports . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OrganizeImportsCommand.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
public void organizeImportsInCompilationUnit(ICompilationUnit unit, WorkspaceEdit rootEdit) {
	try {
		InnovationContext context = new InnovationContext(unit, 0, unit.getBuffer().getLength() - 1);
		CUCorrectionProposal proposal = new CUCorrectionProposal("OrganizeImports", CodeActionKind.SourceOrganizeImports, unit, null, IProposalRelevance.ORGANIZE_IMPORTS) {
			@Override
			protected void addEdits(IDocument document, TextEdit editRoot) throws CoreException {
				CompilationUnit astRoot = context.getASTRoot();
				OrganizeImportsOperation op = new OrganizeImportsOperation(unit, astRoot, true, false, true, null);
				TextEdit edit = op.createTextEdit(null);
				TextEdit staticEdit = OrganizeImportsHandler.wrapStaticImports(edit, astRoot, unit);
				if (staticEdit.getChildrenSize() > 0) {
					editRoot.addChild(staticEdit);
				}
			}
		};

		addWorkspaceEdit(unit, proposal, rootEdit);
	} catch (CoreException e) {
		JavaLanguageServerPlugin.logException("Problem organize imports ", e);
	}
}
 
Example 2
Source File: JDTLanguageServer.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
private CodeActionOptions getCodeActionOptions() {
	String[] kinds = { CodeActionKind.QuickFix, CodeActionKind.Refactor, CodeActionKind.RefactorExtract, CodeActionKind.RefactorInline, CodeActionKind.RefactorRewrite, CodeActionKind.Source, CodeActionKind.SourceOrganizeImports };
	List<String> codeActionKinds = new ArrayList<>();
	for (String kind : kinds) {
		if (preferenceManager.getClientPreferences().isSupportedCodeActionKind(kind)) {
			codeActionKinds.add(kind);
		}
	}
	CodeActionOptions options = new CodeActionOptions(codeActionKinds);
	return options;
}