Skip to content

Commit 2e0f5f6

Browse files
committed
Auto merge of rust-lang#17849 - Veykril:rust-analyzer-crate, r=Veykril
internal: Move some main crate stuff
2 parents bee4926 + 01262d9 commit 2e0f5f6

File tree

10 files changed

+58
-60
lines changed

10 files changed

+58
-60
lines changed

src/tools/rust-analyzer/crates/rust-analyzer/src/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ use triomphe::Arc;
3434
use vfs::{AbsPath, AbsPathBuf, VfsPath};
3535

3636
use crate::{
37-
capabilities::ClientCapabilities,
3837
diagnostics::DiagnosticsMapConfig,
3938
flycheck::{CargoOptions, FlycheckConfig},
39+
lsp::capabilities::ClientCapabilities,
4040
lsp_ext::{WorkspaceSymbolSearchKind, WorkspaceSymbolSearchScope},
4141
};
4242

src/tools/rust-analyzer/crates/rust-analyzer/src/diff.rs

Lines changed: 0 additions & 53 deletions
This file was deleted.

src/tools/rust-analyzer/crates/rust-analyzer/src/global_state.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,11 @@ impl GlobalState {
460460
}
461461
}
462462

463+
// FIXME: `workspace_structure_change` is computed from `should_refresh_for_change` which is
464+
// path syntax based. That is not sufficient for all cases so we should lift that check out
465+
// into a `QueuedTask`, see `handle_did_save_text_document`.
466+
// Or maybe instead of replacing that check, kick off a semantic one if the syntactic one
467+
// didn't find anything (to make up for the lack of precision).
463468
{
464469
if !matches!(&workspace_structure_change, Some((.., true))) {
465470
_ = self

src/tools/rust-analyzer/crates/rust-analyzer/src/handlers/notification.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,8 @@ pub(crate) fn handle_did_save_text_document(
158158
.map(|cfg| cfg.files_to_watch.iter().map(String::as_str).collect::<Vec<&str>>())
159159
.unwrap_or_default();
160160

161+
// FIXME: We should move this check into a QueuedTask and do semantic resolution of
162+
// the files. There is only so much we can tell syntactically from the path.
161163
if reload::should_refresh_for_change(path, ChangeKind::Modify, additional_files) {
162164
state.fetch_workspaces_queue.request_op(
163165
format!("workspace vfs file change saved {path}"),

src/tools/rust-analyzer/crates/rust-analyzer/src/handlers/request.rs

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ use vfs::{AbsPath, AbsPathBuf, FileId, VfsPath};
3636

3737
use crate::{
3838
config::{Config, RustfmtConfig, WorkspaceSymbolConfig},
39-
diff::diff,
4039
global_state::{FetchWorkspaceRequest, GlobalState, GlobalStateSnapshot},
4140
hack_recover_crate_name,
4241
line_index::LineEndings,
@@ -2370,3 +2369,47 @@ fn resolve_resource_op(op: &ResourceOp) -> ResourceOperationKind {
23702369
ResourceOp::Delete(_) => ResourceOperationKind::Delete,
23712370
}
23722371
}
2372+
2373+
pub(crate) fn diff(left: &str, right: &str) -> TextEdit {
2374+
use dissimilar::Chunk;
2375+
2376+
let chunks = dissimilar::diff(left, right);
2377+
2378+
let mut builder = TextEdit::builder();
2379+
let mut pos = TextSize::default();
2380+
2381+
let mut chunks = chunks.into_iter().peekable();
2382+
while let Some(chunk) = chunks.next() {
2383+
if let (Chunk::Delete(deleted), Some(&Chunk::Insert(inserted))) = (chunk, chunks.peek()) {
2384+
chunks.next().unwrap();
2385+
let deleted_len = TextSize::of(deleted);
2386+
builder.replace(TextRange::at(pos, deleted_len), inserted.into());
2387+
pos += deleted_len;
2388+
continue;
2389+
}
2390+
2391+
match chunk {
2392+
Chunk::Equal(text) => {
2393+
pos += TextSize::of(text);
2394+
}
2395+
Chunk::Delete(deleted) => {
2396+
let deleted_len = TextSize::of(deleted);
2397+
builder.delete(TextRange::at(pos, deleted_len));
2398+
pos += deleted_len;
2399+
}
2400+
Chunk::Insert(inserted) => {
2401+
builder.insert(pos, inserted.into());
2402+
}
2403+
}
2404+
}
2405+
builder.finish()
2406+
}
2407+
2408+
#[test]
2409+
fn diff_smoke_test() {
2410+
let mut original = String::from("fn foo(a:u32){\n}");
2411+
let result = "fn foo(a: u32) {}";
2412+
let edit = diff(&original, result);
2413+
edit.apply(&mut original);
2414+
assert_eq!(original, result);
2415+
}

src/tools/rust-analyzer/crates/rust-analyzer/src/lib.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,9 @@
1111
1212
pub mod cli;
1313

14-
mod capabilities;
1514
mod command;
1615
mod diagnostics;
17-
mod diff;
1816
mod discover;
19-
mod dispatch;
2017
mod flycheck;
2118
mod hack_recover_crate_name;
2219
mod line_index;
@@ -30,6 +27,7 @@ mod test_runner;
3027
mod version;
3128

3229
mod handlers {
30+
pub(crate) mod dispatch;
3331
pub(crate) mod notification;
3432
pub(crate) mod request;
3533
}
@@ -51,7 +49,7 @@ mod integrated_benchmarks;
5149
use serde::de::DeserializeOwned;
5250

5351
pub use crate::{
54-
capabilities::server_capabilities, main_loop::main_loop, reload::ws_to_crate_graph,
52+
lsp::capabilities::server_capabilities, main_loop::main_loop, reload::ws_to_crate_graph,
5553
version::version,
5654
};
5755

src/tools/rust-analyzer/crates/rust-analyzer/src/lsp.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
use core::fmt;
44

55
pub mod ext;
6+
7+
pub(crate) mod capabilities;
68
pub(crate) mod from_proto;
79
pub(crate) mod semantic_tokens;
810
pub(crate) mod to_proto;

src/tools/rust-analyzer/crates/rust-analyzer/src/main_loop.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ use crate::{
2020
config::Config,
2121
diagnostics::{fetch_native_diagnostics, DiagnosticsGeneration, NativeDiagnosticsFetchKind},
2222
discover::{DiscoverArgument, DiscoverCommand, DiscoverProjectMessage},
23-
dispatch::{NotificationDispatcher, RequestDispatcher},
2423
flycheck::{self, FlycheckMessage},
2524
global_state::{file_id_to_url, url_to_file_id, FetchWorkspaceRequest, GlobalState},
2625
hack_recover_crate_name,
26+
handlers::dispatch::{NotificationDispatcher, RequestDispatcher},
2727
lsp::{
2828
from_proto, to_proto,
2929
utils::{notification_is, Progress},
@@ -105,6 +105,7 @@ pub(crate) enum Task {
105105
FetchWorkspace(ProjectWorkspaceProgress),
106106
FetchBuildData(BuildDataProgress),
107107
LoadProcMacros(ProcMacroProgress),
108+
// FIXME: Remove this in favor of a more general QueuedTask, see `handle_did_save_text_document`
108109
BuildDepsHaveChanged,
109110
}
110111

0 commit comments

Comments
 (0)