Skip to content

Commit

Permalink
fix: don't generate a symbol name when property starts with '.'
Browse files Browse the repository at this point in the history
Fixes https://github.com/redhat-developer/vscode-quarkus/issues/640

Signed-off-by: azerr <azerr@redhat.com>
  • Loading branch information
angelozerr authored and fbricon committed Feb 1, 2024
1 parent 43faf73 commit 84282d8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,10 @@ public List<DocumentSymbol> findDocumentSymbols(PropertiesModel document, Cancel
String name = getSymbolName(property);
if (!StringUtils.isEmpty(name)) {
// The property is not an empty line
String[] paths = name.split("[.]");
// If the property starts with '.', we don't split it to avoid having an empty
// name.
boolean startsWithDot = name.charAt(0) == '.';
String[] paths = startsWithDot ? name.split("[.]", 1) : name.split("[.]");
DocumentSymbol symbol = null;
for (String path : paths) {
symbol = getSymbol(path, property, symbol != null ? symbol.getChildren() : symbols);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,24 @@ public void multiLineKeyValueSymbols() throws BadLocationException {
@Test
public void justPeriod() throws BadLocationException {
String value = ".";
testDocumentSymbolsFor(value);
testDocumentSymbolsFor(value, ds(".", SymbolKind.Property, r(0, 0, 1), null));
}

@Test
public void propertiesWhichStartWithPeriod() throws BadLocationException {
String value = ".quarkus\n" + //
" .quarkus2\n" + //
"quarkus.\n" + //
".mp\n" + //
" .mp2\n";
testDocumentSymbolsFor(value, //
ds(".quarkus", SymbolKind.Property, r(0, 0, 8), null), //
ds(".quarkus2", SymbolKind.Property, r(1, 2, 11), null), //
ds("quarkus", SymbolKind.Property, r(2, 0, 8), null), //
ds(".mp", SymbolKind.Property, r(3, 0, 3), null), //
ds(".mp2", SymbolKind.Property, r(4, 2, 6), null));
}

@Test
public void justEquals() throws BadLocationException {
String value = "=";
Expand Down

0 comments on commit 84282d8

Please sign in to comment.