continue-comment: add some comments and remove unused code

This commit is contained in:
TornaxO7 2024-08-10 10:13:04 +02:00
parent b842fdb48a
commit b5003e957f
No known key found for this signature in database
GPG Key ID: 2BCDBDF404CEDF55
2 changed files with 10 additions and 16 deletions

View File

@ -18,10 +18,10 @@ pub fn get_comment_token<'a>(
line_num: usize,
) -> Option<&'a str> {
let text = text.slice(..);
let mut apply_token = false;
let mut token_found = false;
if let Some(tokens) = tokens {
let mut used_token = tokens
let mut final_token = tokens
.first()
.map(|token| token.as_str())
.unwrap_or(DEFAULT_COMMENT_TOKEN);
@ -30,16 +30,18 @@ pub fn get_comment_token<'a>(
let (is_commented, _, _, _) = find_line_comment(token, text, [line_num]);
if is_commented {
apply_token = true;
token_found = true;
if token.len() > used_token.len() {
used_token = token;
// in rust for example, there's `//` and `///`.
// We need to find the longest matching comment token so we can't immediately return the first matching token.
if token.len() > final_token.len() {
final_token = token;
}
}
}
if apply_token {
return Some(used_token);
if token_found {
return Some(final_token);
}
} else {
let (is_commented, _, _, _) = find_line_comment(DEFAULT_COMMENT_TOKEN, text, [line_num]);

View File

@ -3,7 +3,6 @@
use crate::{
auto_pairs::AutoPairs,
chars::char_is_line_ending,
comment::DEFAULT_COMMENT_TOKEN,
diagnostic::Severity,
regex::Regex,
transaction::{ChangeSet, Operation},
@ -104,11 +103,8 @@ pub struct LanguageConfiguration {
pub shebangs: Vec<String>, // interpreter(s) associated with language
#[serde(default)]
pub roots: Vec<String>, // these indicate project roots <.git, Cargo.toml>
// Invariants:
// - `comment_tokens.is_some()` is always true
// - the inner Vec is never empty
#[serde(
default = "default_comment_tokens",
default,
skip_serializing,
deserialize_with = "from_comment_tokens",
alias = "comment-token"
@ -278,10 +274,6 @@ enum CommentTokens {
)
}
fn default_comment_tokens() -> Option<Vec<String>> {
Some(vec![DEFAULT_COMMENT_TOKEN.to_string()])
}
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct BlockCommentToken {
pub start: String,