Skip to content

Commit

Permalink
Change xml.symbols.maxItemsComputed to xml.maxItemsComputed
Browse files Browse the repository at this point in the history
Signed-off-by: David Kwon <dakwon@redhat.com>
  • Loading branch information
dkwon17 committed Apr 17, 2020
1 parent d22cd07 commit d0e7b9c
Show file tree
Hide file tree
Showing 10 changed files with 65 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,9 +224,10 @@ public CompletableFuture<List<Either<SymbolInformation, DocumentSymbol>>> docume
return computeDOMAsync(params.getTextDocument(), (cancelChecker, xmlDocument) -> {
boolean resultLimitExceeded = false;
List<Either<SymbolInformation, DocumentSymbol>> 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 //
Expand All @@ -238,7 +239,7 @@ public CompletableFuture<List<Either<SymbolInformation, DocumentSymbol>>> docume
.collect(Collectors.toList());
}
SymbolInformationsResult result = getXMLLanguageService()
.findSymbolInformations(xmlDocument, symbolSettings, cancelChecker);
.findSymbolInformations(xmlDocument, symbolsLimit, cancelChecker);
resultLimitExceeded = result.isResultLimitExceeded();
symbols = result.stream() //
.map(s -> {
Expand All @@ -250,9 +251,9 @@ public CompletableFuture<List<Either<SymbolInformation, DocumentSymbol>>> 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 {
Expand Down Expand Up @@ -484,14 +485,17 @@ public void updateSymbolSettings(XMLSymbolSettings newSettings) {
if (newPatterns != null) {
symbolSettings.setExcluded(newPatterns);
}
symbolSettings.setMaxItemsComputed(newSettings.getMaxItemsComputed());
}

public void updateCodeLensSettings(XMLCodeLensSettings newSettings) {
XMLCodeLensSettings codeLensSettings = sharedSettings.getCodeLensSettings();
codeLensSettings.setEnabled(newSettings.isEnabled());
}

public void updateMaxItemsComputed(int maxItemsComputed) {
sharedSettings.setMaxItemsComputed(maxItemsComputed);
}

public XMLSymbolSettings getSharedSymbolSettings() {
return sharedSettings.getSymbolSettings();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,20 +114,20 @@ public List<DocumentHighlight> findDocumentHighlights(DOMDocument xmlDocument, P
return highlighting.findDocumentHighlights(xmlDocument, position, cancelChecker);
}

public List<SymbolInformation> findSymbolInformations(DOMDocument xmlDocument, XMLSymbolSettings symbolSettings) {
return findSymbolInformations(xmlDocument, symbolSettings, NULL_CHECKER);
public List<SymbolInformation> 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<DocumentSymbol> findDocumentSymbols(DOMDocument xmlDocument, XMLSymbolSettings symbolSettings) {
return findDocumentSymbols(xmlDocument, symbolSettings, NULL_CHECKER);
public List<DocumentSymbol> 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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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<DOMNode> nodesToIgnore = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public class SharedSettings {
private final XMLCodeLensSettings codeLensSettings;
private final XMLHoverSettings hoverSettings;

private int maxItemsComputed;
private boolean actionableNotificationSupport;
private boolean openSettingsCommandSupport;

Expand Down Expand Up @@ -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;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ public class XMLGeneralClientSettings {

private XMLCodeLensSettings codeLens;

private int maxItemsComputed;

public void setLogs(LogsSettings logs) {
this.logs = logs;
}
Expand Down Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ public class XMLSymbolSettings {

private String[] excluded;

private int maxItemsComputed;

public XMLExcludedSymbolFile[] getExcludedFiles() {
return excludedFiles;
}
Expand Down Expand Up @@ -77,12 +75,4 @@ public boolean isExcluded(String uri) {
return false;
}

public int getMaxItemsComputed() {
return maxItemsComputed;
}

public void setMaxItemsComputed(int maxItemsComputed) {
this.maxItemsComputed = maxItemsComputed;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -637,18 +637,11 @@ public static void assertDocumentLinks(List<DocumentLink> 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();
Expand All @@ -661,7 +654,7 @@ public static void testDocumentSymbolsFor(String xml, String fileURI, XMLSymbolS
xmlLanguageService.getResolverExtensionManager());
xmlLanguageService.setDocumentProvider((uri) -> xmlDocument);

List<DocumentSymbol> actual = xmlLanguageService.findDocumentSymbols(xmlDocument, symbolSettings);
List<DocumentSymbol> actual = xmlLanguageService.findDocumentSymbols(xmlDocument, symbolLimit);
assertDocumentSymbols(actual, expected);

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,14 @@
*/
public class XMLDocumentSymbolsTest {

private static final int defaultSymbolLimit = 5000;

@Test
public void externalDTD() {
String dtd = "<!ELEMENT br EMPTY>\n" + //
"<!ATTLIST br\n" + //
" %all;>";
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()))));

Expand All @@ -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()),
Expand Down Expand Up @@ -85,7 +87,7 @@ public void internalDTD() {
"<Folks>\r\n" + //
" \r\n" + //
"</Folks>";
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,
Expand Down Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<SymbolInformation> actualSymbolInfos;
Expand Down Expand Up @@ -276,9 +277,8 @@ public void exceedSymbolLimit() {
"]>\n" + //
"<br />";
String testURI = "test.xml";
XMLSymbolSettings settings = new XMLSymbolSettings();
settings.setMaxItemsComputed(4);
initializeTestObjects(xmlText, testURI, settings);

initializeTestObjects(xmlText, testURI, 4);

List<SymbolInformation> expectedSymbolInfos = new ArrayList<SymbolInformation>();
currentLocation = createLocation(testURI, 0, 63, xmlDocument);
Expand All @@ -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<SymbolInformation> expectedSymbolList, List<SymbolInformation> actualSymbolList) {
Expand Down

0 comments on commit d0e7b9c

Please sign in to comment.