From e76113734aa890635ef0bad37d000eea8720fec9 Mon Sep 17 00:00:00 2001 From: ltulloch Date: Thu, 16 May 2019 15:33:32 -0400 Subject: [PATCH] Upgrade lsp4j version to 0.7.1 and fixed errors it introduced Addition to https://github.com/angelozerr/lsp4xml/pull/372 Fixes #370 Signed-off-by: Nikolas Komonen --- .../lsp4xml/XMLTextDocumentService.java | 12 +++++++----- .../extensions/prolog/PrologModel.java | 3 ++- .../extensions/xsi/XSISchemaModel.java | 2 +- .../eclipse/lsp4xml/utils/StringUtils.java | 14 ++++++++++++++ .../java/org/eclipse/lsp4xml/XMLAssert.java | 19 ++++++++++++------- .../lsp4xml/commons/TextDocumentTest.java | 10 +++++----- .../eclipse/lsp4xml/dom/DOMParserTest.java | 12 ++++++------ pom.xml | 2 +- 8 files changed, 48 insertions(+), 26 deletions(-) diff --git a/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/XMLTextDocumentService.java b/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/XMLTextDocumentService.java index 33aa9baa1..0159c061e 100644 --- a/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/XMLTextDocumentService.java +++ b/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/XMLTextDocumentService.java @@ -49,6 +49,7 @@ import org.eclipse.lsp4j.FoldingRangeRequestParams; import org.eclipse.lsp4j.Hover; import org.eclipse.lsp4j.Location; +import org.eclipse.lsp4j.LocationLink; import org.eclipse.lsp4j.PublishDiagnosticsParams; import org.eclipse.lsp4j.ReferenceParams; import org.eclipse.lsp4j.RenameParams; @@ -144,7 +145,7 @@ public void triggerValidationIfNeeded() { private BasicCancelChecker monitor; private boolean codeActionLiteralSupport; private boolean hierarchicalDocumentSymbolSupport; - + public XMLTextDocumentService(XMLLanguageServer xmlLanguageServer) { this.xmlLanguageServer = xmlLanguageServer; this.documents = new TextDocuments(); @@ -183,8 +184,7 @@ public CompletableFuture, CompletionList>> completio String uri = params.getTextDocument().getUri(); TextDocument document = getDocument(uri); DOMDocument xmlDocument = getXMLDocument(document); - CompletionList list = getXMLLanguageService().doComplete(xmlDocument, params.getPosition(), - sharedSettings); + CompletionList list = getXMLLanguageService().doComplete(xmlDocument, params.getPosition(), sharedSettings); return Either.forRight(list); }); } @@ -311,11 +311,13 @@ public CompletableFuture> documentLink(DocumentLinkParams par } @Override - public CompletableFuture> definition(TextDocumentPositionParams params) { + public CompletableFuture, List>> definition( + TextDocumentPositionParams params) { return computeAsync((monitor) -> { TextDocument document = getDocument(params.getTextDocument().getUri()); DOMDocument xmlDocument = getXMLDocument(document); - return getXMLLanguageService().findDefinition(xmlDocument, params.getPosition()); + Either e = Either.forLeft(getXMLLanguageService().findDefinition(xmlDocument, params.getPosition())); + return e; }); } diff --git a/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/extensions/prolog/PrologModel.java b/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/extensions/prolog/PrologModel.java index 290a0c454..14b3851de 100644 --- a/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/extensions/prolog/PrologModel.java +++ b/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/extensions/prolog/PrologModel.java @@ -37,6 +37,7 @@ import org.eclipse.lsp4xml.services.extensions.ICompletionRequest; import org.eclipse.lsp4xml.services.extensions.ICompletionResponse; import org.eclipse.lsp4xml.settings.SharedSettings; +import org.eclipse.lsp4xml.utils.StringUtils; /** * This class holds values that represent the XSI xsd. Can be seen at @@ -124,7 +125,7 @@ private static void createCompletionItem(String attrName, boolean canSupportSnip MarkupContent markup = new MarkupContent(); markup.setKind(MarkupKind.MARKDOWN); - markup.setValue(documentation); + markup.setValue(StringUtils.getDefaultString(documentation)); item.setDocumentation(markup); response.addCompletionItem(item); } diff --git a/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/extensions/xsi/XSISchemaModel.java b/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/extensions/xsi/XSISchemaModel.java index 24bb524c5..6ff6e3543 100644 --- a/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/extensions/xsi/XSISchemaModel.java +++ b/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/extensions/xsi/XSISchemaModel.java @@ -145,7 +145,7 @@ private static void createCompletionItem(String attrName, boolean canSupportSnip defaultValue, enumerationValues, settings); MarkupContent markup = new MarkupContent(); markup.setKind(MarkupKind.MARKDOWN); - markup.setValue(documentation); + markup.setValue(StringUtils.getDefaultString(documentation)); item.setDocumentation(markup); response.addCompletionItem(item); } diff --git a/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/utils/StringUtils.java b/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/utils/StringUtils.java index 67aadbc46..ee7a31a2a 100644 --- a/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/utils/StringUtils.java +++ b/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/utils/StringUtils.java @@ -215,4 +215,18 @@ public static int getNumberOfNewLines(String text, boolean isWhitespace, String return newLineCounter; } + /** + * Given a string will give back a non null string that is either + * the given string, or an empty string. + * + * @param text + * @return + */ + public static String getDefaultString(String text) { + if(text != null) { + return text; + } + return ""; + } + } diff --git a/org.eclipse.lsp4xml/src/test/java/org/eclipse/lsp4xml/XMLAssert.java b/org.eclipse.lsp4xml/src/test/java/org/eclipse/lsp4xml/XMLAssert.java index 90751edcc..4b3520c70 100644 --- a/org.eclipse.lsp4xml/src/test/java/org/eclipse/lsp4xml/XMLAssert.java +++ b/org.eclipse.lsp4xml/src/test/java/org/eclipse/lsp4xml/XMLAssert.java @@ -55,6 +55,7 @@ import org.eclipse.lsp4xml.services.extensions.save.AbstractSaveContext; import org.eclipse.lsp4xml.settings.SharedSettings; import org.eclipse.lsp4xml.settings.XMLFormattingOptions; +import org.eclipse.lsp4xml.utils.StringUtils; import org.junit.Assert; /** @@ -82,6 +83,7 @@ public DOMDocument getDocument(String uri) { public void collectDocumentToValidate(Predicate validateDocumentPredicate) { } + } public static void testCompletionFor(String value, CompletionItem... expectedItems) throws BadLocationException { @@ -194,7 +196,8 @@ private static void assertCompletion(CompletionList completions, CompletionItem if (expected.getTextEdit().getNewText() != null) { Assert.assertEquals(expected.getTextEdit().getNewText(), match.getTextEdit().getNewText()); } - if (expected.getTextEdit().getRange() != null) { + Range r = expected.getTextEdit().getRange(); + if (r != null && r.getStart() != null && r.getEnd() != null) { Assert.assertEquals(expected.getTextEdit().getRange(), match.getTextEdit().getRange()); } } @@ -217,7 +220,7 @@ public static CompletionItem c(String label, String newText) { } public static CompletionItem c(String label, String newText, String filterText) { - return c(label, newText, null, filterText); + return c(label, newText, new Range(), filterText); } public static CompletionItem c(String label, String newText, Range range, String filterText) { @@ -303,14 +306,14 @@ public static void assertDiagnostics(List actual, Diagnostic... expe public static void assertDiagnostics(List actual, List expected, boolean filter) { List received = actual; final boolean filterMessage; - if(expected != null && !expected.isEmpty() && expected.get(0).getMessage() != null) { + if(expected != null && !expected.isEmpty() && !StringUtils.isEmpty(expected.get(0).getMessage())) { filterMessage = true; } else { filterMessage = false; } if (filter) { received = actual.stream().map(d -> { - Diagnostic simpler = new Diagnostic(d.getRange(), null); + Diagnostic simpler = new Diagnostic(d.getRange(), ""); simpler.setCode(d.getCode()); if(filterMessage) { simpler.setMessage(d.getMessage()); @@ -322,7 +325,7 @@ public static void assertDiagnostics(List actual, List e } public static Diagnostic d(int startLine, int startCharacter, int endLine, int endCharacter, IXMLErrorCode code) { - return d(startLine, startCharacter, endLine, endCharacter, code, null); + return d(startLine, startCharacter, endLine, endCharacter, code, ""); } public static Diagnostic d(int startLine, int startCharacter, int endCharacter, IXMLErrorCode code) { @@ -450,21 +453,23 @@ public static void assertCodeActions(List actual, CodeAction... expe // we don't want to compare title, etc ca.setCommand(null); ca.setKind(null); - ca.setTitle(null); + ca.setTitle(""); if (ca.getDiagnostics() != null) { ca.getDiagnostics().forEach(d -> { d.setSeverity(null); - d.setMessage(null); + d.setMessage(""); d.setSource(null); }); } }); + Assert.assertEquals(expected.length, actual.size()); Assert.assertArrayEquals(expected, actual.toArray()); } public static CodeAction ca(Diagnostic d, TextEdit te) { CodeAction codeAction = new CodeAction(); + codeAction.setTitle(""); codeAction.setDiagnostics(Arrays.asList(d)); VersionedTextDocumentIdentifier versionedTextDocumentIdentifier = new VersionedTextDocumentIdentifier(FILE_URI, diff --git a/org.eclipse.lsp4xml/src/test/java/org/eclipse/lsp4xml/commons/TextDocumentTest.java b/org.eclipse.lsp4xml/src/test/java/org/eclipse/lsp4xml/commons/TextDocumentTest.java index e67f30ae0..429e0bce1 100644 --- a/org.eclipse.lsp4xml/src/test/java/org/eclipse/lsp4xml/commons/TextDocumentTest.java +++ b/org.eclipse.lsp4xml/src/test/java/org/eclipse/lsp4xml/commons/TextDocumentTest.java @@ -22,7 +22,7 @@ public class TextDocumentTest { @Test public void testEmptyDocument() throws BadLocationException { - TextDocument document = new TextDocument("", null); + TextDocument document = new TextDocument("", ""); Position position = document.positionAt(0); Assert.assertEquals(0, position.getLine()); @@ -36,7 +36,7 @@ public void testEmptyDocument() throws BadLocationException { @Test public void testPositionAt() throws BadLocationException { - TextDocument document = new TextDocument("abcd\nefgh", null); + TextDocument document = new TextDocument("abcd\nefgh", ""); Position position = document.positionAt(0); Assert.assertEquals(0, position.getLine()); @@ -65,7 +65,7 @@ public void testPositionAt() throws BadLocationException { @Test public void testPositionAtEndLine() throws BadLocationException { - TextDocument document = new TextDocument("abcd\n", null); + TextDocument document = new TextDocument("abcd\n", ""); Position position = document.positionAt(4); Assert.assertEquals(0, position.getLine()); @@ -83,7 +83,7 @@ public void testPositionAtEndLine() throws BadLocationException { } Assert.assertNotNull(ex); - document = new TextDocument("abcd\nefgh\n", null); + document = new TextDocument("abcd\nefgh\n", ""); position = document.positionAt(9); Assert.assertEquals(1, position.getLine()); @@ -104,7 +104,7 @@ public void testPositionAtEndLine() throws BadLocationException { @Test public void testOffsetAt() throws BadLocationException { - TextDocument document = new TextDocument("abcd\nefgh", null); + TextDocument document = new TextDocument("abcd\nefgh", ""); Position position = new Position(0, 0); int offset = document.offsetAt(position); diff --git a/org.eclipse.lsp4xml/src/test/java/org/eclipse/lsp4xml/dom/DOMParserTest.java b/org.eclipse.lsp4xml/src/test/java/org/eclipse/lsp4xml/dom/DOMParserTest.java index 795637cb3..56d313f26 100644 --- a/org.eclipse.lsp4xml/src/test/java/org/eclipse/lsp4xml/dom/DOMParserTest.java +++ b/org.eclipse.lsp4xml/src/test/java/org/eclipse/lsp4xml/dom/DOMParserTest.java @@ -442,7 +442,7 @@ public void testPreserveWhitespaceContent() { @Test public void elementOffsets() { - DOMDocument document = DOMParser.getInstance().parse("", null, null); + DOMDocument document = DOMParser.getInstance().parse("", "", null); DOMElement a = document.getDocumentElement(); Assert.assertNotNull(a); Assert.assertEquals(a.getTagName(), "a"); @@ -493,7 +493,7 @@ public void testDoctype2() { " \n" + " \n" + " \n "; - DOMDocument document = DOMParser.getInstance().parse(xml, null, null); + DOMDocument document = DOMParser.getInstance().parse(xml, "", null); assertDoctype((DOMDocumentType)(document.getChild(0)), 0, 212, "html", DocumentTypeKind.SYSTEM.name(), null, "\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"", internal); } @@ -511,7 +511,7 @@ public void testDTDEntity() { entity.closed = true; doctype.addChild(entity); - DOMDocument document = DOMParser.getInstance().parse(xml, null, null); + DOMDocument document = DOMParser.getInstance().parse(xml, "", null); compareTrees(doctype, document.getChild(0)); } @@ -538,7 +538,7 @@ public void testDTDAllTypes() { doctype.addChild(element); doctype.addChild(attlist); - DOMDocument document = DOMParser.getInstance().parse(xml, null, null); + DOMDocument document = DOMParser.getInstance().parse(xml, "", null); compareTrees(doctype, document.getChild(0)); } @@ -885,8 +885,8 @@ private static DOMDocumentType createDoctypeNode(int start, int end, Integer nam Integer kindEnd, Integer publicIdStart, Integer publicIdEnd, Integer systemIdStart, Integer systemIdEnd, Integer internalSubsetStart, Integer internalSubsetEnd) { DOMDocumentType doctype = new DOMDocumentType(start, end, null); - doctype.name = nameStart != null ? new DTDDeclParameter(null, nameStart, nameEnd) : null;; - doctype.kind = kindStart != null ? new DTDDeclParameter(null, kindStart, kindEnd) : null;; + doctype.name = nameStart != null ? new DTDDeclParameter(null, nameStart, nameEnd) : null; + doctype.kind = kindStart != null ? new DTDDeclParameter(null, kindStart, kindEnd) : null; doctype.publicId = publicIdStart != null ? new DTDDeclParameter(null, publicIdStart, publicIdEnd) : null;; doctype.systemId = systemIdEnd != null ? new DTDDeclParameter(null, systemIdStart, systemIdEnd) : null;; doctype.internalSubset = internalSubsetStart != null ? new DTDDeclParameter(null, internalSubsetStart, internalSubsetEnd) : null;; diff --git a/pom.xml b/pom.xml index f52adc9f2..25d824cc1 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ lsp4xml is an XML specific implementation of the Language Server Protocol (LSP), and can be used with any editor that supports LSP, to offer an outstanding XML editing experience UTF-8 - 0.6.0 + 0.7.1 https://github.com/angelozerr/lsp4xml