Skip to content

Commit

Permalink
vscode-quarkus should not be a Java formatter
Browse files Browse the repository at this point in the history
Fixed redhat-developer/vscode-quarkus#166

Signed-off-by: azerr <azerr@redhat.com>
  • Loading branch information
angelozerr committed Jul 1, 2020
1 parent 475d3a1 commit ea29f08
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/**
* Copyright (c) 2020 Red Hat, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v20.html
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Red Hat Inc. - initial API and implementation
*/
package com.redhat.microprofile.settings.capabilities;

import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
* Formatting options to inform to the client that only properties file are
* supported for formatting.
*
* <pre>
*
* "registerOptions": {
"documentSelector": [
{ "language": "microprofile-properties" },
{ "language": "quarkus-properties" }
]
}
* </pre>
*
*/
public class FormattingRegisterOptions {

public static class DocumentFilter {

private String language;

public DocumentFilter(String language) {
this.language = language;
}

public String getLanguage() {
return language;
}
}

private final List<DocumentFilter> documentSelector;

public FormattingRegisterOptions(String... languages) {
this.documentSelector = Stream.of(languages).map(language -> new DocumentFilter(language))
.collect(Collectors.toList());
}

public List<DocumentFilter> getDocumentSelector() {
return documentSelector;
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
/*******************************************************************************
* Copyright (c) 2019 Red Hat Inc. and others. All rights reserved. This program
* and the accompanying materials which accompanies this distribution, and is
* available at http://www.eclipse.org/legal/epl-v20.html
/**
* Copyright (c) 2019-2020 Red Hat, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v20.html
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors: Red Hat Inc. - initial API and implementation
*******************************************************************************/
* Contributors:
* Red Hat Inc. - initial API and implementation
*/
package com.redhat.microprofile.settings.capabilities;

import static com.redhat.microprofile.settings.capabilities.ServerCapabilitiesConstants.CODE_ACTION_ID;
import static com.redhat.microprofile.settings.capabilities.ServerCapabilitiesConstants.CODE_LENS_ID;
import static com.redhat.microprofile.settings.capabilities.ServerCapabilitiesConstants.COMPLETION_ID;
import static com.redhat.microprofile.settings.capabilities.ServerCapabilitiesConstants.DEFAULT_COMPLETION_OPTIONS;
import static com.redhat.microprofile.settings.capabilities.ServerCapabilitiesConstants.DEFAULT_FORMATTING_OPTIONS;
import static com.redhat.microprofile.settings.capabilities.ServerCapabilitiesConstants.DEFINITION_ID;
import static com.redhat.microprofile.settings.capabilities.ServerCapabilitiesConstants.DOCUMENT_SYMBOL_ID;
import static com.redhat.microprofile.settings.capabilities.ServerCapabilitiesConstants.FORMATTING_ID;
Expand Down Expand Up @@ -74,14 +80,30 @@ public void initializeCapabilities() {
registerCapability(DEFINITION_ID, TEXT_DOCUMENT_DEFINITION);
}
if (this.getClientCapabilities().isFormattingDynamicRegistered()) {
registerCapability(FORMATTING_ID, TEXT_DOCUMENT_FORMATTING);
// The MP language server manages properties and Java files, but for formatting
// and range formatting
// feature, only properties file are supported.
// We need to inform to the client that only properties are supported for format
// feature with register options:
/**
* <pre>
* "registerOptions": {
"documentSelector": [
{ "language": "microprofile-properties" },
{ "language": "quarkus-properties" }
]
}
* </pre>
*/
registerCapability(FORMATTING_ID, TEXT_DOCUMENT_FORMATTING, DEFAULT_FORMATTING_OPTIONS);
}
if (this.getClientCapabilities().isFormattingDynamicRegistered()) {
registerCapability(RANGE_FORMATTING_ID, TEXT_DOCUMENT_RANGE_FORMATTING);
registerCapability(RANGE_FORMATTING_ID, TEXT_DOCUMENT_RANGE_FORMATTING, DEFAULT_FORMATTING_OPTIONS);
}
}

public void setClientCapabilities(ClientCapabilities clientCapabilities, ExtendedClientCapabilities extendedClientCapabilities) {
public void setClientCapabilities(ClientCapabilities clientCapabilities,
ExtendedClientCapabilities extendedClientCapabilities) {
this.clientWrapper = new ClientCapabilitiesWrapper(clientCapabilities, extendedClientCapabilities);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,12 @@ private ServerCapabilitiesConstants() {
public static final String CODE_ACTION_ID = UUID.randomUUID().toString();
public static final String CODE_LENS_ID = UUID.randomUUID().toString();

public static final CompletionOptions DEFAULT_COMPLETION_OPTIONS = new CompletionOptions(false, Arrays.asList(".",
"%", "=" /* triggered characters for properties file */ , "@" /* triggered characters for java snippets annotation */));
public static final CompletionOptions DEFAULT_COMPLETION_OPTIONS = new CompletionOptions(false,
Arrays.asList(".", "%", "=" /* triggered characters for properties file */ ,
"@" /* triggered characters for java snippets annotation */));

public static final CodeLensOptions DEFAULT_CODELENS_OPTIONS = new CodeLensOptions();

public static final FormattingRegisterOptions DEFAULT_FORMATTING_OPTIONS = new FormattingRegisterOptions(
"microprofile-properties", "quarkus-properties");
}

0 comments on commit ea29f08

Please sign in to comment.