mirror of
https://github.com/denoland/deno.git
synced 2025-03-03 17:34:47 -05:00
fix(lsp): don't apply renames to remote modules (#22765)
This commit is contained in:
parent
8fda1b8a9c
commit
94cf92a98f
3 changed files with 73 additions and 0 deletions
|
@ -2115,8 +2115,13 @@ impl RenameLocations {
|
||||||
LspClientUrl,
|
LspClientUrl,
|
||||||
lsp::TextDocumentEdit,
|
lsp::TextDocumentEdit,
|
||||||
> = HashMap::new();
|
> = HashMap::new();
|
||||||
|
let mut includes_non_files = false;
|
||||||
for location in self.locations.iter() {
|
for location in self.locations.iter() {
|
||||||
let specifier = resolve_url(&location.document_span.file_name)?;
|
let specifier = resolve_url(&location.document_span.file_name)?;
|
||||||
|
if specifier.scheme() != "file" {
|
||||||
|
includes_non_files = true;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
let uri = language_server.url_map.normalize_specifier(&specifier)?;
|
let uri = language_server.url_map.normalize_specifier(&specifier)?;
|
||||||
let asset_or_doc = language_server.get_asset_or_document(&specifier)?;
|
let asset_or_doc = language_server.get_asset_or_document(&specifier)?;
|
||||||
|
|
||||||
|
@ -2146,6 +2151,10 @@ impl RenameLocations {
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if includes_non_files {
|
||||||
|
language_server.client.show_message(lsp::MessageType::WARNING, "The renamed symbol had references in non-file schemed modules. These have not been modified.");
|
||||||
|
}
|
||||||
|
|
||||||
Ok(lsp::WorkspaceEdit {
|
Ok(lsp::WorkspaceEdit {
|
||||||
change_annotations: None,
|
change_annotations: None,
|
||||||
changes: None,
|
changes: None,
|
||||||
|
|
|
@ -2461,6 +2461,69 @@ fn lsp_hover_deps_preserved_when_invalid_parse() {
|
||||||
client.shutdown();
|
client.shutdown();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Regression test for https://github.com/denoland/vscode_deno/issues/1068.
|
||||||
|
#[test]
|
||||||
|
fn lsp_rename_synbol_file_scheme_edits_only() {
|
||||||
|
let context = TestContextBuilder::new()
|
||||||
|
.use_http_server()
|
||||||
|
.use_temp_cwd()
|
||||||
|
.build();
|
||||||
|
let temp_dir = context.temp_dir();
|
||||||
|
let mut client = context.new_lsp_command().build();
|
||||||
|
client.initialize_default();
|
||||||
|
client.did_open(json!({
|
||||||
|
"textDocument": {
|
||||||
|
"uri": temp_dir.uri().join("file.ts").unwrap(),
|
||||||
|
"languageId": "typescript",
|
||||||
|
"version": 1,
|
||||||
|
"text": r#"
|
||||||
|
import { SEPARATOR } from "http://localhost:4545/subdir/exports.ts";
|
||||||
|
console.log(SEPARATOR);
|
||||||
|
"#,
|
||||||
|
},
|
||||||
|
}));
|
||||||
|
let res = client.write_request(
|
||||||
|
"textDocument/rename",
|
||||||
|
json!({
|
||||||
|
"textDocument": {
|
||||||
|
"uri": temp_dir.uri().join("file.ts").unwrap(),
|
||||||
|
},
|
||||||
|
"position": { "line": 1, "character": 17 },
|
||||||
|
"newName": "PATH_SEPARATOR",
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
res,
|
||||||
|
json!({
|
||||||
|
"documentChanges": [
|
||||||
|
{
|
||||||
|
"textDocument": {
|
||||||
|
"uri": temp_dir.uri().join("file.ts").unwrap(),
|
||||||
|
"version": 1,
|
||||||
|
},
|
||||||
|
"edits": [
|
||||||
|
{
|
||||||
|
"range": {
|
||||||
|
"start": { "line": 1, "character": 17 },
|
||||||
|
"end": { "line": 1, "character": 26 },
|
||||||
|
},
|
||||||
|
"newText": "PATH_SEPARATOR",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"range": {
|
||||||
|
"start": { "line": 2, "character": 20 },
|
||||||
|
"end": { "line": 2, "character": 29 },
|
||||||
|
},
|
||||||
|
"newText": "PATH_SEPARATOR",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}
|
||||||
|
],
|
||||||
|
})
|
||||||
|
);
|
||||||
|
client.shutdown();
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn lsp_hover_typescript_types() {
|
fn lsp_hover_typescript_types() {
|
||||||
let context = TestContextBuilder::new()
|
let context = TestContextBuilder::new()
|
||||||
|
|
1
tests/testdata/subdir/exports.ts
vendored
Normal file
1
tests/testdata/subdir/exports.ts
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
export const SEPARATOR = "/";
|
Loading…
Add table
Reference in a new issue