Skip to content

Commit

Permalink
fix: add languageId filter for options similar to microprofile
Browse files Browse the repository at this point in the history
Signed-off-by: azerr <[email protected]>
  • Loading branch information
angelozerr committed Oct 10, 2024
1 parent 910e2be commit 27c0522
Show file tree
Hide file tree
Showing 5 changed files with 129 additions and 35 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*******************************************************************************
* Copyright (c) 2024 Red Hat Inc. and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
* which is available at https://www.apache.org/licenses/LICENSE-2.0.
*
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
*
* Contributors:
* Red Hat Inc. - initial API and implementation
*******************************************************************************/
package com.redhat.quarkus;

/**
* Quarkus language ids.
*/
public class QuarkusLanguageIds {

public static final String QUARKUS_PROPERTIES = "quarkus-properties";

private QuarkusLanguageIds() {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,16 @@
*/
package com.redhat.quarkus.settings.capabilities;

import static org.eclipse.lsp4mp.settings.capabilities.ServerCapabilitiesConstants.TEXT_DOCUMENT_FORMATTING;
import static org.eclipse.lsp4mp.settings.capabilities.ServerCapabilitiesConstants.TEXT_DOCUMENT_RANGE_FORMATTING;
import java.util.List;

import org.eclipse.lsp4j.DocumentFilter;
import org.eclipse.lsp4j.Registration;
import org.eclipse.lsp4j.TextDocumentRegistrationOptions;

import org.eclipse.lsp4mp.MicroProfileLanguageIds;
import org.eclipse.lsp4mp.settings.capabilities.IMicroProfileRegistrationConfiguration;

import com.redhat.quarkus.QuarkusLanguageIds;

/**
* Specific Quarkus LSP Registration configuration
*
Expand All @@ -29,18 +30,16 @@ public class QuarkusRegistrationConfiguration implements IMicroProfileRegistrati

@Override
public void configure(Registration registration) {
switch (registration.getMethod()) {
case TEXT_DOCUMENT_FORMATTING:
case TEXT_DOCUMENT_RANGE_FORMATTING:
// add "quarkus-properties" as language document filter for formatting
((TextDocumentRegistrationOptions) registration.getRegisterOptions()).getDocumentSelector()
.add(new DocumentFilter("quarkus-properties", null, null));
break;
default:
break;

if (registration.getRegisterOptions() instanceof TextDocumentRegistrationOptions) {
List<DocumentFilter> documentSelector = ((TextDocumentRegistrationOptions) registration
.getRegisterOptions()).getDocumentSelector();
if (documentSelector != null && documentSelector.stream().anyMatch(filter -> filter != null
&& MicroProfileLanguageIds.MICROPROFILE_PROPERTIES.equals(filter.getLanguage()))) {
// Add "quarkus-properties" in the list of filter which contains
// "microprofile-properties"
documentSelector.add(new DocumentFilter(QuarkusLanguageIds.QUARKUS_PROPERTIES, null, null));
}
}

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*******************************************************************************
* Copyright (c) 2024 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
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Red Hat Inc. - initial API and implementation
*******************************************************************************/
package com.redhat.qute;

/**
* Qute language Ids.
*/
public class QuteLanguageIds {

public static final String QUTE_HTML = "qute-html";

public static final String QUTE_JSON = "qute-json";

public static final String QUTE_YAML = "qute-yaml";

public static final String QUTE_TXT = "qute-txt";

public static final String[] QUTE_ALL = { QUTE_HTML, QUTE_JSON, QUTE_YAML, QUTE_TXT };

private QuteLanguageIds() {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import static com.redhat.qute.settings.capabilities.ServerCapabilitiesConstants.CODE_LENS_ID;
import static com.redhat.qute.settings.capabilities.ServerCapabilitiesConstants.COMPLETION_ID;
import static com.redhat.qute.settings.capabilities.ServerCapabilitiesConstants.DEFAULT_CODELENS_OPTIONS;
import static com.redhat.qute.settings.capabilities.ServerCapabilitiesConstants.DEFAULT_COMPLETION_OPTIONS;
import static com.redhat.qute.settings.capabilities.ServerCapabilitiesConstants.DEFAULT_DOCUMENT_LINK_OPTIONS;
import static com.redhat.qute.settings.capabilities.ServerCapabilitiesConstants.DOCUMENT_DEFINITION_ID;
import static com.redhat.qute.settings.capabilities.ServerCapabilitiesConstants.DOCUMENT_HIGHLIGHT_ID;
Expand Down Expand Up @@ -44,20 +43,35 @@
import static com.redhat.qute.settings.capabilities.ServerCapabilitiesConstants.WORKSPACE_WATCHED_FILES_ID;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.eclipse.lsp4j.ClientCapabilities;
import org.eclipse.lsp4j.CodeActionKind;
import org.eclipse.lsp4j.CodeActionRegistrationOptions;
import org.eclipse.lsp4j.CompletionRegistrationOptions;
import org.eclipse.lsp4j.DefinitionRegistrationOptions;
import org.eclipse.lsp4j.DidChangeWatchedFilesRegistrationOptions;
import org.eclipse.lsp4j.DocumentFilter;
import org.eclipse.lsp4j.DocumentHighlightRegistrationOptions;
import org.eclipse.lsp4j.DocumentSymbolRegistrationOptions;
import org.eclipse.lsp4j.ExecuteCommandOptions;
import org.eclipse.lsp4j.FileSystemWatcher;
import org.eclipse.lsp4j.HoverRegistrationOptions;
import org.eclipse.lsp4j.InlayHintRegistrationOptions;
import org.eclipse.lsp4j.LinkedEditingRangeRegistrationOptions;
import org.eclipse.lsp4j.ReferenceRegistrationOptions;
import org.eclipse.lsp4j.Registration;
import org.eclipse.lsp4j.RegistrationParams;
import org.eclipse.lsp4j.RenameOptions;
import org.eclipse.lsp4j.TextDocumentRegistrationOptions;
import org.eclipse.lsp4j.jsonrpc.messages.Either;
import org.eclipse.lsp4j.services.LanguageClient;

import com.redhat.qute.QuteLanguageIds;
import com.redhat.qute.ls.commons.client.ExtendedClientCapabilities;

/**
Expand All @@ -80,43 +94,63 @@ public QuteCapabilityManager(LanguageClient languageClient) {
*/
public void initializeCapabilities() {
if (this.getClientCapabilities().isCodeActionDynamicRegistered()) {
registerCapability(CODE_ACTION_ID, TEXT_DOCUMENT_CODE_ACTION, ServerCapabilitiesConstants.DEFAULT_CODE_ACTION_OPTIONS);
// Code action is only available for Qute templates
CodeActionRegistrationOptions options = new CodeActionRegistrationOptions(
Arrays.asList(CodeActionKind.QuickFix, CodeActionKind.Empty));
options.setResolveProvider(true);
registerCapability(CODE_ACTION_ID, TEXT_DOCUMENT_CODE_ACTION, options, QuteLanguageIds.QUTE_ALL);
}
if (this.getClientCapabilities().isCodeLensDynamicRegistered()) {
// Code Lens is available for Qute templates and Java both
registerCapability(CODE_LENS_ID, TEXT_DOCUMENT_CODE_LENS, DEFAULT_CODELENS_OPTIONS);
}
if (this.getClientCapabilities().isCompletionDynamicRegistrationSupported()) {
registerCapability(COMPLETION_ID, TEXT_DOCUMENT_COMPLETION, DEFAULT_COMPLETION_OPTIONS);
// Completion is only available for Qute templates
CompletionRegistrationOptions options = new CompletionRegistrationOptions(
Arrays.asList("{", "@", "#", ".", ":", "$", "!"), false);
registerCapability(COMPLETION_ID, TEXT_DOCUMENT_COMPLETION, options, QuteLanguageIds.QUTE_ALL);
}
if (this.getClientCapabilities().isDefinitionDynamicRegistered()) {
registerCapability(DOCUMENT_DEFINITION_ID, TEXT_DOCUMENT_DEFINITION);
}
if (this.getClientCapabilities().isDocumentLinkDynamicRegistered()) {
registerCapability(DOCUMENT_DEFINITION_ID, TEXT_DOCUMENT_DEFINITION);
// Definition is only available for Qute templates
registerCapability(DOCUMENT_DEFINITION_ID, TEXT_DOCUMENT_DEFINITION, new DefinitionRegistrationOptions(),
QuteLanguageIds.QUTE_ALL);
}
if (this.getClientCapabilities().isDocumentHighlightDynamicRegistered()) {
registerCapability(DOCUMENT_HIGHLIGHT_ID, TEXT_DOCUMENT_HIGHLIGHT);
// Document highlight is only available for Qute templates
registerCapability(DOCUMENT_HIGHLIGHT_ID, TEXT_DOCUMENT_HIGHLIGHT,
new DocumentHighlightRegistrationOptions(), QuteLanguageIds.QUTE_ALL);
}
if (this.getClientCapabilities().isDocumentLinkDynamicRegistered()) {
// Document link is available for Qute templates and Java both
registerCapability(DOCUMENT_LINK_ID, TEXT_DOCUMENT_DOCUMENT_LINK, DEFAULT_DOCUMENT_LINK_OPTIONS);
}
if (this.getClientCapabilities().isDocumentSymbolDynamicRegistrationSupported()) {
registerCapability(DOCUMENT_SYMBOL_ID, TEXT_DOCUMENT_DOCUMENT_SYMBOL);
// Document symbol is only available for Qute templates
registerCapability(DOCUMENT_SYMBOL_ID, TEXT_DOCUMENT_DOCUMENT_SYMBOL,
new DocumentSymbolRegistrationOptions(), QuteLanguageIds.QUTE_ALL);
}
if (this.getClientCapabilities().isHoverDynamicRegistered()) {
registerCapability(HOVER_ID, TEXT_DOCUMENT_HOVER);
// Hover is only available for Qute templates
registerCapability(HOVER_ID, TEXT_DOCUMENT_HOVER, new HoverRegistrationOptions(), QuteLanguageIds.QUTE_ALL);
}
if (this.getClientCapabilities().isLinkedEditingRangeDynamicRegistered()) {
registerCapability(LINKED_EDITING_RANGE_ID, TEXT_DOCUMENT_LINKED_EDITING_RANGE);
// Linked editing range is only available for Qute templates
registerCapability(LINKED_EDITING_RANGE_ID, TEXT_DOCUMENT_LINKED_EDITING_RANGE,
new LinkedEditingRangeRegistrationOptions(), QuteLanguageIds.QUTE_ALL);
}
if (this.getClientCapabilities().isReferencesDynamicRegistrationSupported()) {
registerCapability(REFERENCES_ID, TEXT_DOCUMENT_REFERENCES);
// References is only available for Qute templates
registerCapability(REFERENCES_ID, TEXT_DOCUMENT_REFERENCES, new ReferenceRegistrationOptions(),
QuteLanguageIds.QUTE_ALL);
}
if (this.getClientCapabilities().isRenameDynamicRegistered()) {
registerCapability(RENAME_ID, TEXT_DOCUMENT_RENAME);
// Rename is only available for Qute templates
registerCapability(RENAME_ID, TEXT_DOCUMENT_RENAME, new RenameOptions(), QuteLanguageIds.QUTE_ALL);
}
if (this.getClientCapabilities().isInlayHintDynamicRegistered()) {
registerCapability(INLAY_HINT_ID, TEXT_DOCUMENT_INLAY_HINT);
// Inlay Hint is only available for Qute templates
registerCapability(INLAY_HINT_ID, TEXT_DOCUMENT_INLAY_HINT, new InlayHintRegistrationOptions(),
QuteLanguageIds.QUTE_ALL);
}
if (this.getClientCapabilities().isDidChangeWatchedFilesRegistered()) {
registerWatchedFiles();
Expand Down Expand Up @@ -150,12 +184,15 @@ public Set<String> getRegisteredCapabilities() {
return registeredCapabilities;
}

private void registerCapability(String id, String method) {
registerCapability(id, method, null);
}

private void registerCapability(String id, String method, Object options) {
private void registerCapability(String id, String method, Object options, String... languageIds) {
if (registeredCapabilities.add(id)) {
if (languageIds != null && languageIds.length > 0) {
List<DocumentFilter> documentSelector = new ArrayList<>();
((TextDocumentRegistrationOptions) options).setDocumentSelector(documentSelector);
for (String languageId : languageIds) {
documentSelector.add(new DocumentFilter(languageId, null, null));
}
}
Registration registration = new Registration(id, method, options);
RegistrationParams registrationParams = new RegistrationParams(Collections.singletonList(registration));
languageClient.registerCapability(registrationParams);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.eclipse.lsp4j.MarkupContent;
import org.eclipse.lsp4j.MarkupKind;

import com.redhat.qute.QuteLanguageIds;
import com.redhat.qute.commons.JavaElementKind;
import com.redhat.qute.commons.JavaMemberInfo;
import com.redhat.qute.commons.JavaMethodInfo;
Expand Down Expand Up @@ -94,7 +95,7 @@ public static MarkupContent getDocumentation(MethodValueResolver resolver,
documentation.append(":");
documentation.append(System.lineSeparator());
if (markdown) {
documentation.append("```qute-html");
documentation.append("```" + QuteLanguageIds.QUTE_HTML);
documentation.append(System.lineSeparator());
}
for (int i = 0; i < resolver.getSample().size(); i++) {
Expand Down Expand Up @@ -249,7 +250,7 @@ public static MarkupContent getDocumentation(CaseOperator operator, boolean mark
documentation.append(":");
documentation.append(System.lineSeparator());
if (markdown) {
documentation.append("```qute-html");
documentation.append("```" + QuteLanguageIds.QUTE_HTML);
documentation.append(System.lineSeparator());
}
for (int i = 0; i < operator.getSample().size(); i++) {
Expand Down

0 comments on commit 27c0522

Please sign in to comment.