Skip to content

Commit

Permalink
minor updates
Browse files Browse the repository at this point in the history
Signed-off-by: xiarui.xr <[email protected]>
  • Loading branch information
amyXia1994 committed Oct 17, 2023
1 parent ea4c169 commit 74f1efa
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 10 deletions.
1 change: 0 additions & 1 deletion kclvm/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions kclvm/sema/src/info/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
use regex::Regex;

#[inline]
pub fn is_private_field(name: &str) -> bool {
name.starts_with('_')
}

#[inline]
pub fn is_valid_kcl_name(name: &str) -> bool {
let re = Regex::new(r#"^[a-zA-Z_][a-zA-Z0-9_]*$"#).unwrap();
re.is_match(name)
}
1 change: 0 additions & 1 deletion kclvm/tools/src/LSP/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ log = "0.4.14"
im-rc = "15.0.0"
rustc_lexer = "0.1.0"
clap = "4.3.0"
regex = "1.4"

kclvm-tools = { path = "../../../tools" }
kclvm-error = { path = "../../../error" }
Expand Down
4 changes: 2 additions & 2 deletions kclvm/tools/src/LSP/src/request.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use anyhow::{anyhow, Ok};
use crossbeam_channel::Sender;
use kclvm_sema::info::is_valid_kcl_name;
use lsp_types::{Location, TextEdit};
use ra_ap_vfs::VfsPath;
use std::collections::HashMap;
Expand All @@ -16,7 +17,6 @@ use crate::{
goto_def::goto_definition,
hover, quick_fix,
state::{log_message, LanguageServerSnapshot, LanguageServerState, Task},
util,
};

impl LanguageServerState {
Expand Down Expand Up @@ -226,7 +226,7 @@ pub(crate) fn handle_rename(
) -> anyhow::Result<Option<lsp_types::WorkspaceEdit>> {
// 1. check the new name validity
let new_name = params.new_name;
if !util::is_valid_kcl_name(new_name.clone()) {
if !is_valid_kcl_name(new_name.as_str()) {
return Err(anyhow!("Can not rename to: {new_name}, invalid name"));
}

Expand Down
6 changes: 0 additions & 6 deletions kclvm/tools/src/LSP/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ use kclvm_utils::pkgpath::rm_external_pkg_name;
use lsp_types::{Location, Position, Range, Url};
use parking_lot::{RwLock, RwLockReadGuard};
use ra_ap_vfs::{FileId, Vfs};
use regex::Regex;
use serde::{de::DeserializeOwned, Serialize};
use std::cell::RefCell;
use std::collections::HashMap;
Expand Down Expand Up @@ -895,11 +894,6 @@ fn line_to_words(text: String) -> HashMap<String, Vec<Word>> {
result
}

pub fn is_valid_kcl_name(name: String) -> bool {
let re = Regex::new(r#"^[a-zA-Z_][a-zA-Z0-9_]*$"#).unwrap();
re.is_match(&name)
}

#[cfg(test)]
mod tests {
use super::{build_word_index, line_to_words, word_index_add, word_index_subtract, Word};
Expand Down

0 comments on commit 74f1efa

Please sign in to comment.