summaryrefslogtreecommitdiff
path: root/cli/lsp/analysis.rs
diff options
context:
space:
mode:
Diffstat (limited to 'cli/lsp/analysis.rs')
-rw-r--r--cli/lsp/analysis.rs46
1 files changed, 24 insertions, 22 deletions
diff --git a/cli/lsp/analysis.rs b/cli/lsp/analysis.rs
index c4b9f0a86..bce89cc35 100644
--- a/cli/lsp/analysis.rs
+++ b/cli/lsp/analysis.rs
@@ -184,28 +184,30 @@ pub fn fix_ts_import_changes(
for change in changes {
let mut text_changes = Vec::new();
for text_change in &change.text_changes {
- if let Some(captures) =
- IMPORT_SPECIFIER_RE.captures(&text_change.new_text)
- {
- let specifier = captures
- .get(1)
- .ok_or_else(|| anyhow!("Missing capture."))?
- .as_str();
- if let Some(new_specifier) =
- check_specifier(specifier, referrer, documents)
- {
- let new_text =
- text_change.new_text.replace(specifier, &new_specifier);
- text_changes.push(tsc::TextChange {
- span: text_change.span.clone(),
- new_text,
- });
- } else {
- text_changes.push(text_change.clone());
- }
- } else {
- text_changes.push(text_change.clone());
- }
+ let lines = text_change.new_text.split('\n');
+
+ let new_lines: Vec<String> = lines
+ .map(|line| {
+ // This assumes that there's only one import per line.
+ if let Some(captures) = IMPORT_SPECIFIER_RE.captures(line) {
+ let specifier = captures.get(1).unwrap().as_str();
+ if let Some(new_specifier) =
+ check_specifier(specifier, referrer, documents)
+ {
+ line.replace(specifier, &new_specifier)
+ } else {
+ line.to_string()
+ }
+ } else {
+ line.to_string()
+ }
+ })
+ .collect();
+
+ text_changes.push(tsc::TextChange {
+ span: text_change.span.clone(),
+ new_text: new_lines.join("\n").to_string(),
+ });
}
r.push(tsc::FileTextChanges {
file_name: change.file_name.clone(),