Skip to content

Commit

Permalink
Rename contains to test_contains and contains_ok to contains
Browse files Browse the repository at this point in the history
…for `SymbolTable` and marcher
  • Loading branch information
SpontanCombust committed May 19, 2024
1 parent 6b3d4b8 commit 6afb230
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
2 changes: 1 addition & 1 deletion crates/analysis/src/jobs/scan_symbols.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ struct SymbolScannerVisitor<'a> {
impl SymbolScannerVisitor<'_> {
// Returns whether the symbol is not a duplicate
fn check_contains(&mut self, path: &SymbolPath, range: Range) -> bool {
if let Err(err) = self.symtab.contains(path) {
if let Err(err) = self.symtab.test_contains(path) {
// missing nodes don't get an error, as it's the job of syntax analysis to detect them and inform the user about them
// these situations are very rare anyways, so doing anything aside from showing a diagnostic is an overkill
if !path.has_missing() {
Expand Down
10 changes: 7 additions & 3 deletions crates/analysis/src/symbol_analysis/symbol_table/marcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,20 @@ where It: Clone {

impl<'a, It> SymbolTableMarcher<It>
where It: Iterator<Item = &'a SymbolTable> + 'a {
pub fn contains(mut self, path: &SymbolPath) -> Result<(), PathOccupiedError> {
pub fn test_contains(mut self, path: &SymbolPath) -> Result<(), PathOccupiedError> {
while let Some(symtab) = self.it.next() {
symtab.contains(path)?;
symtab.test_contains(path)?;
}

Ok(())
}

pub fn contains(mut self, path: &SymbolPath) -> bool {
self.it.find(|symtab| symtab.contains(path)).is_some()
}

pub fn find_containing(self, path: &SymbolPath) -> Option<&'a SymbolTable> {
self.march(|symtab| if symtab.contains_ok(path) { Some(symtab) } else { None })
self.march(|symtab| if symtab.contains(path) { Some(symtab) } else { None })
}

#[inline]
Expand Down
9 changes: 5 additions & 4 deletions crates/analysis/src/symbol_analysis/symbol_table/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,10 @@ impl SymbolTable {
self.symbols.is_empty()
}

//TODO rename to is_occupied
/// If the path is occupied returns Err(PathOccupiedError).
/// Otherwise if the path was not found returns Ok.
pub fn contains(&self, path: &SymbolPath) -> Result<(), PathOccupiedError> {
/// If you only want to know if the path exists in the symbol table without extra info, use [`Self::contains`] instead.
pub fn test_contains(&self, path: &SymbolPath) -> Result<(), PathOccupiedError> {
if let Some(occupying) = self.symbols.get(path) {
Err(PathOccupiedError {
occupied_path: occupying.path().to_sympath_buf(),
Expand All @@ -98,9 +98,10 @@ impl SymbolTable {
}
}

//TODO rename to contains
/// Returns whether the given symbol path exists in the symbol table.
/// If you want to know more about the occupying symbol, use [`Self::test_contains`] instead.
#[inline]
pub fn contains_ok(&self, path: &SymbolPath) -> bool {
pub fn contains(&self, path: &SymbolPath) -> bool {
self.symbols.contains_key(path)
}

Expand Down

0 comments on commit 6afb230

Please sign in to comment.