Helper: given PHP source with a cursor marker `/*|*/`, run the inline variable action and return the resulting edits (if offered).
(php: &str)
| 785 | /// Helper: given PHP source with a cursor marker `/*|*/`, run the |
| 786 | /// inline variable action and return the resulting edits (if offered). |
| 787 | fn run_inline(php: &str) -> Option<Vec<TextEdit>> { |
| 788 | let marker = "/*|*/"; |
| 789 | let marker_pos = php.find(marker)?; |
| 790 | let content = php.replace(marker, ""); |
| 791 | |
| 792 | let uri = "file:///test.php"; |
| 793 | let cursor_offset = marker_pos; |
| 794 | let position = offset_to_position(&content, cursor_offset); |
| 795 | let params = CodeActionParams { |
| 796 | text_document: TextDocumentIdentifier { |
| 797 | uri: Url::parse(uri).unwrap(), |
| 798 | }, |
| 799 | range: Range { |
| 800 | start: position, |
| 801 | end: position, |
| 802 | }, |
| 803 | context: CodeActionContext { |
| 804 | diagnostics: vec![], |
| 805 | only: None, |
| 806 | trigger_kind: None, |
| 807 | }, |
| 808 | work_done_progress_params: WorkDoneProgressParams { |
| 809 | work_done_token: None, |
| 810 | }, |
| 811 | partial_result_params: PartialResultParams { |
| 812 | partial_result_token: None, |
| 813 | }, |
| 814 | }; |
| 815 | |
| 816 | let backend = Backend::new_test(); |
| 817 | // Store file content so resolve_code_action can retrieve it. |
| 818 | backend |
| 819 | .open_files |
| 820 | .write() |
| 821 | .insert(uri.to_string(), std::sync::Arc::new(content.clone())); |
| 822 | |
| 823 | let mut actions = Vec::new(); |
| 824 | backend.collect_inline_variable_actions(uri, &content, ¶ms, &mut actions); |
| 825 | |
| 826 | if actions.is_empty() { |
| 827 | return None; |
| 828 | } |
| 829 | |
| 830 | let action = match &actions[0] { |
| 831 | CodeActionOrCommand::CodeAction(a) => a.clone(), |
| 832 | _ => return None, |
| 833 | }; |
| 834 | |
| 835 | // Phase 1 should have data but no edit. |
| 836 | assert!(action.edit.is_none(), "Phase 1 should not compute edits"); |
| 837 | assert!(action.data.is_some(), "Phase 1 should attach resolve data"); |
| 838 | |
| 839 | // Phase 2: resolve the action to get the workspace edit. |
| 840 | let (resolved, _) = backend.resolve_code_action(action); |
| 841 | let edit = resolved.edit.as_ref()?; |
| 842 | let changes = edit.changes.as_ref()?; |
| 843 | let parsed_uri = Url::parse(uri).unwrap(); |
| 844 | let edits = changes.get(&parsed_uri)?; |