Skip to content

Commit 595320a

Browse files
committed
Replace Ident with Ident2, using Cow for everything
1 parent 2f0ee3e commit 595320a

15 files changed

Lines changed: 368 additions & 349 deletions

File tree

crates/dm-langserver/src/completion.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use foldhash::{HashSet, HashSetExt};
55
use lsp_types::*;
66

77
use dm::annotation::Annotation;
8-
use dm::ast::PathOp;
8+
use dm::ast::{Ident, PathOp};
99
use dm::objtree::{ProcValue, TypeProc, TypeRef, TypeVar};
1010

1111
use crate::symbol_search::contains;
@@ -103,7 +103,7 @@ fn item_documentation(docs: &dm::docs::DocCollection) -> Option<Documentation> {
103103

104104
fn items_ty<'a>(
105105
results: &mut Vec<CompletionItem>,
106-
skip: &mut HashSet<(&str, &'a String)>,
106+
skip: &mut HashSet<(&str, &'a str)>,
107107
ty: TypeRef<'a>,
108108
query: &str,
109109
) {
@@ -124,7 +124,7 @@ fn items_ty<'a>(
124124
}
125125
if contains(name, query) {
126126
results.push(CompletionItem {
127-
insert_text: Some(name.to_owned()),
127+
insert_text: Some(name.to_string()),
128128
..item_proc(ty, name, proc)
129129
});
130130
}
@@ -134,7 +134,7 @@ fn items_ty<'a>(
134134
pub fn combine_tree_path<'a, I>(
135135
iter: &I,
136136
mut absolute: bool,
137-
mut parts: &'a [String],
137+
mut parts: &'a [Ident],
138138
) -> impl Iterator<Item = &'a str>
139139
where
140140
I: Iterator<Item = (Span, &'a Annotation)> + Clone,
@@ -175,7 +175,7 @@ impl Engine {
175175
pub fn follow_type_path<'b, I>(
176176
&'b self,
177177
iter: &I,
178-
mut parts: &'b [(PathOp, String)],
178+
mut parts: &'b [(PathOp, Ident)],
179179
) -> Option<TypePathResult<'b>>
180180
where
181181
I: Iterator<Item = (Span, &'b Annotation)> + Clone,
@@ -320,7 +320,7 @@ impl Engine {
320320
&'b self,
321321
results: &mut Vec<CompletionItem>,
322322
iter: &I,
323-
parts: &'b [(PathOp, String)],
323+
parts: &'b [(PathOp, Ident)],
324324
_last_op: PathOp,
325325
query: &str,
326326
) where
@@ -419,7 +419,7 @@ impl Engine {
419419
if let Annotation::LocalVarScope(_var_type, name) = annotation {
420420
if contains(name, query) {
421421
results.push(CompletionItem {
422-
label: name.clone(),
422+
label: name.as_str().to_owned(),
423423
kind: Some(CompletionItemKind::VARIABLE),
424424
detail: Some("(local)".to_owned()),
425425
..Default::default()
@@ -436,7 +436,7 @@ impl Engine {
436436
for param in value.parameters.iter() {
437437
if contains(&param.name, query) {
438438
results.push(CompletionItem {
439-
label: param.name.clone(),
439+
label: param.name.as_str().to_owned(),
440440
kind: Some(CompletionItemKind::VARIABLE),
441441
detail: Some("(parameter)".to_owned()),
442442
..Default::default()
@@ -453,7 +453,7 @@ impl Engine {
453453
for (_, (name, define)) in defines.iter() {
454454
if contains(name, query) {
455455
results.push(CompletionItem {
456-
label: name.to_owned(),
456+
label: name.as_str().to_owned(),
457457
kind: Some(CompletionItemKind::CONSTANT),
458458
detail: Some(define.display_with_name(name).to_string()),
459459
documentation: item_documentation(define.docs()),
@@ -476,7 +476,7 @@ impl Engine {
476476
&'b self,
477477
results: &mut Vec<CompletionItem>,
478478
iter: &I,
479-
priors: &[String],
479+
priors: &[Ident],
480480
query: &str,
481481
) where
482482
I: Iterator<Item = (Span, &'b Annotation)> + Clone,

crates/dm-langserver/src/debugger/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ impl DebugDatabaseBuilder {
164164
line_numbers.entry(pv.location.file).or_default().push((
165165
pv.location.line.into(),
166166
ty.path.to_owned(),
167-
name.to_owned(),
167+
name.to_string(),
168168
override_id,
169169
));
170170
}

crates/dm-langserver/src/find_references.rs

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -148,35 +148,35 @@ struct WalkProc<'o> {
148148
objtree: &'o ObjectTree,
149149
ty: TypeRef<'o>,
150150
proc: Option<ProcRef<'o>>,
151-
local_vars: HashMap<String, Local<'o>>,
151+
local_vars: HashMap<Ident, Local<'o>>,
152152
}
153153

154154
impl<'o> WalkProc<'o> {
155155
fn from_proc(tab: &'o mut ReferencesTable, objtree: &'o ObjectTree, proc: ProcRef<'o>) -> Self {
156156
let mut local_vars = HashMap::new();
157157
local_vars.insert(
158-
"global".to_owned(),
158+
"global".into(),
159159
Local {
160160
ty: StaticType::Type(objtree.root()),
161161
symbol: objtree.root().id,
162162
},
163163
);
164164
local_vars.insert(
165-
".".to_owned(),
165+
".".into(),
166166
Local {
167167
ty: StaticType::None,
168168
symbol: tab.new_symbol(proc.location),
169169
},
170170
);
171171
local_vars.insert(
172-
"args".to_owned(),
172+
"args".into(),
173173
Local {
174174
ty: StaticType::Type(objtree.expect("/list")),
175175
symbol: tab.new_symbol(proc.location),
176176
},
177177
);
178178
local_vars.insert(
179-
"usr".to_owned(),
179+
"usr".into(),
180180
Local {
181181
ty: StaticType::Type(objtree.expect("/mob")),
182182
symbol: tab.new_symbol(proc.location),
@@ -186,7 +186,7 @@ impl<'o> WalkProc<'o> {
186186
let ty = proc.ty();
187187
if !ty.is_root() {
188188
local_vars.insert(
189-
"src".to_owned(),
189+
"src".into(),
190190
Local {
191191
ty: StaticType::Type(ty),
192192
symbol: tab.new_symbol(proc.location),
@@ -206,7 +206,7 @@ impl<'o> WalkProc<'o> {
206206
fn from_ty(tab: &'o mut ReferencesTable, objtree: &'o ObjectTree, ty: TypeRef<'o>) -> Self {
207207
let mut local_vars = HashMap::new();
208208
local_vars.insert(
209-
"global".to_owned(),
209+
"global".into(),
210210
Local {
211211
ty: StaticType::Type(objtree.root()),
212212
symbol: objtree.root().id,
@@ -433,7 +433,7 @@ impl<'o> WalkProc<'o> {
433433
&mut self,
434434
location: Location,
435435
var_type: &VarType,
436-
name: &str,
436+
name: &Ident,
437437
value: Option<&'o Expression>,
438438
) {
439439
let ty = self.static_type(location, &var_type.type_path);
@@ -442,7 +442,7 @@ impl<'o> WalkProc<'o> {
442442
self.visit_expression(location, expr, ty.basic_type());
443443
}
444444
self.local_vars.insert(
445-
name.to_owned(),
445+
name.clone(),
446446
Local {
447447
ty,
448448
symbol: self.tab.new_symbol(location),
@@ -844,15 +844,14 @@ impl<'o> WalkProc<'o> {
844844
rhs,
845845
} = arg
846846
{
847-
match lhs.as_term() {
848-
Some(Term::Ident(_name)) | Some(Term::String(_name)) => {
847+
if let Some(term) = lhs.as_term() {
848+
if let Some(_name) = term.as_kwarg_key() {
849849
// Don't visit_expression the kwarg key.
850850
argument_value = rhs;
851851

852852
// TODO: register a usage of the kwarg symbol here.
853853
// Recurse to children too?
854-
},
855-
_ => {},
854+
}
856855
}
857856
}
858857

@@ -871,12 +870,11 @@ impl<'o> WalkProc<'o> {
871870
rhs,
872871
} = arg
873872
{
874-
match lhs.as_term() {
875-
Some(Term::Ident(_name)) | Some(Term::String(_name)) => {
873+
if let Some(term) = lhs.as_term() {
874+
if let Some(_name) = term.as_kwarg_key() {
876875
// Don't visit_expression the kwarg key.
877876
argument_value = rhs;
878-
},
879-
_ => {},
877+
}
880878
}
881879
}
882880

@@ -885,7 +883,7 @@ impl<'o> WalkProc<'o> {
885883
}
886884

887885
#[allow(clippy::only_used_in_recursion)]
888-
fn static_type(&mut self, location: Location, mut of: &[String]) -> StaticType<'o> {
886+
fn static_type(&mut self, location: Location, mut of: &[Ident]) -> StaticType<'o> {
889887
while !of.is_empty()
890888
&& [
891889
"static",

crates/dm-langserver/src/main.rs

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ mod symbol_search;
3636

3737
use crate::extras::{QueryObjectTree, Reparse, SetTraceVsc, StartDebugger};
3838
use dm::annotation::{Annotation, AnnotationTree};
39+
use dm::ast::Ident;
3940
use dm::objtree::TypeRef;
4041
use dm::FileId;
4142
use foldhash::{HashMap, HashMapExt, HashSet, HashSetExt};
@@ -436,7 +437,7 @@ impl Engine {
436437
for (name, var) in ty.vars.iter() {
437438
let is_declaration = var.declaration.is_some();
438439
entry.vars.push(extras::ObjectTreeVar {
439-
name: name.to_owned(),
440+
name: name.to_string(),
440441
kind: if var
441442
.declaration
442443
.as_ref()
@@ -463,7 +464,7 @@ impl Engine {
463464
let mut is_verb = proc.declaration.as_ref().map(|d| d.kind.is_verb());
464465
for value in proc.value.iter() {
465466
entry.procs.push(extras::ObjectTreeProc {
466-
name: name.to_owned(),
467+
name: name.to_string(),
467468
kind: if ty.is_root() {
468469
lsp_types::SymbolKind::FUNCTION
469470
} else if is_constructor_name(name) {
@@ -917,7 +918,7 @@ impl Engine {
917918
UnscopedVar::None
918919
}
919920

920-
fn find_scoped_type<'b, I>(&'b self, iter: &I, priors: &[String]) -> Option<TypeRef<'b>>
921+
fn find_scoped_type<'b, I>(&'b self, iter: &I, priors: &[Ident]) -> Option<TypeRef<'b>>
921922
where
922923
I: Iterator<Item = (Span, &'b Annotation)> + Clone,
923924
{
@@ -1466,7 +1467,7 @@ impl Engine {
14661467
for (range, (name, define)) in defines.iter() {
14671468
if query.matches_define(name) {
14681469
results.push(SymbolInformation {
1469-
name: name.to_owned(),
1470+
name: name.to_string(),
14701471
kind: SymbolKind::CONSTANT,
14711472
location: self.convert_location(
14721473
range.start,
@@ -1500,7 +1501,7 @@ impl Engine {
15001501
if let Some(decl) = tv.declaration.as_ref() {
15011502
if query.matches_var(var_name) {
15021503
results.push(SymbolInformation {
1503-
name: var_name.clone(),
1504+
name: var_name.to_string(),
15041505
kind: SymbolKind::FIELD,
15051506
location: self.convert_location(
15061507
decl.location,
@@ -1519,7 +1520,7 @@ impl Engine {
15191520
if let Some(decl) = pv.declaration.as_ref() {
15201521
if query.matches_proc(proc_name, decl.kind) {
15211522
results.push(SymbolInformation {
1522-
name: proc_name.clone(),
1523+
name: proc_name.to_string(),
15231524
kind: if ty.is_root() {
15241525
SymbolKind::FUNCTION
15251526
} else if is_constructor_name(proc_name.as_str()) {
@@ -1858,7 +1859,7 @@ impl Engine {
18581859
column: tdp.position.character as u16 + 1,
18591860
};
18601861

1861-
let mut type_path: &[String] = &[];
1862+
let mut type_path: &[Ident] = &[];
18621863

18631864
let iter = annotations.get_location(location);
18641865
match_annotation! { iter;
@@ -2072,7 +2073,7 @@ impl Engine {
20722073
});
20732074
} else {
20742075
params.push(ParameterInformation {
2075-
label: ParameterLabel::Simple(param.name.clone()),
2076+
label: ParameterLabel::Simple(param.name.to_string()),
20762077
documentation: None,
20772078
});
20782079
}
@@ -2108,10 +2109,10 @@ impl Engine {
21082109
&mut self,
21092110
params: P<DocumentSymbolRequest>,
21102111
) -> R<DocumentSymbolRequest> {
2111-
fn name_and_detail(path: &[String], skip_front: usize) -> (String, Option<String>) {
2112+
fn name_and_detail(path: &[Ident], skip_front: usize) -> (String, Option<String>) {
21122113
let (name, rest) = path.split_last().unwrap();
21132114
(
2114-
name.to_owned(),
2115+
name.to_string(),
21152116
rest.get(skip_front..).and_then(|i| {
21162117
i.iter()
21172118
.rev()
@@ -2121,7 +2122,7 @@ impl Engine {
21212122
&& dm::ast::VarTypeFlags::from_name(x).is_none()
21222123
&& *x != "var"
21232124
})
2124-
.map(ToOwned::to_owned)
2125+
.map(|i| i.to_string())
21252126
}),
21262127
)
21272128
}
@@ -2206,7 +2207,7 @@ impl Engine {
22062207
},
22072208
Annotation::LocalVarScope(_, ref name) => {
22082209
result.push(DocumentSymbol {
2209-
name: name.to_owned(),
2210+
name: name.to_string(),
22102211
detail: None,
22112212
kind: SymbolKind::VARIABLE,
22122213
tags: None,
@@ -2217,7 +2218,7 @@ impl Engine {
22172218
});
22182219
},
22192220
Annotation::MacroDefinition(ref name) => result.push(DocumentSymbol {
2220-
name: name.to_owned(),
2221+
name: name.to_string(),
22212222
detail: None,
22222223
kind: SymbolKind::CONSTANT,
22232224
tags: None,

0 commit comments

Comments
 (0)