forked from eclipse-wildwebdeveloper/wildwebdeveloper
-
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.
[XML+HTML] Support for autoCloseTags
Fixes eclipse-wildwebdeveloper#143 Signed-off-by: azerr <azerr@redhat.com>
- Loading branch information
1 parent
d70dbb0
commit 9ef3d59
Showing
30 changed files
with
1,032 additions
and
154 deletions.
There are no files selected for viewing
258 changes: 160 additions & 98 deletions
258
org.eclipse.wildwebdeveloper.tests/src/org/eclipse/wildwebdeveloper/tests/TestHTML.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 |
---|---|---|
@@ -1,98 +1,160 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2019 Red Hat Inc. and others. | ||
* | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Mickael Istria (Red Hat Inc.) - initial implementation | ||
*******************************************************************************/ | ||
package org.eclipse.wildwebdeveloper.tests; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import java.io.ByteArrayInputStream; | ||
import java.util.concurrent.atomic.AtomicReference; | ||
|
||
import org.eclipse.core.resources.IFile; | ||
import org.eclipse.core.resources.IProject; | ||
import org.eclipse.core.resources.IResource; | ||
import org.eclipse.core.resources.ResourcesPlugin; | ||
import org.eclipse.core.runtime.CoreException; | ||
import org.eclipse.jface.text.TextSelection; | ||
import org.eclipse.ui.PlatformUI; | ||
import org.eclipse.ui.commands.ICommandService; | ||
import org.eclipse.ui.handlers.IHandlerService; | ||
import org.eclipse.ui.ide.IDE; | ||
import org.eclipse.ui.tests.harness.util.DisplayHelper; | ||
import org.eclipse.ui.texteditor.ITextEditor; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
|
||
@ExtendWith(AllCleanRule.class) | ||
public class TestHTML { | ||
|
||
@Test | ||
public void testHTMLFile() throws Exception { | ||
final IProject project = ResourcesPlugin.getWorkspace().getRoot() | ||
.getProject("testHTMLFile" + System.currentTimeMillis()); | ||
project.create(null); | ||
project.open(null); | ||
final IFile file = project.getFile("blah.html"); | ||
file.create(new ByteArrayInputStream("FAIL".getBytes()), true, null); | ||
ITextEditor editor = (ITextEditor) IDE | ||
.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), file); | ||
editor.getDocumentProvider().getDocument(editor.getEditorInput()).set("<style\n<html><"); | ||
assertTrue(new DisplayHelper() { | ||
@Override | ||
protected boolean condition() { | ||
try { | ||
return file.findMarkers("org.eclipse.lsp4e.diagnostic", true, IResource.DEPTH_ZERO).length != 0; | ||
} catch (CoreException e) { | ||
return false; | ||
} | ||
} | ||
}.waitForCondition(PlatformUI.getWorkbench().getDisplay(), 5000), "Diagnostic not published"); | ||
} | ||
|
||
@Test | ||
public void testFormat() throws Exception { | ||
final IProject project = ResourcesPlugin.getWorkspace().getRoot() | ||
.getProject("testHTMLFile" + System.currentTimeMillis()); | ||
project.create(null); | ||
project.open(null); | ||
final IFile file = project.getFile("blah.html"); | ||
file.create(new ByteArrayInputStream("<html><body><a></a></body></html>".getBytes()), true, null); | ||
ITextEditor editor = (ITextEditor) IDE | ||
.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), file); | ||
editor.setFocus(); | ||
editor.getSelectionProvider().setSelection(new TextSelection(0, 0)); | ||
IHandlerService handlerService = PlatformUI.getWorkbench().getService(IHandlerService.class); | ||
assertTrue( | ||
PlatformUI.getWorkbench().getService(ICommandService.class).getCommand("org.eclipse.lsp4e.format").isEnabled()); | ||
AtomicReference<Exception> ex = new AtomicReference<>(); | ||
new DisplayHelper() { | ||
@Override | ||
protected boolean condition() { | ||
try { | ||
handlerService.executeCommand("org.eclipse.lsp4e.format", null); | ||
return true; | ||
} catch (Exception e) { | ||
return false; | ||
} | ||
} | ||
}.waitForCondition(editor.getSite().getShell().getDisplay(), 3000); | ||
if (ex.get() != null) { | ||
throw ex.get(); | ||
} | ||
new DisplayHelper() { | ||
@Override | ||
protected boolean condition() { | ||
return editor.getDocumentProvider().getDocument(editor.getEditorInput()).getNumberOfLines() > 1; | ||
} | ||
}.waitForCondition(editor.getSite().getShell().getDisplay(), 3000); | ||
} | ||
} | ||
/******************************************************************************* | ||
* Copyright (c) 2019 Red Hat Inc. and others. | ||
* | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Mickael Istria (Red Hat Inc.) - initial implementation | ||
*******************************************************************************/ | ||
package org.eclipse.wildwebdeveloper.tests; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import java.io.ByteArrayInputStream; | ||
|
||
import org.eclipse.core.resources.IFile; | ||
import org.eclipse.core.resources.IProject; | ||
import org.eclipse.core.resources.IResource; | ||
import org.eclipse.core.resources.ResourcesPlugin; | ||
import org.eclipse.core.runtime.CoreException; | ||
import org.eclipse.jface.text.IDocument; | ||
import org.eclipse.jface.text.TextSelection; | ||
import org.eclipse.jface.text.contentassist.ICompletionProposal; | ||
import org.eclipse.lsp4e.operations.completion.LSContentAssistProcessor; | ||
import org.eclipse.ui.PlatformUI; | ||
import org.eclipse.ui.ide.IDE; | ||
import org.eclipse.ui.tests.harness.util.DisplayHelper; | ||
import org.eclipse.ui.texteditor.AbstractTextEditor; | ||
import org.eclipse.ui.texteditor.ITextEditor; | ||
import org.junit.Test; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
|
||
@ExtendWith(AllCleanRule.class) | ||
public class TestXML { | ||
|
||
private IProject project; | ||
private ICompletionProposal[] proposals; | ||
|
||
@BeforeEach | ||
public void setUpProject() throws CoreException { | ||
this.project = ResourcesPlugin.getWorkspace().getRoot().getProject(getClass().getName() + System.nanoTime()); | ||
project.create(null); | ||
project.open(null); | ||
} | ||
|
||
@Test | ||
public void testXMLFile() throws Exception { | ||
final IFile file = project.getFile("blah.xml"); | ||
file.create(new ByteArrayInputStream("FAIL".getBytes()), true, null); | ||
ITextEditor editor = (ITextEditor) IDE | ||
.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), file); | ||
editor.getDocumentProvider().getDocument(editor.getEditorInput()).set("<plugin></"); | ||
assertTrue(new DisplayHelper() { | ||
@Override | ||
protected boolean condition() { | ||
try { | ||
return file.findMarkers("org.eclipse.lsp4e.diagnostic", true, IResource.DEPTH_ZERO).length != 0; | ||
} catch (CoreException e) { | ||
return false; | ||
} | ||
} | ||
}.waitForCondition(PlatformUI.getWorkbench().getDisplay(), 5000), "Diagnostic not published"); | ||
} | ||
|
||
@Test | ||
public void testXSLFile() throws Exception { | ||
final IFile file = project.getFile("blah.xsl"); | ||
file.create(new ByteArrayInputStream("FAIL".getBytes()), true, null); | ||
ITextEditor editor = (ITextEditor) IDE | ||
.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), file); | ||
editor.getDocumentProvider().getDocument(editor.getEditorInput()).set("FAIL"); | ||
assertTrue(new DisplayHelper() { | ||
@Override | ||
protected boolean condition() { | ||
try { | ||
return file.findMarkers("org.eclipse.lsp4e.diagnostic", true, IResource.DEPTH_ZERO).length != 0; | ||
} catch (CoreException e) { | ||
return false; | ||
} | ||
} | ||
}.waitForCondition(PlatformUI.getWorkbench().getDisplay(), 5000), "Diagnostic not published"); | ||
} | ||
|
||
@Test | ||
public void testXSDFile() throws Exception { | ||
final IFile file = project.getFile("blah.xsd"); | ||
file.create(new ByteArrayInputStream("FAIL".getBytes()), true, null); | ||
ITextEditor editor = (ITextEditor) IDE | ||
.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), file); | ||
editor.getDocumentProvider().getDocument(editor.getEditorInput()).set("a<"); | ||
assertTrue(new DisplayHelper() { | ||
@Override | ||
protected boolean condition() { | ||
try { | ||
return file.findMarkers("org.eclipse.lsp4e.diagnostic", true, IResource.DEPTH_ZERO).length != 0; | ||
} catch (CoreException e) { | ||
return false; | ||
} | ||
} | ||
}.waitForCondition(PlatformUI.getWorkbench().getDisplay(), 5000), "Diagnostic not published"); | ||
} | ||
|
||
@Test | ||
public void testDTDFile() throws Exception { | ||
final IFile file = project.getFile("blah.dtd"); | ||
file.create(new ByteArrayInputStream("FAIL".getBytes()), true, null); | ||
ITextEditor editor = (ITextEditor) IDE | ||
.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), file); | ||
editor.getDocumentProvider().getDocument(editor.getEditorInput()).set("<!--<!-- -->"); | ||
assertTrue(new DisplayHelper() { | ||
@Override | ||
protected boolean condition() { | ||
try { | ||
return file.findMarkers("org.eclipse.lsp4e.diagnostic", true, IResource.DEPTH_ZERO).length != 0; | ||
} catch (CoreException e) { | ||
return false; | ||
} | ||
} | ||
}.waitForCondition(PlatformUI.getWorkbench().getDisplay(), 5000), "Diagnostic not published"); | ||
} | ||
|
||
@Test | ||
public void testComplexXML() throws Exception { | ||
final IFile file = project.getFile("blah.xml"); | ||
String content = "<layout:BlockLayoutCell\n" + " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" \n" | ||
+ " xsi:schemaLocation=\"sap.ui.layout https://openui5.hana.ondemand.com/downloads/schemas/sap.ui.layout.xsd\"\n" | ||
+ " xmlns:layout=\"sap.ui.layout\">\n" + " |\n" + "</layout:BlockLayoutCell>"; | ||
int offset = content.indexOf('|'); | ||
content = content.replace("|", ""); | ||
file.create(new ByteArrayInputStream(content.getBytes()), true, null); | ||
AbstractTextEditor editor = (AbstractTextEditor) IDE.openEditor( | ||
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), file, | ||
"org.eclipse.ui.genericeditor.GenericEditor"); | ||
editor.getSelectionProvider().setSelection(new TextSelection(offset, 0)); | ||
LSContentAssistProcessor processor = new LSContentAssistProcessor(); | ||
proposals = processor.computeCompletionProposals(Utils.getViewer(editor), offset); | ||
DisplayHelper.sleep(editor.getSite().getShell().getDisplay(), 2000); | ||
assertTrue(proposals.length > 1); | ||
} | ||
|
||
@Test | ||
public void autoCloseTags() throws Exception { | ||
final IFile file = project.getFile("autoCloseTags.xml"); | ||
file.create(new ByteArrayInputStream("<foo".getBytes()), true, null); | ||
ITextEditor editor = (ITextEditor) IDE | ||
.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), file); | ||
IDocument document = editor.getDocumentProvider().getDocument(editor.getEditorInput()); | ||
document.replace(4, 0, ">"); | ||
assertTrue(new DisplayHelper() { | ||
@Override | ||
protected boolean condition() { | ||
return "<foo></foo>".equals(document.get()); | ||
} | ||
}.waitForCondition(PlatformUI.getWorkbench().getDisplay(), 5000), "Autoclose not done"); | ||
} | ||
} |
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
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
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
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
30 changes: 30 additions & 0 deletions
30
...dwebdeveloper.xml/src/org/eclipse/wildwebdeveloper/xml/internal/XMLLanguageServerAPI.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,30 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2020 Red Hat Inc. and others. | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Victor Rubezhny (Red Hat Inc.) - initial implementation | ||
*******************************************************************************/ | ||
package org.eclipse.wildwebdeveloper.xml.internal; | ||
|
||
import java.util.concurrent.CompletableFuture; | ||
|
||
import org.eclipse.lsp4j.TextDocumentPositionParams; | ||
import org.eclipse.lsp4j.jsonrpc.services.JsonRequest; | ||
import org.eclipse.lsp4j.services.LanguageServer; | ||
import org.eclipse.wildwebdeveloper.xml.internal.autoclose.AutoCloseTagResponse; | ||
|
||
/** | ||
* XML language server API which defines custom LSP commands. | ||
* | ||
*/ | ||
public interface XMLLanguageServerAPI extends LanguageServer { | ||
|
||
@JsonRequest("xml/closeTag") | ||
CompletableFuture<AutoCloseTagResponse> closeTag(TextDocumentPositionParams params); | ||
|
||
} |
Oops, something went wrong.