forked from eclipse/lemminx
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature request: buttons to associate XML documents with schema files
Fixes eclipse#395 Signed-off-by: azerr <[email protected]>
- Loading branch information
1 parent
4497ae5
commit 8bf302f
Showing
3 changed files
with
65 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
...eclipse/lemminx/extensions/contentmodel/participants/ContentModelCodeLensParticipant.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2021 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 org.eclipse.lemminx.extensions.contentmodel.participants; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
import org.eclipse.lemminx.dom.DOMDocument; | ||
import org.eclipse.lemminx.dom.DOMElement; | ||
import org.eclipse.lemminx.services.extensions.codelens.ICodeLensParticipant; | ||
import org.eclipse.lemminx.services.extensions.codelens.ICodeLensRequest; | ||
import org.eclipse.lemminx.utils.XMLPositionUtility; | ||
import org.eclipse.lsp4j.CodeLens; | ||
import org.eclipse.lsp4j.Command; | ||
import org.eclipse.lsp4j.Range; | ||
import org.eclipse.lsp4j.jsonrpc.CancelChecker; | ||
|
||
public class ContentModelCodeLensParticipant implements ICodeLensParticipant { | ||
|
||
private static final String COMMAND_ID = "xml.associate.grammar.selectFile"; | ||
|
||
@Override | ||
public void doCodeLens(ICodeLensRequest request, List<CodeLens> lenses, CancelChecker cancelChecker) { | ||
DOMDocument document = request.getDocument(); | ||
DOMElement documentElement = document.getDocumentElement(); | ||
if (documentElement == null || document.hasGrammar()) { | ||
return; | ||
} | ||
String documentURI = document.getDocumentURI(); | ||
Range range = XMLPositionUtility.selectRootStartTag(document); | ||
|
||
lenses.add(createAssociateLens(documentURI, "Associate with XSD and schemaLocation", "XSD", "schemaLocation", | ||
range)); | ||
lenses.add(createAssociateLens(documentURI, "Associate with XSD and xml-model", "XSD", "xml-model", range)); | ||
lenses.add(createAssociateLens(documentURI, "Associate with DTD and DOCTYPE", "DTD", "DOCTYPE", range)); | ||
lenses.add(createAssociateLens(documentURI, "Associate with DTD and xml-model", "DTD", "xml-model", range)); | ||
} | ||
|
||
private static CodeLens createAssociateLens(String documentURI, String title, String type, String bindingKind, | ||
Range range) { | ||
Command command = new Command(title, COMMAND_ID, Arrays.asList(documentURI, type, bindingKind)); | ||
return new CodeLens(range, command, null); | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters