From d0e7b9c4d3a95cc76b1df71609f70aad8c36b616 Mon Sep 17 00:00:00 2001 From: David Kwon Date: Fri, 17 Apr 2020 17:12:19 -0400 Subject: [PATCH] Change xml.symbols.maxItemsComputed to xml.maxItemsComputed Signed-off-by: David Kwon --- .../eclipse/lemminx/XMLLanguageServer.java | 2 ++ .../lemminx/XMLTextDocumentService.java | 14 ++++++++----- .../lemminx/services/XMLLanguageService.java | 16 +++++++-------- .../lemminx/services/XMLSymbolsProvider.java | 12 +++++------ .../lemminx/settings/SharedSettings.java | 9 +++++++++ .../settings/XMLGeneralClientSettings.java | 10 ++++++++++ .../lemminx/settings/XMLSymbolSettings.java | 10 ---------- .../java/org/eclipse/lemminx/XMLAssert.java | 15 ++++---------- .../services/XMLDocumentSymbolsTest.java | 20 ++++++++----------- .../services/XMLSymbolInformationsTest.java | 20 +++++++++---------- 10 files changed, 65 insertions(+), 63 deletions(-) diff --git a/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/XMLLanguageServer.java b/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/XMLLanguageServer.java index 00a07e400..8c896cdd8 100644 --- a/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/XMLLanguageServer.java +++ b/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/XMLLanguageServer.java @@ -164,6 +164,8 @@ public synchronized void updateSettings(Object initializationOptionsSettings) { String workDir = serverSettings.getNormalizedWorkDir(); FilesUtils.setCachePathSetting(workDir); } + + xmlTextDocumentService.updateMaxItemsComputed(xmlClientSettings.getMaxItemsComputed()); } ContentModelSettings cmSettings = ContentModelSettings .getContentModelXMLSettings(initializationOptionsSettings); diff --git a/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/XMLTextDocumentService.java b/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/XMLTextDocumentService.java index 1ee408862..17d371599 100644 --- a/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/XMLTextDocumentService.java +++ b/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/XMLTextDocumentService.java @@ -224,9 +224,10 @@ public CompletableFuture>> docume return computeDOMAsync(params.getTextDocument(), (cancelChecker, xmlDocument) -> { boolean resultLimitExceeded = false; List> symbols = null; + int symbolsLimit = sharedSettings.getMaxItemsComputed(); if (hierarchicalDocumentSymbolSupport) { - DocumentSymbolsResult result = getXMLLanguageService().findDocumentSymbols(xmlDocument, symbolSettings, + DocumentSymbolsResult result = getXMLLanguageService().findDocumentSymbols(xmlDocument, symbolsLimit, cancelChecker); resultLimitExceeded = result.isResultLimitExceeded(); symbols = result // @@ -238,7 +239,7 @@ public CompletableFuture>> docume .collect(Collectors.toList()); } SymbolInformationsResult result = getXMLLanguageService() - .findSymbolInformations(xmlDocument, symbolSettings, cancelChecker); + .findSymbolInformations(xmlDocument, symbolsLimit, cancelChecker); resultLimitExceeded = result.isResultLimitExceeded(); symbols = result.stream() // .map(s -> { @@ -250,9 +251,9 @@ public CompletableFuture>> docume if (resultLimitExceeded) { String filename = Paths.get(xmlDocument.getTextDocument().getUri()).getFileName().toString(); String message = filename != null ? filename + ": " : ""; - message += "For performance reasons, document symbols have been limited to " + symbolSettings.getMaxItemsComputed() + " items."; + message += "For performance reasons, document symbols have been limited to " + symbolsLimit + " items."; if (sharedSettings.isActionableNotificationSupport() && sharedSettings.isOpenSettingsCommandSupport()) { - Command command = new Command("Configure limit", ClientCommands.OPEN_SETTINGS, Collections.singletonList("xml.symbols.maxItemsComputed")); + Command command = new Command("Configure limit", ClientCommands.OPEN_SETTINGS, Collections.singletonList("xml.maxItemsComputed")); ActionableNotification notification = new ActionableNotification().withSeverity(MessageType.Info).withMessage(message).withCommands(Collections.singletonList(command)); xmlLanguageServer.getLanguageClient().actionableNotification(notification); } else { @@ -484,7 +485,6 @@ public void updateSymbolSettings(XMLSymbolSettings newSettings) { if (newPatterns != null) { symbolSettings.setExcluded(newPatterns); } - symbolSettings.setMaxItemsComputed(newSettings.getMaxItemsComputed()); } public void updateCodeLensSettings(XMLCodeLensSettings newSettings) { @@ -492,6 +492,10 @@ public void updateCodeLensSettings(XMLCodeLensSettings newSettings) { codeLensSettings.setEnabled(newSettings.isEnabled()); } + public void updateMaxItemsComputed(int maxItemsComputed) { + sharedSettings.setMaxItemsComputed(maxItemsComputed); + } + public XMLSymbolSettings getSharedSymbolSettings() { return sharedSettings.getSymbolSettings(); } diff --git a/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/services/XMLLanguageService.java b/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/services/XMLLanguageService.java index 9ceced107..590e235fc 100644 --- a/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/services/XMLLanguageService.java +++ b/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/services/XMLLanguageService.java @@ -114,20 +114,20 @@ public List findDocumentHighlights(DOMDocument xmlDocument, P return highlighting.findDocumentHighlights(xmlDocument, position, cancelChecker); } - public List findSymbolInformations(DOMDocument xmlDocument, XMLSymbolSettings symbolSettings) { - return findSymbolInformations(xmlDocument, symbolSettings, NULL_CHECKER); + public List findSymbolInformations(DOMDocument xmlDocument, int symbolsLimit) { + return findSymbolInformations(xmlDocument, symbolsLimit, NULL_CHECKER); } - public SymbolInformationsResult findSymbolInformations(DOMDocument xmlDocument, XMLSymbolSettings symbolSettings, CancelChecker cancelChecker) { - return symbolsProvider.findSymbolInformations(xmlDocument, symbolSettings, cancelChecker); + public SymbolInformationsResult findSymbolInformations(DOMDocument xmlDocument, int symbolsLimit, CancelChecker cancelChecker) { + return symbolsProvider.findSymbolInformations(xmlDocument, symbolsLimit, cancelChecker); } - public List findDocumentSymbols(DOMDocument xmlDocument, XMLSymbolSettings symbolSettings) { - return findDocumentSymbols(xmlDocument, symbolSettings, NULL_CHECKER); + public List findDocumentSymbols(DOMDocument xmlDocument, int symbolsLimit) { + return findDocumentSymbols(xmlDocument, symbolsLimit, NULL_CHECKER); } - public DocumentSymbolsResult findDocumentSymbols(DOMDocument xmlDocument, XMLSymbolSettings symbolSettings, CancelChecker cancelChecker) { - return symbolsProvider.findDocumentSymbols(xmlDocument, symbolSettings, cancelChecker); + public DocumentSymbolsResult findDocumentSymbols(DOMDocument xmlDocument, int symbolsLimit, CancelChecker cancelChecker) { + return symbolsProvider.findDocumentSymbols(xmlDocument, symbolsLimit, cancelChecker); } public CompletionList doComplete(DOMDocument xmlDocument, Position position, SharedSettings settings) { diff --git a/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/services/XMLSymbolsProvider.java b/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/services/XMLSymbolsProvider.java index 0632a415b..5ab795649 100644 --- a/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/services/XMLSymbolsProvider.java +++ b/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/services/XMLSymbolsProvider.java @@ -59,11 +59,11 @@ public XMLSymbolsProvider(XMLExtensionsRegistry extensionsRegistry) { this.extensionsRegistry = extensionsRegistry; } - public SymbolInformationsResult findSymbolInformations(DOMDocument xmlDocument, XMLSymbolSettings symbolSettings, + public SymbolInformationsResult findSymbolInformations(DOMDocument xmlDocument, int symbolsLimit, CancelChecker cancelChecker) { SymbolInformationsResult symbols = new SymbolInformationsResult(); - AtomicLong limit = symbolSettings.getMaxItemsComputed() > 0 - ? new AtomicLong(symbolSettings.getMaxItemsComputed()) + AtomicLong limit = symbolsLimit > 0 + ? new AtomicLong(symbolsLimit) : null; boolean isDTD = xmlDocument.isDTD(); try { @@ -82,11 +82,11 @@ public SymbolInformationsResult findSymbolInformations(DOMDocument xmlDocument, return symbols; } - public DocumentSymbolsResult findDocumentSymbols(DOMDocument xmlDocument, XMLSymbolSettings symbolSettings, + public DocumentSymbolsResult findDocumentSymbols(DOMDocument xmlDocument, int symbolsLimit, CancelChecker cancelChecker) { DocumentSymbolsResult symbols = new DocumentSymbolsResult(); - AtomicLong limit = symbolSettings.getMaxItemsComputed() > 0 - ? new AtomicLong(symbolSettings.getMaxItemsComputed()) + AtomicLong limit = symbolsLimit > 0 + ? new AtomicLong(symbolsLimit) : null; boolean isDTD = xmlDocument.isDTD(); List nodesToIgnore = new ArrayList<>(); diff --git a/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/settings/SharedSettings.java b/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/settings/SharedSettings.java index 996db53b6..f78ab59ed 100644 --- a/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/settings/SharedSettings.java +++ b/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/settings/SharedSettings.java @@ -26,6 +26,7 @@ public class SharedSettings { private final XMLCodeLensSettings codeLensSettings; private final XMLHoverSettings hoverSettings; + private int maxItemsComputed; private boolean actionableNotificationSupport; private boolean openSettingsCommandSupport; @@ -85,4 +86,12 @@ public void setOpenSettingsCommandSupport(boolean openSettingsCommandSupport) { this.openSettingsCommandSupport = openSettingsCommandSupport; } + public int getMaxItemsComputed() { + return maxItemsComputed; + } + + public void setMaxItemsComputed(int maxItemsComputed) { + this.maxItemsComputed = maxItemsComputed; + } + } \ No newline at end of file diff --git a/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/settings/XMLGeneralClientSettings.java b/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/settings/XMLGeneralClientSettings.java index 8bf1d5ade..86436b895 100644 --- a/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/settings/XMLGeneralClientSettings.java +++ b/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/settings/XMLGeneralClientSettings.java @@ -47,6 +47,8 @@ public class XMLGeneralClientSettings { private XMLCodeLensSettings codeLens; + private int maxItemsComputed; + public void setLogs(LogsSettings logs) { this.logs = logs; } @@ -124,4 +126,12 @@ public void setServer(ServerSettings server) { public static XMLGeneralClientSettings getGeneralXMLSettings(Object initializationOptionsSettings) { return JSONUtility.toModel(initializationOptionsSettings, XMLGeneralClientSettings.class); } + + public int getMaxItemsComputed() { + return maxItemsComputed; + } + + public void setMaxItemsComputed(int maxItemsComputed) { + this.maxItemsComputed = maxItemsComputed; + } } \ No newline at end of file diff --git a/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/settings/XMLSymbolSettings.java b/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/settings/XMLSymbolSettings.java index c3c47cdc6..83194cd78 100644 --- a/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/settings/XMLSymbolSettings.java +++ b/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/settings/XMLSymbolSettings.java @@ -22,8 +22,6 @@ public class XMLSymbolSettings { private String[] excluded; - private int maxItemsComputed; - public XMLExcludedSymbolFile[] getExcludedFiles() { return excludedFiles; } @@ -77,12 +75,4 @@ public boolean isExcluded(String uri) { return false; } - public int getMaxItemsComputed() { - return maxItemsComputed; - } - - public void setMaxItemsComputed(int maxItemsComputed) { - this.maxItemsComputed = maxItemsComputed; - } - } diff --git a/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/XMLAssert.java b/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/XMLAssert.java index 48fadcda6..3444d94c8 100644 --- a/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/XMLAssert.java +++ b/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/XMLAssert.java @@ -637,18 +637,11 @@ public static void assertDocumentLinks(List actual, DocumentLink.. // ------------------- DocumentSymbol assert - public static void testDocumentSymbolsFor(String xml, DocumentSymbol... expected) { - testDocumentSymbolsFor(xml, null, new XMLSymbolSettings(), expected); - } - public static void testDocumentSymbolsFor(String xml, XMLSymbolSettings symbolSettings, DocumentSymbol... expected) { - testDocumentSymbolsFor(xml, null, symbolSettings, expected); - } - - public static void testDocumentSymbolsFor(String xml, String fileURI, DocumentSymbol... expected) { - testDocumentSymbolsFor(xml, fileURI, new XMLSymbolSettings(), expected); + public static void testDocumentSymbolsFor(String xml, int symbolLimit, DocumentSymbol... expected) { + testDocumentSymbolsFor(xml, null, symbolLimit, expected); } - public static void testDocumentSymbolsFor(String xml, String fileURI, XMLSymbolSettings symbolSettings, DocumentSymbol... expected) { + public static void testDocumentSymbolsFor(String xml, String fileURI, int symbolLimit, DocumentSymbol... expected) { TextDocument document = new TextDocument(xml, fileURI != null ? fileURI : "test.xml"); XMLLanguageService xmlLanguageService = new XMLLanguageService(); @@ -661,7 +654,7 @@ public static void testDocumentSymbolsFor(String xml, String fileURI, XMLSymbolS xmlLanguageService.getResolverExtensionManager()); xmlLanguageService.setDocumentProvider((uri) -> xmlDocument); - List actual = xmlLanguageService.findDocumentSymbols(xmlDocument, symbolSettings); + List actual = xmlLanguageService.findDocumentSymbols(xmlDocument, symbolLimit); assertDocumentSymbols(actual, expected); } diff --git a/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/services/XMLDocumentSymbolsTest.java b/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/services/XMLDocumentSymbolsTest.java index e561024cf..5e03f199c 100644 --- a/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/services/XMLDocumentSymbolsTest.java +++ b/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/services/XMLDocumentSymbolsTest.java @@ -28,12 +28,14 @@ */ public class XMLDocumentSymbolsTest { + private static final int defaultSymbolLimit = 5000; + @Test public void externalDTD() { String dtd = "\n" + // ""; - XMLAssert.testDocumentSymbolsFor(dtd, "test.dtd", // + XMLAssert.testDocumentSymbolsFor(dtd, "test.dtd", defaultSymbolLimit, // ds("br", SymbolKind.Property, r(0, 0, 0, 19), r(0, 0, 0, 19), null, // Arrays.asList(ds("%all;", SymbolKind.Key, r(2, 1, 2, 6), r(2, 1, 2, 6), null, Arrays.asList())))); @@ -55,7 +57,7 @@ public void multipleAttlistValues() { " ep CDATA #IMPLIED\r\n" + " ep2 CDATA #IMPLIED>\r\n"; - XMLAssert.testDocumentSymbolsFor(dtd, "test.dtd", + XMLAssert.testDocumentSymbolsFor(dtd, "test.dtd", defaultSymbolLimit, // ds("target", SymbolKind.Property, r(0, 0, 0, 23), r(0, 0, 0, 23), null, Arrays.asList( ds("tid", SymbolKind.Key, r(3, 10, 3, 13), r(3, 10, 3, 13), null, Arrays.asList()), @@ -85,7 +87,7 @@ public void internalDTD() { "\r\n" + // " \r\n" + // ""; - XMLAssert.testDocumentSymbolsFor(xml, "test.xml", // + XMLAssert.testDocumentSymbolsFor(xml, "test.xml", defaultSymbolLimit, // ds("xml", SymbolKind.Property, r(0, 0, 0, 23), r(0, 0, 0, 23), null, // Collections.emptyList()), // ds("DOCTYPE:Folks", SymbolKind.Struct, r(1, 0, 9, 3), r(1, 0, 9, 3), null, @@ -132,14 +134,8 @@ public void exceedSymbolLimit() { ds("Email", SymbolKind.Property, r(8, 1, 8, 27), r(8, 1, 8, 27), null, Collections.emptyList()))); DocumentSymbol symbol3 = ds("Folks", SymbolKind.Field, r(10, 0, 12, 8), r(10, 0, 12, 8), null, Collections.emptyList()); - XMLSymbolSettings settings = new XMLSymbolSettings(); - settings.setMaxItemsComputed(10); - XMLAssert.testDocumentSymbolsFor(xml, "test.xml", settings, symbol1, symbol2, symbol3); - - settings.setMaxItemsComputed(15); - XMLAssert.testDocumentSymbolsFor(xml, "test.xml", settings, symbol1, symbol2, symbol3); - - settings.setMaxItemsComputed(9); - XMLAssert.testDocumentSymbolsFor(xml, "test.xml", settings, symbol1, symbol2); + XMLAssert.testDocumentSymbolsFor(xml, "test.xml", 10, symbol1, symbol2, symbol3); + XMLAssert.testDocumentSymbolsFor(xml, "test.xml", 15, symbol1, symbol2, symbol3); + XMLAssert.testDocumentSymbolsFor(xml, "test.xml", 9, symbol1, symbol2); } } diff --git a/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/services/XMLSymbolInformationsTest.java b/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/services/XMLSymbolInformationsTest.java index 658fd6546..0c08e233e 100644 --- a/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/services/XMLSymbolInformationsTest.java +++ b/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/services/XMLSymbolInformationsTest.java @@ -36,6 +36,7 @@ */ public class XMLSymbolInformationsTest { private static final String testURI = "test:URI"; + private static final int defaultSymbolLimit = 5000; private XMLLanguageService languageService; private DOMDocument xmlDocument; private List actualSymbolInfos; @@ -276,9 +277,8 @@ public void exceedSymbolLimit() { "]>\n" + // "
"; String testURI = "test.xml"; - XMLSymbolSettings settings = new XMLSymbolSettings(); - settings.setMaxItemsComputed(4); - initializeTestObjects(xmlText, testURI, settings); + + initializeTestObjects(xmlText, testURI, 4); List expectedSymbolInfos = new ArrayList(); currentLocation = createLocation(testURI, 0, 63, xmlDocument); @@ -299,27 +299,25 @@ public void exceedSymbolLimit() { assertSymbols(expectedSymbolInfos, actualSymbolInfos); - settings.setMaxItemsComputed(10); - initializeTestObjects(xmlText, testURI, settings); + initializeTestObjects(xmlText, testURI, 10); assertSymbols(expectedSymbolInfos, actualSymbolInfos); - settings.setMaxItemsComputed(3); - initializeTestObjects(xmlText, testURI, settings); + initializeTestObjects(xmlText, testURI, 3); assertSymbols(expectedSymbolInfos.stream().limit(3).collect(Collectors.toList()), actualSymbolInfos); } // -------------------Tools------------------------------ private void initializeTestObjects(String xmlText) { - initializeTestObjects(xmlText, testURI, new XMLSymbolSettings()); + initializeTestObjects(xmlText, testURI, defaultSymbolLimit); } private void initializeTestObjects(String xmlText, String uri) { - initializeTestObjects(xmlText, uri, new XMLSymbolSettings()); + initializeTestObjects(xmlText, uri, defaultSymbolLimit); } - private void initializeTestObjects(String xmlText, String uri, XMLSymbolSettings settings) { + private void initializeTestObjects(String xmlText, String uri, int limit) { xmlDocument = DOMParser.getInstance().parse(xmlText, uri, null); - actualSymbolInfos = languageService.findSymbolInformations(xmlDocument, settings); + actualSymbolInfos = languageService.findSymbolInformations(xmlDocument, limit); } private void assertSymbols(List expectedSymbolList, List actualSymbolList) {