Skip to content

Commit ebc617b

Browse files
authored
Merge pull request #3389 from 1c-syntax/fix/document-context-comparable
2 parents df086dc + a991795 commit ebc617b

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

src/main/java/com/github/_1c_syntax/bsl/languageserver/context/DocumentContext.java

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,10 @@
4343
import com.github._1c_syntax.bsl.types.ConfigurationSource;
4444
import com.github._1c_syntax.bsl.types.ModuleType;
4545
import com.github._1c_syntax.utils.Lazy;
46+
import edu.umd.cs.findbugs.annotations.NonNull;
4647
import edu.umd.cs.findbugs.annotations.Nullable;
4748
import jakarta.annotation.PostConstruct;
49+
import lombok.EqualsAndHashCode;
4850
import lombok.Getter;
4951
import lombok.RequiredArgsConstructor;
5052
import lombok.Setter;
@@ -65,12 +67,12 @@
6567
import java.net.URI;
6668
import java.nio.charset.StandardCharsets;
6769
import java.util.Collections;
70+
import java.util.Comparator;
6871
import java.util.List;
6972
import java.util.Locale;
7073
import java.util.Optional;
7174
import java.util.concurrent.locks.ReentrantLock;
7275
import java.util.regex.Pattern;
73-
import java.util.stream.Collectors;
7476

7577
import static java.util.Objects.requireNonNull;
7678
import static org.antlr.v4.runtime.Token.DEFAULT_CHANNEL;
@@ -79,16 +81,20 @@
7981
@Scope("prototype")
8082
@RequiredArgsConstructor
8183
@Slf4j
82-
public class DocumentContext {
84+
@EqualsAndHashCode(onlyExplicitlyIncluded = true)
85+
public class DocumentContext implements Comparable<DocumentContext> {
8386

8487
private static final Pattern CONTENT_SPLIT_PATTERN = Pattern.compile("\r?\n|\r");
8588

8689
@Getter
90+
@EqualsAndHashCode.Include
8791
private final URI uri;
8892

8993
@Nullable
9094
private String content;
95+
9196
@Getter
97+
@EqualsAndHashCode.Include
9298
private int version;
9399

94100
@Setter(onMethod = @__({@Autowired}))
@@ -158,13 +164,13 @@ public List<Token> getTokens() {
158164
}
159165

160166
public List<Token> getTokensFromDefaultChannel() {
161-
return getTokens().stream().filter(token -> token.getChannel() == DEFAULT_CHANNEL).collect(Collectors.toList());
167+
return getTokens().stream().filter(token -> token.getChannel() == DEFAULT_CHANNEL).toList();
162168
}
163169

164170
public List<Token> getComments() {
165171
return getTokens().stream()
166172
.filter(token -> token.getType() == BSLLexer.LINE_COMMENT)
167-
.collect(Collectors.toList());
173+
.toList();
168174
}
169175

170176
public String getText(Range range) {
@@ -429,4 +435,10 @@ private List<SDBLTokenizer> computeQueries() {
429435
return (new QueryComputer(this)).compute();
430436
}
431437

438+
@Override
439+
public int compareTo(@NonNull DocumentContext other) {
440+
return Comparator.comparing(DocumentContext::getUri)
441+
.thenComparing(DocumentContext::getVersion)
442+
.compare(this, other);
443+
}
432444
}

0 commit comments

Comments
 (0)