Skip to content

Commit

Permalink
fix: formatting around commas of type argument, parameter, result, an…
Browse files Browse the repository at this point in the history
…d type parameter lists
  • Loading branch information
lars-reimann committed Jul 4, 2023
1 parent 361d2a1 commit b3e5bc1
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions DSL/src/language-server/formatting/safe-ds-formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -498,13 +498,14 @@ export class SafeDSFormatter extends AbstractFormatter {
parameters.length >= 3 ||
parameters.some((it) => annotationCallsOrEmpty(it).length > 0 || this.isComplexType(it.type))
) {
formatter.nodes(...parameters).prepend(indent());
formatter.keywords(',').prepend(noSpace());
closingParenthesis.prepend(newLine());
formatter.interior(openingParenthesis, closingParenthesis).prepend(indent());
formatter.keywords(',').prepend(noSpace()).append(newLine());
} else {
openingParenthesis.append(noSpace());
formatter.nodes(...parameters.slice(1)).prepend(oneSpace());
formatter.keywords(',').prepend(noSpace());
closingParenthesis.prepend(noSpace());
formatter.keywords(',').prepend(noSpace()).append(oneSpace());
}
}

Expand Down Expand Up @@ -538,11 +539,12 @@ export class SafeDSFormatter extends AbstractFormatter {
results.some((it) => annotationCallsOrEmpty(it).length > 0 || this.isComplexType(it.type))
) {
formatter.nodes(...results).prepend(indent());
formatter.keywords(',').prepend(noSpace()).append(newLine());
formatter.keywords(',').prepend(noSpace());
closingParenthesis.prepend(newLine());
} else {
openingParenthesis.append(noSpace());
formatter.keywords(',').prepend(noSpace()).append(oneSpace());
formatter.nodes(...results.slice(1)).prepend(oneSpace());
formatter.keywords(',').prepend(noSpace());
closingParenthesis.prepend(noSpace());
}
}
Expand Down Expand Up @@ -761,15 +763,16 @@ export class SafeDSFormatter extends AbstractFormatter {
const typeParameters = node.typeParameters ?? [];

if (typeParameters.length >= 3 || typeParameters.some((it) => annotationCallsOrEmpty(it).length > 0)) {
closingBracket.prepend(newLine());
formatter.nodes(...typeParameters).prepend(indent());
formatter.keywords(',').prepend(noSpace()).append(newLine());
formatter.keywords(',').prepend(noSpace());
closingBracket.prepend(newLine());
} else {
closingBracket.prepend(noSpace());
if (typeParameters.length > 0) {
formatter.node(typeParameters[0]).prepend(noSpace());
formatter.nodes(...typeParameters.slice(1)).prepend(oneSpace());
}
formatter.keywords(',').prepend(noSpace()).append(oneSpace());
formatter.keywords(',').prepend(noSpace());
closingBracket.prepend(noSpace());
}
}

Expand All @@ -793,9 +796,10 @@ export class SafeDSFormatter extends AbstractFormatter {

if (typeArguments.length > 0) {
formatter.node(typeArguments[0]).prepend(noSpace());
formatter.nodes(...typeArguments.slice(1)).prepend(oneSpace());
}

formatter.keywords(',').prepend(noSpace()).append(oneSpace());
formatter.keywords(',').prepend(noSpace());
formatter.keyword('>').prepend(noSpace());
}

Expand Down

0 comments on commit b3e5bc1

Please sign in to comment.