mirror of
https://github.com/denoland/deno.git
synced 2024-11-21 15:04:11 -05:00
fix(lsp): don't apply renames to remote modules (#22765)
This commit is contained in:
parent
0fdb33c3aa
commit
8df47882c9
3 changed files with 73 additions and 0 deletions
|
@ -2115,8 +2115,13 @@ impl RenameLocations {
|
|||
LspClientUrl,
|
||||
lsp::TextDocumentEdit,
|
||||
> = HashMap::new();
|
||||
let mut includes_non_files = false;
|
||||
for location in self.locations.iter() {
|
||||
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 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 {
|
||||
change_annotations: None,
|
||||
changes: None,
|
||||
|
|
|
@ -2461,6 +2461,69 @@ fn lsp_hover_deps_preserved_when_invalid_parse() {
|
|||
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]
|
||||
fn lsp_hover_typescript_types() {
|
||||
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…
Reference in a new issue