Skip to content

Commit

Permalink
misc: changes from code review
Browse files Browse the repository at this point in the history
  • Loading branch information
baszalmstra committed Apr 10, 2021
1 parent 4936096 commit b1f50b2
Show file tree
Hide file tree
Showing 13 changed files with 37 additions and 35 deletions.
2 changes: 1 addition & 1 deletion crates/mun_abi/ffi
Submodule ffi updated 1 files
+65 −57 include/mun_abi.h
4 changes: 2 additions & 2 deletions crates/mun_hir/src/code_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ pub use self::{
function::Function,
module::{Module, ModuleDef},
package::Package,
r#struct::{Field, LocalStructFieldId, Struct, StructKind, StructMemoryKind},
r#struct::{Field, LocalFieldId, Struct, StructKind, StructMemoryKind},
src::HasSource,
type_alias::TypeAlias,
};

pub use self::{
function::FunctionData,
r#struct::{StructData, StructFieldData},
r#struct::{FieldData, StructData},
type_alias::TypeAliasData,
};

Expand Down
14 changes: 7 additions & 7 deletions crates/mun_hir/src/code_model/struct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ impl From<StructId> for Struct {
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct Field {
pub(crate) parent: Struct,
pub(crate) id: LocalStructFieldId,
pub(crate) id: LocalFieldId,
}

impl Field {
Expand All @@ -58,7 +58,7 @@ impl Field {
}

/// Returns the ID of the field with relation to the parent struct
pub(crate) fn id(self) -> LocalStructFieldId {
pub(crate) fn id(self) -> LocalFieldId {
self.id
}
}
Expand Down Expand Up @@ -140,7 +140,7 @@ impl Struct {
/// )
/// ```
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct StructFieldData {
pub struct FieldData {
pub name: Name,
pub type_ref: LocalTypeRefId,
}
Expand All @@ -164,13 +164,13 @@ impl fmt::Display for StructKind {
}

/// An identifier for a struct's or tuple's field
pub type LocalStructFieldId = Idx<StructFieldData>;
pub type LocalFieldId = Idx<FieldData>;

#[derive(Debug, PartialEq, Eq)]
pub struct StructData {
pub name: Name,
pub visibility: RawVisibility,
pub fields: Arena<StructFieldData>,
pub fields: Arena<FieldData>,
pub kind: StructKind,
pub memory_kind: StructMemoryKind,
type_ref_map: TypeRefMap,
Expand All @@ -194,7 +194,7 @@ impl StructData {
ast::StructKind::Record(r) => {
let fields = r
.fields()
.map(|fd| StructFieldData {
.map(|fd| FieldData {
name: fd.name().map(|n| n.as_name()).unwrap_or_else(Name::missing),
type_ref: type_ref_builder.alloc_from_node_opt(fd.ascribed_type().as_ref()),
})
Expand All @@ -205,7 +205,7 @@ impl StructData {
let fields = t
.fields()
.enumerate()
.map(|(index, fd)| StructFieldData {
.map(|(index, fd)| FieldData {
name: Name::new_tuple_field(index),
type_ref: type_ref_builder.alloc_from_node_opt(fd.type_ref().as_ref()),
})
Expand Down
13 changes: 7 additions & 6 deletions crates/mun_hir/src/semantics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
//! Our compilation databases (e.g. `HirDatabase`) provides a lot of steps to go from a syntax tree
//! (as provided by the [`mun_syntax::ast`] module) to more abstract representations of the source
//! through the process of `lowering`. However, for IDE purposes we often want to cut through all
//! this and go from source locations straight to lowered datastructures and back. This is what the
//! this and go from source locations straight to lowered data structures and back. This is what
//! [`Semantics`] enables.

mod source_to_def;
Expand Down Expand Up @@ -45,7 +45,7 @@ impl<'db> Semantics<'db> {
}
}

/// Returns the the Concrete Syntax Tree for the file with the given `file_id`.
/// Returns the Concrete Syntax Tree for the file with the given `file_id`.
pub fn parse(&self, file_id: FileId) -> ast::SourceFile {
let tree = self.db.parse(file_id).tree();
let mut cache = self.source_file_to_file.borrow_mut();
Expand Down Expand Up @@ -111,7 +111,7 @@ impl<'db> Semantics<'db> {
f(&mut context)
}

/// Returns the file that is associated with the given root CST node or None if no such
/// Returns the file that is associated with the given root CST node or `None` if no such
/// association exists.
fn lookup_file(&self, root_node: &SyntaxNode) -> Option<FileId> {
let cache = self.source_file_to_file.borrow();
Expand Down Expand Up @@ -201,15 +201,16 @@ impl Local {
}

impl<'a> SemanticsScope<'a> {
pub fn visit_all_names(&self, visitor: &mut dyn FnMut(Name, ScopeDef)) {
/// Call the `visit` function for every named item in the scope
pub fn visit_all_names(&self, visit: &mut dyn FnMut(Name, ScopeDef)) {
let resolver = &self.resolver;

resolver.visit_all_names(self.db.upcast(), &mut |name, def| {
let def = match def {
resolve::ScopeDef::PerNs(it) => {
let items = ScopeDef::all_items(it);
for item in items {
visitor(name.clone(), item);
visit(name.clone(), item);
}
return;
}
Expand All @@ -220,7 +221,7 @@ impl<'a> SemanticsScope<'a> {
ScopeDef::Local(Local { parent, pat_id })
}
};
visitor(name, def)
visit(name, def)
})
}
}
16 changes: 10 additions & 6 deletions crates/mun_hir/src/semantics/source_to_def.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
use crate::code_model::src::HasSource;
use crate::ids::{DefWithBodyId, FunctionId, ItemDefinitionId, Lookup, StructId, TypeAliasId};
use crate::item_scope::ItemScope;
use crate::{DefDatabase, FileId, HirDatabase, InFile, ModuleId};
use crate::{
code_model::src::HasSource,
ids::{DefWithBodyId, FunctionId, ItemDefinitionId, Lookup, StructId, TypeAliasId},
item_scope::ItemScope,
DefDatabase, FileId, HirDatabase, InFile, ModuleId,
};
use mun_syntax::{ast, match_ast, AstNode, SyntaxNode};
use rustc_hash::FxHashMap;

pub(super) type SourceToDefCache = FxHashMap<SourceToDefContainer, SourceToDefMap>;

pub(super) struct SourceToDefContext<'a, 'b> {
pub(super) db: &'b dyn HirDatabase,
/// An object that can be used to efficiently find definitions of source objects. It is used to
/// find HIR elements for corresponding AST elements.
pub(super) struct SourceToDefContext<'a, 'db> {
pub(super) db: &'db dyn HirDatabase,
pub(super) cache: &'a mut SourceToDefCache,
}

Expand Down
9 changes: 3 additions & 6 deletions crates/mun_hir/src/source_analyzer.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
use crate::expr::scope::LocalScopeId;
use crate::expr::BodySourceMap;
use crate::ids::DefWithBodyId;
use crate::{
resolver_for_scope, Body, ExprId, ExprScopes, FileId, HirDatabase, InFile, InferenceResult,
Resolver, Ty,
expr::scope::LocalScopeId, expr::BodySourceMap, ids::DefWithBodyId, resolver_for_scope, Body,
ExprId, ExprScopes, FileId, HirDatabase, InFile, InferenceResult, Resolver, Ty,
};
use mun_syntax::{ast, AstNode, SyntaxNode, TextRange, TextSize};
use std::sync::Arc;

/// A `SourceAnalyzer` is a wrapper which exposes the HIR API in terms of the original source file.
/// Its useful to query things from the syntax.
/// It's useful to query things from the syntax.
pub(crate) struct SourceAnalyzer {
/// The file for which this analyzer was constructed
pub(crate) file_id: FileId,
Expand Down
2 changes: 1 addition & 1 deletion crates/mun_language_server/src/change_fixture.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::change::AnalysisChange;
use hir::fixture::Fixture;
use mun_syntax::{TextRange, TextSize};
use mun_test::Fixture;
use std::sync::Arc;

pub const CURSOR_MARKER: &str = "$0";
Expand Down
2 changes: 1 addition & 1 deletion crates/mun_language_server/src/completion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub use item::{CompletionItem, CompletionItemKind, CompletionKind};
///
/// Second is to compute a set of completions based on the previously computed context. We provide
/// several methods for computing completions based on different syntax contexts. For instance when
/// writing `foo.$0` you want to complete the fields of `foo` and dont want the local variables of
/// writing `foo.$0` you want to complete the fields of `foo` and don't want the local variables of
/// the active scope.
pub(crate) fn completions(db: &AnalysisDatabase, position: FilePosition) -> Option<Completions> {
let context = CompletionContext::new(db, position)?;
Expand Down
2 changes: 1 addition & 1 deletion crates/mun_language_server/src/completion/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ impl<'a> CompletionContext<'a> {
}
}

/// Returns true if the given `node` or on if its parents is of the specified type.
/// Returns true if the given `node` or one if its parents is of the specified type.
fn is_node<N: AstNode>(node: &SyntaxNode) -> bool {
match node.ancestors().find_map(N::cast) {
None => false,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::{CompletionContext, Completions};

/// Adds completions to `result` for unqualified path. Unqualified path are simple names which do
/// Adds completions to `result` for unqualified path. Unqualified paths are simple names which do
/// not refer to anything outside of the current scope: local function names, variables, etc. E.g.:
/// ```mun
/// fn foo() {
Expand Down
2 changes: 1 addition & 1 deletion crates/mun_language_server/src/to_lsp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ pub(crate) fn url(snapshot: &LanguageServerSnapshot, file_id: hir::FileId) -> an
Ok(url)
}

/// Converts from our CompletionItem to an LSP CompletionItem
/// Converts from our `CompletionItem` to an LSP `CompletionItem`
pub(crate) fn completion_item(completion_item: CompletionItem) -> lsp_types::CompletionItem {
lsp_types::CompletionItem {
label: completion_item.label,
Expand Down
2 changes: 1 addition & 1 deletion crates/mun_syntax/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ impl Parse<SourceFile> {
self.full_reparse(indel)
}

/// Performance a "reparse" of the SourceFile after applying the specified modification by
/// Performs a "reparse" of the `SourceFile` after applying the specified modification by
/// simply parsing the entire thing again.
fn full_reparse(&self, indel: &Indel) -> Parse<SourceFile> {
let mut text = self.tree().syntax().text().to_string();
Expand Down

0 comments on commit b1f50b2

Please sign in to comment.