mirror of
https://github.com/denoland/deno.git
synced 2025-09-27 04:39:10 +00:00
fix(lsp): fix import specifiers in file rename changes (#30458)
Some checks are pending
ci / test release macos-x86_64 (push) Blocked by required conditions
ci / test debug windows-x86_64 (push) Blocked by required conditions
ci / test release windows-x86_64 (push) Blocked by required conditions
ci / build libs (push) Blocked by required conditions
ci / pre-build (push) Waiting to run
ci / test debug linux-aarch64 (push) Blocked by required conditions
ci / test release linux-aarch64 (push) Blocked by required conditions
ci / test debug macos-aarch64 (push) Blocked by required conditions
ci / test release macos-aarch64 (push) Blocked by required conditions
ci / bench release linux-x86_64 (push) Blocked by required conditions
ci / lint debug linux-x86_64 (push) Blocked by required conditions
ci / lint debug macos-x86_64 (push) Blocked by required conditions
ci / lint debug windows-x86_64 (push) Blocked by required conditions
ci / test debug linux-x86_64 (push) Blocked by required conditions
ci / test release linux-x86_64 (push) Blocked by required conditions
ci / test debug macos-x86_64 (push) Blocked by required conditions
ci / publish canary (push) Blocked by required conditions
Some checks are pending
ci / test release macos-x86_64 (push) Blocked by required conditions
ci / test debug windows-x86_64 (push) Blocked by required conditions
ci / test release windows-x86_64 (push) Blocked by required conditions
ci / build libs (push) Blocked by required conditions
ci / pre-build (push) Waiting to run
ci / test debug linux-aarch64 (push) Blocked by required conditions
ci / test release linux-aarch64 (push) Blocked by required conditions
ci / test debug macos-aarch64 (push) Blocked by required conditions
ci / test release macos-aarch64 (push) Blocked by required conditions
ci / bench release linux-x86_64 (push) Blocked by required conditions
ci / lint debug linux-x86_64 (push) Blocked by required conditions
ci / lint debug macos-x86_64 (push) Blocked by required conditions
ci / lint debug windows-x86_64 (push) Blocked by required conditions
ci / test debug linux-x86_64 (push) Blocked by required conditions
ci / test release linux-x86_64 (push) Blocked by required conditions
ci / test debug macos-x86_64 (push) Blocked by required conditions
ci / publish canary (push) Blocked by required conditions
This commit is contained in:
parent
dabf9c79b3
commit
efdcdf82c9
3 changed files with 104 additions and 2 deletions
|
@ -5,6 +5,7 @@ use std::cmp::Ordering;
|
|||
use std::collections::HashMap;
|
||||
use std::collections::HashSet;
|
||||
use std::path::Path;
|
||||
use std::str::FromStr;
|
||||
use std::sync::Arc;
|
||||
|
||||
use deno_ast::SourceRange;
|
||||
|
@ -55,6 +56,7 @@ use super::language_server;
|
|||
use super::resolver::LspResolver;
|
||||
use super::tsc;
|
||||
use crate::args::jsr_url;
|
||||
use crate::lsp::urls::uri_to_url;
|
||||
use crate::tools::lint::CliLinter;
|
||||
use crate::util::path::relative_specifier;
|
||||
|
||||
|
@ -757,6 +759,43 @@ pub fn fix_ts_import_changes(
|
|||
Ok(r)
|
||||
}
|
||||
|
||||
pub fn fix_ts_import_changes_for_file_rename(
|
||||
changes: Vec<tsc::FileTextChanges>,
|
||||
new_uri: &str,
|
||||
module: &DocumentModule,
|
||||
language_server: &language_server::Inner,
|
||||
token: &CancellationToken,
|
||||
) -> Result<Vec<tsc::FileTextChanges>, AnyError> {
|
||||
let Ok(new_uri) = Uri::from_str(new_uri) else {
|
||||
return Ok(Vec::new());
|
||||
};
|
||||
if !new_uri.scheme().is_some_and(|s| s.eq_lowercase("file")) {
|
||||
return Ok(Vec::new());
|
||||
}
|
||||
let new_url = uri_to_url(&new_uri);
|
||||
let mut r = Vec::with_capacity(changes.len());
|
||||
for mut change in changes {
|
||||
if token.is_cancelled() {
|
||||
return Err(anyhow!("request cancelled"));
|
||||
}
|
||||
let Ok(target_specifier) = resolve_url(&change.file_name) else {
|
||||
continue;
|
||||
};
|
||||
let import_mapper = language_server.get_ts_response_import_mapper(module);
|
||||
for text_change in &mut change.text_changes {
|
||||
if let Some(new_specifier) = import_mapper
|
||||
.check_specifier(&new_url, &target_specifier)
|
||||
.or_else(|| relative_specifier(&target_specifier, &new_url))
|
||||
.filter(|s| !s.contains("/node_modules/"))
|
||||
{
|
||||
text_change.new_text = new_specifier;
|
||||
}
|
||||
}
|
||||
r.push(change);
|
||||
}
|
||||
Ok(r)
|
||||
}
|
||||
|
||||
/// Fix tsc import code actions so that the module specifier is correct for
|
||||
/// resolution by Deno (includes the extension).
|
||||
fn fix_ts_import_action<'a>(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue