Skip to content

Commit c948357

Browse files
authored
Merge pull request #1799 from 1c-syntax/fix/contentList
2 parents 79fb62c + 397a417 commit c948357

File tree

4 files changed

+18
-1
lines changed

4 files changed

+18
-1
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44
*.md eol=lf
55
*.json eol=lf
66
*.bat eol=crlf
7+
src/test/resources/context/DocumentContextBrokenLineFeeds.bsl binary

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
import java.util.Map;
6666
import java.util.Optional;
6767
import java.util.concurrent.locks.ReentrantLock;
68+
import java.util.regex.Pattern;
6869
import java.util.stream.Collectors;
6970

7071
import static java.util.Objects.requireNonNull;
@@ -75,6 +76,8 @@
7576
@RequiredArgsConstructor
7677
public class DocumentContext {
7778

79+
private static final Pattern CONTENT_SPLIT_PATTERN = Pattern.compile("\r?\n|\r");
80+
7881
private final URI uri;
7982

8083
@Nullable
@@ -315,7 +318,7 @@ private static FileType computeFileType(URI uri) {
315318
}
316319

317320
private String[] computeContentList() {
318-
return getContent().split("\n", -1);
321+
return CONTENT_SPLIT_PATTERN.split(getContent(), -1);
319322
}
320323

321324
private SymbolTree computeSymbolTree() {

src/test/java/com/github/_1c_syntax/bsl/languageserver/context/DocumentContextTest.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,18 @@ void testContentList() {
216216
assertThat(contentList).hasSize(40);
217217
}
218218

219+
@Test
220+
void testContentListWithStandaloneCR() {
221+
// given
222+
var documentContext = getDocumentContext("./src/test/resources/context/DocumentContextBrokenLineFeeds.bsl");
223+
224+
// when
225+
var contentList = documentContext.getContentList();
226+
227+
// then
228+
assertThat(contentList).hasSize(3);
229+
}
230+
219231
@Test
220232
void testEOF() {
221233
// given

src/test/resources/context/DocumentContextBrokenLineFeeds.bsl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ПереводCRЕщеОдинCR

0 commit comments

Comments
 (0)