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

Some nits for Pax lsp #55

Closed
wants to merge 5 commits 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
70 changes: 20 additions & 50 deletions pax-language-server/src/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,15 @@ fn extract_between(source: &str, start: &str, _end: &str) -> Option<String> {
}
}

fn create_info(file_path: &str, span: Span) -> Info {
Info {
path: file_path.to_string(),
position: span_to_position(span),
definition_id: None,
hover_id: None,
}
}

struct IndexVisitor<'a> {
index: &'a DashMap<String, IdentifierInfo>,
file_path: String,
Expand All @@ -221,11 +230,12 @@ impl<'ast, 'a> Visit<'ast> for IndexVisitor<'a> {
fn visit_item_struct(&mut self, i: &'ast ItemStruct) {
let attributes = &i.attrs;

let ty = if attributes.iter().any(|attr| {
let is_special = |attr: &Attribute| {
attr.path.is_ident("primitive")
|| attr.path.is_ident("inlined")
|| attr.path.is_ident("file")
}) {
};
let ty = if attributes.iter().any(is_special) {
IdentifierType::Component
} else {
IdentifierType::PaxType
Expand All @@ -237,12 +247,7 @@ impl<'ast, 'a> Visit<'ast> for IndexVisitor<'a> {
.map(|f| {
let rust_type_string = extract_rust_type(&(f.clone()).ty);
if let Some(_) = f.ident.clone() {
let prop_info = Info {
path: self.file_path.clone(),
position: span_to_position(f.ident.clone().unwrap().span()),
definition_id: None,
hover_id: None,
};
let prop_info = create_info(&self.file_path, f.ident.span());

self.requests.push(InfoRequest {
identifier_type: IdentifierType::Property,
Expand All @@ -260,12 +265,7 @@ impl<'ast, 'a> Visit<'ast> for IndexVisitor<'a> {
StructProperty {
identifier: rust_type_string.clone(),
rust_type: rust_type_string.clone(),
info: Info {
path: self.file_path.clone(),
position: span_to_position(f.ty.span()),
definition_id: None,
hover_id: None,
},
info: create_info(&self.file_path, f.ty.span()),
}
}
})
Expand All @@ -277,12 +277,7 @@ impl<'ast, 'a> Visit<'ast> for IndexVisitor<'a> {
IdentifierInfo {
ty: ty.clone(),
identifier: struct_name.clone(),
info: Info {
path: self.file_path.clone(),
position: span_to_position(i.span()),
definition_id: None,
hover_id: None,
},
info: create_info(&self.file_path, i.span()),
properties,
methods: Vec::new(),
variants: Vec::new(),
Expand All @@ -293,12 +288,7 @@ impl<'ast, 'a> Visit<'ast> for IndexVisitor<'a> {
identifier_type: ty,
identifier: struct_name,
owner_identifier: None,
info: Info {
path: self.file_path.clone(),
position: span_to_position(i.ident.span()),
definition_id: None,
hover_id: None,
},
info: create_info(&self.file_path, i.ident.span()),
});
}

Expand All @@ -318,12 +308,7 @@ impl<'ast, 'a> Visit<'ast> for IndexVisitor<'a> {
let method_name = method.sig.ident.to_string();
let method_info = Method {
identifier: method_name.clone(),
info: Info {
path: self.file_path.clone(),
position: span_to_position(method.sig.ident.span()),
definition_id: None,
hover_id: None,
},
info: create_info(&self.file_path, method.sig.ident.span()),
};
info.methods.push(method_info.clone());

Expand Down Expand Up @@ -353,12 +338,7 @@ impl<'ast, 'a> Visit<'ast> for IndexVisitor<'a> {
let variant_info = VariantData {
identifier: variant.ident.to_string(),
has_fields,
info: Info {
path: self.file_path.clone(),
position: span_to_position(variant.ident.span()),
definition_id: None,
hover_id: None,
},
info: create_info(&self.file_path, variant.ident.span()),
};

self.requests.push(InfoRequest {
Expand All @@ -377,12 +357,7 @@ impl<'ast, 'a> Visit<'ast> for IndexVisitor<'a> {
IdentifierInfo {
ty: IdentifierType::Enum,
identifier: enum_name.clone(),
info: Info {
path: self.file_path.clone(),
position: span_to_position(i.ident.span()),
definition_id: None,
hover_id: None,
},
info: create_info(&self.file_path, i.span()),
properties: Vec::new(),
methods: Vec::new(),
variants,
Expand All @@ -393,12 +368,7 @@ impl<'ast, 'a> Visit<'ast> for IndexVisitor<'a> {
identifier_type: IdentifierType::Enum,
identifier: enum_name,
owner_identifier: None,
info: Info {
path: self.file_path.clone(),
position: span_to_position(i.ident.span()),
definition_id: None,
hover_id: None,
},
info: create_info(&self.file_path, i.ident.span()),
});
}
}
Expand Down
Loading