Skip to content

Commit

Permalink
Impl renaming
Browse files Browse the repository at this point in the history
  • Loading branch information
oxalica committed Sep 6, 2022
1 parent 0cdcbe9 commit 55cda67
Show file tree
Hide file tree
Showing 9 changed files with 505 additions and 8 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ Super fast incremental analysis! Scans `all-packages.nix` in less than 0.1s and
- [x] Warnings of unused bindings, `with` and `rec`.
- [ ] Client pulled diagnostics.
- [x] Expand selection. `textDocument/selectionRange`
- [x] Renaming. `textDocument/renamme`, `textDocument/prepareRename`
- [x] Identifiers in parameters and bindings, from `let`, rec and non-rec attrsets.
- [x] Static string literal bindings.
- [x] Merged path-value binding names.
- [ ] Names introduced by `inherit`.
- [ ] Names used by `inherit`.
- [ ] Conflict detection.
- [ ] Rename to string literals.
- [ ] Cross-file analysis.
- [ ] Multi-threaded.

Expand Down
18 changes: 17 additions & 1 deletion crates/ide/src/ide/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ mod diagnostics;
mod expand_selection;
mod goto_definition;
mod references;
mod rename;

use crate::base::SourceDatabaseStorage;
use crate::def::DefDatabaseStorage;
use crate::{Change, Diagnostic, FileId, FilePos, FileRange};
use crate::{Change, Diagnostic, FileId, FilePos, FileRange, WorkspaceEdit};
use rowan::TextRange;
use salsa::{Database, Durability, ParallelDatabase};
use smol_str::SmolStr;
use std::fmt;

pub use completion::{CompletionItem, CompletionItemKind};
Expand All @@ -21,6 +23,8 @@ pub struct NavigationTarget {
}

pub use salsa::Cancelled;

use self::rename::RenameResult;
pub type Cancellable<T> = Result<T, Cancelled>;

#[salsa::database(SourceDatabaseStorage, DefDatabaseStorage)]
Expand Down Expand Up @@ -100,6 +104,18 @@ impl Analysis {
self.with_db(|db| references::references(db, pos))
}

pub fn prepare_rename(&self, fpos: FilePos) -> Cancellable<RenameResult<(TextRange, SmolStr)>> {
self.with_db(|db| rename::prepare_rename(db, fpos))
}

pub fn rename(
&self,
fpos: FilePos,
new_name: &str,
) -> Cancellable<RenameResult<WorkspaceEdit>> {
self.with_db(|db| rename::rename(db, fpos, new_name))
}

pub fn expand_selection(&self, frange: FileRange) -> Cancellable<Option<Vec<TextRange>>> {
self.with_db(|db| expand_selection::expand_selection(db, frange))
}
Expand Down
Loading

0 comments on commit 55cda67

Please sign in to comment.