@@ -22,7 +22,7 @@ pub fn get_comment_token(
22
22
let start_char = text. line_to_char ( line_num) + start;
23
23
24
24
let injected_tokens = get_injected_tokens ( syntax, start_char, start_char)
25
- // we don't care about block comment tokens
25
+ // we only care about line comment tokens
26
26
. 0
27
27
. and_then ( |tokens| {
28
28
tokens
@@ -32,7 +32,7 @@ pub fn get_comment_token(
32
32
} ) ;
33
33
34
34
injected_tokens. or (
35
- // no comment tokens found for injection. Use doc tokens instead
35
+ // no comment tokens found for injection, use doc comments if exists
36
36
doc_default_tokens. and_then ( |tokens| {
37
37
tokens
38
38
. iter ( )
@@ -51,14 +51,13 @@ pub fn get_injected_tokens(
51
51
// Find the injection with the most tightly encompassing range.
52
52
syntax
53
53
. and_then ( |syntax| {
54
- injection_for_range ( syntax, start, end)
55
- . map ( |language_id| syntax. layer_config ( language_id) )
56
- . map ( |config| {
57
- (
58
- config. comment_tokens . clone ( ) ,
59
- config. block_comment_tokens . clone ( ) ,
60
- )
61
- } )
54
+ injection_for_range ( syntax, start, end) . map ( |language_id| {
55
+ let config = syntax. layer_config ( language_id) ;
56
+ (
57
+ config. comment_tokens . clone ( ) ,
58
+ config. block_comment_tokens . clone ( ) ,
59
+ )
60
+ } )
62
61
} )
63
62
. unwrap_or_default ( )
64
63
}
@@ -73,20 +72,18 @@ pub fn injection_for_range(syntax: &Syntax, from: usize, to: usize) -> Option<La
73
72
for ts_range in & layer. ranges {
74
73
let is_encompassing = ts_range. start_byte <= from && ts_range. end_byte >= to;
75
74
if is_encompassing {
76
- let this_gap = ts_range. end_byte - ts_range. start_byte ;
75
+ let gap = ts_range. end_byte - ts_range. start_byte ;
77
76
let config = syntax. layer_config ( layer_id) ;
77
+ // ignore the language family for which it won't make
78
+ // sense to consider their comment.
79
+ //
80
+ // This includes, for instance, `comment`, `jsdoc`, `regex`
78
81
let has_comment_tokens =
79
82
config. comment_tokens . is_some ( ) || config. block_comment_tokens . is_some ( ) ;
80
83
81
- if this_gap < min_gap
82
- // ignore the language family for which it won't make
83
- // sense to consider their comment.
84
- //
85
- // This includes, for instance, `comment`, `jsdoc`, `regex`
86
- && has_comment_tokens
87
- {
84
+ if gap < min_gap && has_comment_tokens {
88
85
best_fit = Some ( layer_id) ;
89
- min_gap = this_gap ;
86
+ min_gap = gap ;
90
87
}
91
88
}
92
89
}
@@ -145,16 +142,6 @@ fn find_line_comment(
145
142
( commented, to_change, min, margin)
146
143
}
147
144
148
- // for a given range and syntax, determine if there are additional tokens to consider
149
- pub type GetInjectedTokens < ' a > = Box <
150
- dyn FnMut (
151
- Option < & Syntax > ,
152
- usize ,
153
- usize ,
154
- ) -> ( Option < Vec < String > > , Option < Vec < BlockCommentToken > > )
155
- + ' a ,
156
- > ;
157
-
158
145
#[ must_use]
159
146
pub fn toggle_line_comments ( doc : & Rope , range : & Range , token : Option < & str > ) -> Vec < Change > {
160
147
let text = doc. slice ( ..) ;
0 commit comments