Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Experiment] Use sorbus-backed rowan #2

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 74 additions & 12 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ opt-level = 0
opt-level = 0

[patch.'crates-io']
# rowan = { path = "../rowan" }
rowan = { path = "../rowan" }

[patch.'https://github.com/rust-lang/chalk.git']
# chalk-solve = { path = "../chalk/chalk-solve" }
Expand Down
17 changes: 7 additions & 10 deletions crates/ra_assists/src/handlers/add_custom_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,24 +29,21 @@ pub(crate) fn add_custom_impl(ctx: AssistCtx) -> Option<Assist> {
let input = ctx.find_node_at_offset::<ast::AttrInput>()?;
let attr = input.syntax().parent().and_then(ast::Attr::cast)?;

let attr_name = attr
let attr_node = attr
.syntax()
.descendants_with_tokens()
.filter(|t| t.kind() == IDENT)
.find_map(|i| i.into_token())
.filter(|t| *t.text() == "derive")?
.text()
.clone();
.filter(|t| t.text() == "derive")?;
let attr_name = attr_node.text();

let trait_token =
ctx.token_at_offset().find(|t| t.kind() == IDENT && *t.text() != attr_name)?;
let trait_token = ctx.token_at_offset().find(|t| t.kind() == IDENT && t.text() != attr_name)?;

let annotated = attr.syntax().siblings(Direction::Next).find_map(ast::Name::cast)?;
let annotated_name = annotated.syntax().text().to_string();
let start_offset = annotated.syntax().parent()?.text_range().end();

let label =
format!("Add custom impl '{}' for '{}'", trait_token.text().as_str(), annotated_name);
let label = format!("Add custom impl '{}' for '{}'", trait_token.text(), annotated_name);

ctx.add_assist(AssistId("add_custom_impl"), label, |edit| {
edit.target(attr.syntax().text_range());
Expand All @@ -55,15 +52,15 @@ pub(crate) fn add_custom_impl(ctx: AssistCtx) -> Option<Assist> {
.syntax()
.descendants_with_tokens()
.filter(|t| t.kind() == IDENT)
.filter_map(|t| t.into_token().map(|t| t.text().clone()))
.filter_map(|t| t.into_token().map(|t| SmolStr::from(t.text())))
.filter(|t| t != trait_token.text())
.collect::<Vec<SmolStr>>();
let has_more_derives = !new_attr_input.is_empty();
let new_attr_input = new_attr_input.iter().sep_by(", ").surround_with("(", ")").to_string();

let mut buf = String::new();
buf.push_str("\n\nimpl ");
buf.push_str(trait_token.text().as_str());
buf.push_str(trait_token.text());
buf.push_str(" for ");
buf.push_str(annotated_name.as_str());
buf.push_str(" {\n");
Expand Down
14 changes: 8 additions & 6 deletions crates/ra_assists/src/handlers/add_impl.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use ra_syntax::{
ast::{self, AstNode, NameOwner, TypeParamsOwner},
TextSize,
SmolStr, TextSize,
};
use stdx::{format_to, SepBy};

Expand Down Expand Up @@ -28,7 +28,7 @@ use crate::{Assist, AssistCtx, AssistId};
pub(crate) fn add_impl(ctx: AssistCtx) -> Option<Assist> {
let nominal = ctx.find_node_at_offset::<ast::NominalDef>()?;
let name = nominal.name()?;
ctx.add_assist(AssistId("add_impl"), format!("Implement {}", name.text().as_str()), |edit| {
ctx.add_assist(AssistId("add_impl"), format!("Implement {}", name.text()), |edit| {
edit.target(nominal.syntax().text_range());
let type_params = nominal.type_param_list();
let start_offset = nominal.syntax().text_range().end();
Expand All @@ -38,14 +38,16 @@ pub(crate) fn add_impl(ctx: AssistCtx) -> Option<Assist> {
format_to!(buf, "{}", type_params.syntax());
}
buf.push_str(" ");
buf.push_str(name.text().as_str());
buf.push_str(name.text());
if let Some(type_params) = type_params {
let lifetime_params = type_params
.lifetime_params()
.filter_map(|it| it.lifetime_token())
.map(|it| it.text().clone());
let type_params =
type_params.type_params().filter_map(|it| it.name()).map(|it| it.text().clone());
.map(|it| SmolStr::from(it.text()));
let type_params = type_params
.type_params()
.filter_map(|it| it.name())
.map(|it| SmolStr::from(it.text()));

let generic_params = lifetime_params.chain(type_params).sep_by(", ");
format_to!(buf, "<{}>", generic_params)
Expand Down
2 changes: 1 addition & 1 deletion crates/ra_assists/src/handlers/add_missing_impl_members.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ fn add_missing_impl_members_inner(
ast::ImplItem::TypeAliasDef(def) => def.name(),
ast::ImplItem::ConstDef(def) => def.name(),
}
.map(|it| it.text().clone())
.map(|it| it.text().into())
};

let missing_items = get_missing_impl_items(&ctx.sema, &impl_node)
Expand Down
8 changes: 4 additions & 4 deletions crates/ra_assists/src/handlers/add_new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use ra_syntax::{
ast::{
self, AstNode, NameOwner, StructKind, TypeAscriptionOwner, TypeParamsOwner, VisibilityOwner,
},
TextSize, T,
SmolStr, TextSize, T,
};
use stdx::{format_to, SepBy};

Expand Down Expand Up @@ -101,14 +101,14 @@ fn generate_impl_text(strukt: &ast::StructDef, code: &str) -> String {
format_to!(buf, "{}", type_params.syntax());
}
buf.push_str(" ");
buf.push_str(strukt.name().unwrap().text().as_str());
buf.push_str(strukt.name().unwrap().text());
if let Some(type_params) = type_params {
let lifetime_params = type_params
.lifetime_params()
.filter_map(|it| it.lifetime_token())
.map(|it| it.text().clone());
.map(|it| SmolStr::from(it.text()));
let type_params =
type_params.type_params().filter_map(|it| it.name()).map(|it| it.text().clone());
type_params.type_params().filter_map(|it| it.name()).map(|it| SmolStr::from(it.text()));
format_to!(buf, "<{}>", lifetime_params.chain(type_params).sep_by(", "))
}

Expand Down
2 changes: 1 addition & 1 deletion crates/ra_assists/src/handlers/raw_string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ pub(crate) fn add_hash(ctx: AssistCtx) -> Option<Assist> {
// ```
pub(crate) fn remove_hash(ctx: AssistCtx) -> Option<Assist> {
let token = ctx.find_token_at_offset(RAW_STRING)?;
let text = token.text().as_str();
let text = token.text();
if text.starts_with("r\"") {
// no hash to remove
return None;
Expand Down
2 changes: 1 addition & 1 deletion crates/ra_hir_expand/src/builtin_derive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ fn parse_adt(tt: &tt::Subtree) -> Result<BasicAdtInfo, mbe::ExpandError> {
debug!("name token not found");
mbe::ExpandError::ConversionError
})?;
let name_token = tt::Ident { id: name_token_id, text: name.text().clone() };
let name_token = tt::Ident { id: name_token_id, text: name.text().into() };
let type_params = params.map_or(0, |type_param_list| type_param_list.type_params().count());
Ok(BasicAdtInfo { name: name_token, type_params })
}
Expand Down
6 changes: 3 additions & 3 deletions crates/ra_hir_expand/src/name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ impl Name {
}

/// Resolve a name from the text of token.
fn resolve(raw_text: &SmolStr) -> Name {
fn resolve(raw_text: &str) -> Name {
let raw_start = "r#";
if raw_text.as_str().starts_with(raw_start) {
if raw_text.starts_with(raw_start) {
Name::new_text(SmolStr::new(&raw_text[raw_start.len()..]))
} else {
Name::new_text(raw_text.clone())
Name::new_text(raw_text.into())
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/ra_ide/src/display/navigation_target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ impl NavigationTarget {
description: Option<String>,
) -> NavigationTarget {
//FIXME: use `_` instead of empty string
let name = node.value.name().map(|it| it.text().clone()).unwrap_or_default();
let name = node.value.name().map(|it| SmolStr::from(it.text())).unwrap_or_default();
let focus_range =
node.value.name().map(|it| original_range(db, node.with_value(it.syntax())).range);
let frange = original_range(db, node.map(|it| it.syntax()));
Expand Down
2 changes: 1 addition & 1 deletion crates/ra_ide/src/display/short_label.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,6 @@ where
{
let mut buf = node.visibility().map(|v| format!("{} ", v.syntax())).unwrap_or_default();
buf.push_str(label);
buf.push_str(node.name()?.text().as_str());
buf.push_str(node.name()?.text());
Some(buf)
}
4 changes: 2 additions & 2 deletions crates/ra_ide/src/extend_selection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,8 @@ fn extend_ws(root: &SyntaxNode, ws: SyntaxToken, offset: TextSize) -> TextRange
let ws_text = ws.text();
let suffix = TextRange::new(offset, ws.text_range().end()) - ws.text_range().start();
let prefix = TextRange::new(ws.text_range().start(), offset) - ws.text_range().start();
let ws_suffix = &ws_text.as_str()[suffix];
let ws_prefix = &ws_text.as_str()[prefix];
let ws_suffix = &ws_text[suffix];
let ws_prefix = &ws_text[prefix];
if ws_text.contains('\n') && !ws_suffix.contains('\n') {
if let Some(node) = ws.next_sibling_or_token() {
let start = match ws_prefix.rfind('\n') {
Expand Down
2 changes: 1 addition & 1 deletion crates/ra_ide/src/join_lines.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ fn remove_newline(edit: &mut TextEditBuilder, token: &SyntaxToken, offset: TextS
// The node is either the first or the last in the file
let suff = &token.text()[TextRange::new(
offset - token.text_range().start() + TextSize::of('\n'),
TextSize::of(token.text().as_str()),
TextSize::of(token.text()),
)];
let spaces = suff.bytes().take_while(|&b| b == b' ').count();

Expand Down
2 changes: 1 addition & 1 deletion crates/ra_ide/src/syntax_highlighting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ pub(crate) fn highlight(
if let Some(name) =
fmt_macro_call.path().and_then(|p| p.segment()).and_then(|s| s.name_ref())
{
match name.text().as_str() {
match name.text() {
"format_args" | "format_args_nl" => {
format_string = parent
.children_with_tokens()
Expand Down
2 changes: 1 addition & 1 deletion crates/ra_ide_db/src/symbol_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ fn to_symbol(node: &SyntaxNode) -> Option<(SmolStr, SyntaxNodePtr, TextRange)> {
fn decl<N: NameOwner>(node: N) -> Option<(SmolStr, SyntaxNodePtr, TextRange)> {
let name = node.name()?;
let name_range = name.syntax().text_range();
let name = name.text().clone();
let name = name.text().into();
let ptr = SyntaxNodePtr::new(node.syntax());

Some((name, ptr, name_range))
Expand Down
6 changes: 3 additions & 3 deletions crates/ra_mbe/src/syntax_bridge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ impl SrcToken for SynToken {
}
}
fn to_text(&self) -> SmolStr {
self.token().text().clone()
self.token().text().into()
}
}

Expand Down Expand Up @@ -672,9 +672,9 @@ impl<'a> TreeSink for TtTreeSink<'a> {
self.text_pos += TextSize::of(text.as_str());
}

let text = SmolStr::new(self.buf.as_str());
self.buf.clear();
let text = self.buf.as_str();
self.inner.token(kind, text);
self.buf.clear();

// Add whitespace between adjoint puncts
let next = last.bump();
Expand Down
2 changes: 1 addition & 1 deletion crates/ra_syntax/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ doctest = false

[dependencies]
itertools = "0.9.0"
rowan = "0.10.0"
rowan = "0.11.0"
rustc_lexer = { version = "652.0.0", package = "rustc-ap-rustc_lexer" }
rustc-hash = "1.1.0"
arrayvec = "0.5.1"
Expand Down
Loading