Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita620165

Browse files
authored
Merge pull request#55 from Inky-developer/fix-52
Show correct line numbers when fold ist set to true,fixes#52
2 parents448b804 +0814113 commita620165

File tree

3 files changed

+29
-6
lines changed

3 files changed

+29
-6
lines changed

‎src/display_list/from_snippet.rs‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,9 @@ fn format_slice(
111111
) ->Vec<DisplayLine<'_>>{
112112
let main_range = slice.annotations.get(0).map(|x| x.range.0);
113113
let origin = slice.origin;
114-
let line_start = slice.line_start;
115114
let need_empty_header = origin.is_some() || is_first;
116115
letmut body =format_body(slice, need_empty_header, has_footer, margin);
117-
let header =format_header(origin, main_range,line_start,&body, is_first);
116+
let header =format_header(origin, main_range,&body, is_first);
118117
letmut result =vec![];
119118

120119
ifletSome(header) = header{
@@ -133,7 +132,6 @@ fn zip_opt<A, B>(a: Option<A>, b: Option<B>) -> Option<(A, B)> {
133132
fnformat_header<'a>(
134133
origin:Option<&'astr>,
135134
main_range:Option<usize>,
136-
mutrow:usize,
137135
body:&[DisplayLine<'_>],
138136
is_first:bool,
139137
) ->Option<DisplayLine<'a>>{
@@ -145,24 +143,26 @@ fn format_header<'a>(
145143

146144
ifletSome((main_range, path)) =zip_opt(main_range, origin){
147145
letmut col =1;
146+
letmut line_offset =1;
148147

149148
for itemin body{
150149
ifletDisplayLine::Source{
151150
line:DisplaySourceLine::Content{ range, ..},
151+
lineno,
152152
..
153153
} = item
154154
{
155155
if main_range >= range.0 && main_range <= range.1{
156156
col = main_range - range.0 +1;
157+
line_offset = lineno.unwrap_or(1);
157158
break;
158159
}
159-
row +=1;
160160
}
161161
}
162162

163163
returnSome(DisplayLine::Raw(DisplayRawLine::Origin{
164164
path,
165-
pos:Some((row, col)),
165+
pos:Some((line_offset, col)),
166166
header_type: display_header,
167167
}));
168168
}
@@ -307,7 +307,7 @@ fn format_body(
307307
let char_widths = line
308308
.chars()
309309
.map(|c| unicode_width::UnicodeWidthChar::width(c).unwrap_or(0))
310-
.chain(std::iter::once(1))// treat the end of line assignle-width
310+
.chain(std::iter::once(1))// treat the end of line assingle-width
311311
.collect::<Vec<_>>();
312312
body.push(DisplayLine::Source{
313313
lineno:Some(current_line),
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[title]
2+
annotation_type ="Error"
3+
4+
[[slices]]
5+
source ="""
6+
7+
8+
invalid syntax
9+
"""
10+
line_start =1
11+
origin ="path/to/error.rs"
12+
fold =true
13+
[[slices.annotations]]
14+
label ="error here"
15+
annotation_type ="Warning"
16+
range = [2,16]
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
error
2+
--> path/to/error.rs:3:1
3+
|
4+
...
5+
3 | invalid syntax
6+
| -------------- error here
7+
|

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp