Skip to content

Commit

Permalink
Auto merge of rust-lang#17849 - Veykril:rust-analyzer-crate, r=Veykril
Browse files Browse the repository at this point in the history
internal: Move some main crate stuff
  • Loading branch information
bors committed Aug 10, 2024
2 parents bee4926 + 01262d9 commit 2e0f5f6
Show file tree
Hide file tree
Showing 10 changed files with 58 additions and 60 deletions.
2 changes: 1 addition & 1 deletion src/tools/rust-analyzer/crates/rust-analyzer/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ use triomphe::Arc;
use vfs::{AbsPath, AbsPathBuf, VfsPath};

use crate::{
capabilities::ClientCapabilities,
diagnostics::DiagnosticsMapConfig,
flycheck::{CargoOptions, FlycheckConfig},
lsp::capabilities::ClientCapabilities,
lsp_ext::{WorkspaceSymbolSearchKind, WorkspaceSymbolSearchScope},
};

Expand Down
53 changes: 0 additions & 53 deletions src/tools/rust-analyzer/crates/rust-analyzer/src/diff.rs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,11 @@ impl GlobalState {
}
}

// FIXME: `workspace_structure_change` is computed from `should_refresh_for_change` which is
// path syntax based. That is not sufficient for all cases so we should lift that check out
// into a `QueuedTask`, see `handle_did_save_text_document`.
// Or maybe instead of replacing that check, kick off a semantic one if the syntactic one
// didn't find anything (to make up for the lack of precision).
{
if !matches!(&workspace_structure_change, Some((.., true))) {
_ = self
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@ pub(crate) fn handle_did_save_text_document(
.map(|cfg| cfg.files_to_watch.iter().map(String::as_str).collect::<Vec<&str>>())
.unwrap_or_default();

// FIXME: We should move this check into a QueuedTask and do semantic resolution of
// the files. There is only so much we can tell syntactically from the path.
if reload::should_refresh_for_change(path, ChangeKind::Modify, additional_files) {
state.fetch_workspaces_queue.request_op(
format!("workspace vfs file change saved {path}"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ use vfs::{AbsPath, AbsPathBuf, FileId, VfsPath};

use crate::{
config::{Config, RustfmtConfig, WorkspaceSymbolConfig},
diff::diff,
global_state::{FetchWorkspaceRequest, GlobalState, GlobalStateSnapshot},
hack_recover_crate_name,
line_index::LineEndings,
Expand Down Expand Up @@ -2370,3 +2369,47 @@ fn resolve_resource_op(op: &ResourceOp) -> ResourceOperationKind {
ResourceOp::Delete(_) => ResourceOperationKind::Delete,
}
}

pub(crate) fn diff(left: &str, right: &str) -> TextEdit {
use dissimilar::Chunk;

let chunks = dissimilar::diff(left, right);

let mut builder = TextEdit::builder();
let mut pos = TextSize::default();

let mut chunks = chunks.into_iter().peekable();
while let Some(chunk) = chunks.next() {
if let (Chunk::Delete(deleted), Some(&Chunk::Insert(inserted))) = (chunk, chunks.peek()) {
chunks.next().unwrap();
let deleted_len = TextSize::of(deleted);
builder.replace(TextRange::at(pos, deleted_len), inserted.into());
pos += deleted_len;
continue;
}

match chunk {
Chunk::Equal(text) => {
pos += TextSize::of(text);
}
Chunk::Delete(deleted) => {
let deleted_len = TextSize::of(deleted);
builder.delete(TextRange::at(pos, deleted_len));
pos += deleted_len;
}
Chunk::Insert(inserted) => {
builder.insert(pos, inserted.into());
}
}
}
builder.finish()
}

#[test]
fn diff_smoke_test() {
let mut original = String::from("fn foo(a:u32){\n}");
let result = "fn foo(a: u32) {}";
let edit = diff(&original, result);
edit.apply(&mut original);
assert_eq!(original, result);
}
6 changes: 2 additions & 4 deletions src/tools/rust-analyzer/crates/rust-analyzer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,9 @@
pub mod cli;

mod capabilities;
mod command;
mod diagnostics;
mod diff;
mod discover;
mod dispatch;
mod flycheck;
mod hack_recover_crate_name;
mod line_index;
Expand All @@ -30,6 +27,7 @@ mod test_runner;
mod version;

mod handlers {
pub(crate) mod dispatch;
pub(crate) mod notification;
pub(crate) mod request;
}
Expand All @@ -51,7 +49,7 @@ mod integrated_benchmarks;
use serde::de::DeserializeOwned;

pub use crate::{
capabilities::server_capabilities, main_loop::main_loop, reload::ws_to_crate_graph,
lsp::capabilities::server_capabilities, main_loop::main_loop, reload::ws_to_crate_graph,
version::version,
};

Expand Down
2 changes: 2 additions & 0 deletions src/tools/rust-analyzer/crates/rust-analyzer/src/lsp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
use core::fmt;

pub mod ext;

pub(crate) mod capabilities;
pub(crate) mod from_proto;
pub(crate) mod semantic_tokens;
pub(crate) mod to_proto;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ use crate::{
config::Config,
diagnostics::{fetch_native_diagnostics, DiagnosticsGeneration, NativeDiagnosticsFetchKind},
discover::{DiscoverArgument, DiscoverCommand, DiscoverProjectMessage},
dispatch::{NotificationDispatcher, RequestDispatcher},
flycheck::{self, FlycheckMessage},
global_state::{file_id_to_url, url_to_file_id, FetchWorkspaceRequest, GlobalState},
hack_recover_crate_name,
handlers::dispatch::{NotificationDispatcher, RequestDispatcher},
lsp::{
from_proto, to_proto,
utils::{notification_is, Progress},
Expand Down Expand Up @@ -105,6 +105,7 @@ pub(crate) enum Task {
FetchWorkspace(ProjectWorkspaceProgress),
FetchBuildData(BuildDataProgress),
LoadProcMacros(ProcMacroProgress),
// FIXME: Remove this in favor of a more general QueuedTask, see `handle_did_save_text_document`
BuildDepsHaveChanged,
}

Expand Down

0 comments on commit 2e0f5f6

Please sign in to comment.