Skip to content

Commit b397c2c

Browse files
committed
Fix the decorators display issue
Signed-off-by: sheche <[email protected]>
1 parent 1cda07b commit b397c2c

2 files changed

Lines changed: 27 additions & 10 deletions

File tree

org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/handlers/CompletionRanking.java

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,16 @@
1818
* The ranking result of each completion proposal.
1919
*/
2020
public class CompletionRanking {
21+
22+
/**
23+
* The allowed max score.
24+
*/
25+
public static final int MAX_SCORE = 100;
26+
27+
/**
28+
* The allowed min score.
29+
*/
30+
public static final int MIN_SCORE = 0;
2131
/**
2232
* The score of the completion proposal. Score will be added to the proposal's relevance field.
2333
*/
@@ -39,8 +49,9 @@ public class CompletionRanking {
3949
/**
4050
* The score of the completion proposal. Score will be added to the proposal's relevance field.
4151
* <p>
42-
* The acceptable values are [0, 100]. When adding to the relevance, values larger than 100 will
43-
* be treated as 100 and value lower than 0 will be treated as 0.
52+
* The acceptable values are [{@link #MIN_SCORE}, {@link #MAX_SCORE}]. When adding to the relevance, values larger than
53+
* {@link #MAX_SCORE} will be treated as {@link #MAX_SCORE}.Values lower than {@link #MIN_SCORE} will be treated as
54+
* {@link #MIN_SCORE}.
4455
*/
4556
public int getScore() {
4657
return score;
@@ -49,8 +60,9 @@ public int getScore() {
4960
/**
5061
* The score of the completion proposal. Score will be added to the proposal's relevance field.
5162
* <p>
52-
* The acceptable values are [0, 100]. When adding to the relevance, values larger than 100 will
53-
* be treated as 100 and value lower than 0 will be treated as 0.
63+
* The acceptable values are [{@link #MIN_SCORE}, {@link #MAX_SCORE}]. When adding to the relevance, values larger than
64+
* {@link #MAX_SCORE} will be treated as {@link #MAX_SCORE}.Values lower than {@link #MIN_SCORE} will be treated as
65+
* {@link #MIN_SCORE}.
5466
*/
5567
public void setScore(int score) {
5668
this.score = score;

org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/handlers/CompletionRankingAggregation.java

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,14 @@
1212
*******************************************************************************/
1313
package org.eclipse.jdt.ls.core.internal.handlers;
1414

15+
import static org.eclipse.jdt.ls.core.internal.handlers.CompletionRanking.MAX_SCORE;
16+
import static org.eclipse.jdt.ls.core.internal.handlers.CompletionRanking.MIN_SCORE;
17+
1518
import java.util.HashMap;
1619
import java.util.HashSet;
1720
import java.util.Map;
1821
import java.util.Set;
22+
import java.util.stream.Collectors;
1923

2024
/**
2125
* Aggregated result of all the ranking results from ranking providers.
@@ -41,25 +45,26 @@ public int getScore() {
4145
}
4246

4347
/**
44-
* Add score from a ranking provider. The acceptable values are [0, 100].
45-
* When adding to the relevance, values larger than 100 will be treated as
46-
* 100 and value lower than 0 will be treated as 0.
48+
* Add score from a ranking provider. The acceptable values are [{@link CompletionRanking#MIN_SCORE},
49+
* {@link CompletionRanking#MAX_SCORE}]. When adding to the relevance, values larger than {@link CompletionRanking#MAX_SCORE}
50+
* will be treated as {@link CompletionRanking#MAX_SCORE} and value lower than {@link CompletionRanking#MIN_SCORE}
51+
* will be treated as {@link CompletionRanking#MIN_SCORE}.
4752
* @param score score from a ranking provider.
4853
*/
4954
public void addScore(int score) {
50-
if (score <= 0) {
55+
if (score <= MIN_SCORE) {
5156
return;
5257
}
5358

54-
this.score += score > 100 ? 100 : score;
59+
this.score += score > MAX_SCORE ? MAX_SCORE : score;
5560
}
5661

5762
/**
5863
* Get the aggregated decorators from all ranking providers.
5964
* The decorator chars will be de-duplicated and sorted.
6065
*/
6166
public String getDecorators() {
62-
return String.valueOf(this.decorators.stream().sorted().toArray(Character[]::new));
67+
return this.decorators.stream().sorted().map(String::valueOf).collect(Collectors.joining());
6368
}
6469

6570
/**

0 commit comments

Comments
 (0)