Skip to content

Commit

Permalink
Fix #1316 - Vue.JS tests failures
Browse files Browse the repository at this point in the history
  • Loading branch information
zulus committed Sep 11, 2023
1 parent f0f32b0 commit 96f8bc4
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.contentassist.ICompletionProposal;
import org.eclipse.lsp4e.LanguageServerWrapper;
import org.eclipse.lsp4e.LanguageServersRegistry;
import org.eclipse.lsp4e.LanguageServiceAccessor;
import org.eclipse.lsp4e.operations.completion.LSContentAssistProcessor;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.editors.text.TextEditor;
Expand Down Expand Up @@ -86,8 +89,8 @@ void testVueApp() throws Exception {
IFile appComponentFile = project.getFile("src/App.vue");
TextEditor editor = (TextEditor) IDE
.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), appComponentFile);
DisplayHelper.sleep(4000); // Give time for LS to initialize enough before making edit and sending a
// didChange
LanguageServerWrapper lsWrapper = LanguageServiceAccessor.getLSWrapper(project,
LanguageServersRegistry.getInstance().getDefinition("org.eclipse.wildwebdeveloper.vue"));
assertTrue(new DisplayHelper() {
@Override
protected boolean condition() {
Expand All @@ -104,6 +107,16 @@ protected boolean condition() {
}.waitForCondition(editor.getSite().getShell().getDisplay(), 30000),
"Diagnostic not published in standalone component file");
IDocument document = editor.getDocumentProvider().getDocument(editor.getEditorInput());

assertTrue(new DisplayHelper() {

@Override
protected boolean condition() {
return lsWrapper.isActive() && lsWrapper.isConnectedTo(appComponentFile.getLocationURI())
&& lsWrapper.canOperate(project) && lsWrapper.canOperate(document);
}
}.waitForCondition(editor.getSite().getShell().getDisplay(), 30000));

LSContentAssistProcessor contentAssistProcessor = new LSContentAssistProcessor();
ICompletionProposal[] proposals = contentAssistProcessor.computeCompletionProposals(Utils.getViewer(editor),
document.get().indexOf(" }}"));
Expand All @@ -123,16 +136,13 @@ void testVueTemplate() throws Exception {
TextEditor editor = (TextEditor) IDE.openEditor(
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(),
componentFolder.getFile("HelloWorld.vue"));
DisplayHelper.sleep(4000); // Give time for LS to initialize enough before making edit and sending a
// didChange
LanguageServerWrapper lsWrapper = LanguageServiceAccessor.getLSWrapper(project,
LanguageServersRegistry.getInstance().getDefinition("org.eclipse.wildwebdeveloper.vue"));
IFile appComponentHTML = componentFolder.getFile("HelloWorld.vue");
editor = (TextEditor) IDE.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(),
appComponentHTML);
// Give some time for LS to load
DisplayHelper.sleep(2000);
// then make an edit
IDocument document = editor.getDocumentProvider().getDocument(editor.getEditorInput());
document.set(document.get() + "\n");

assertTrue(new DisplayHelper() {
@Override
protected boolean condition() {
Expand All @@ -149,9 +159,23 @@ protected boolean condition() {
}.waitForCondition(editor.getSite().getShell().getDisplay(), 30000),
"No error found on erroneous HTML component file");
// test completion

assertTrue(new DisplayHelper() {

@Override
protected boolean condition() {
return lsWrapper.isActive() && lsWrapper.isConnectedTo(appComponentHTML.getLocationURI())
&& lsWrapper.canOperate(project) && lsWrapper.canOperate(document);
}
}.waitForCondition(editor.getSite().getShell().getDisplay(), 30000));

// DisplayHelper.sleep(1000000);
LSContentAssistProcessor contentAssistProcessor = new LSContentAssistProcessor();
String tag = "<only-start>";
document.set(document.get().replace(tag, tag + "<"));
int pos = document.get().indexOf(tag) + tag.length();
ICompletionProposal[] proposals = contentAssistProcessor.computeCompletionProposals(Utils.getViewer(editor),
document.get().indexOf("<only-start>") + " <only-start>".length() - 1);
pos + 1);
proposals[0].apply(document);
assertEquals(new String(componentFolder.getFile("HelloWorldCorrect.vue").getContents().readAllBytes()).trim(),
document.get().trim(), "Incorrect completion insertion");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,10 @@ public Object getInitializationOptions(URI rootUri) {

try {
URL url = FileLocator.toFileURL(getClass().getResource("/node_modules/typescript/lib"));
System.out.println(new File(url.getPath()).getAbsolutePath());
return Collections.singletonMap("typescript", Collections.singletonMap("tsdk", new File(url.getPath()).getAbsolutePath()));
} catch (IOException e) {
Activator.getDefault().getLog().log(
new Status(IStatus.ERROR, Activator.getDefault().getBundle().getSymbolicName(), e.getMessage(), e));
}
return null;
}
Expand Down

0 comments on commit 96f8bc4

Please sign in to comment.