(
workspace: AcodeWorkspace,
uri: string,
lspChanges: LspChange[],
mapping: { mapPosition: (uri: string, pos: lsp.Position) => number },
)
| 155 | } |
| 156 | |
| 157 | async function applyChangesToFile( |
| 158 | workspace: AcodeWorkspace, |
| 159 | uri: string, |
| 160 | lspChanges: LspChange[], |
| 161 | mapping: { mapPosition: (uri: string, pos: lsp.Position) => number }, |
| 162 | ): Promise<boolean> { |
| 163 | const file = workspace.getFile(uri); |
| 164 | |
| 165 | if (file) { |
| 166 | const view = file.getView(); |
| 167 | if (view) { |
| 168 | view.dispatch({ |
| 169 | changes: lspChanges.map((change) => ({ |
| 170 | from: mapping.mapPosition(uri, change.range.start), |
| 171 | to: mapping.mapPosition(uri, change.range.end), |
| 172 | insert: change.newText, |
| 173 | })), |
| 174 | userEvent: "rename", |
| 175 | }); |
| 176 | return true; |
| 177 | } |
| 178 | } |
| 179 | |
| 180 | const displayedView = await workspace.displayFile(uri); |
| 181 | if (!displayedView?.state?.doc) { |
| 182 | addLspLogFor(workspace.client, "warn", `Rename could not open file: ${uri}`); |
| 183 | console.warn(`[LSP:Rename] Could not open file: ${uri}`); |
| 184 | return false; |
| 185 | } |
| 186 | |
| 187 | const doc = displayedView.state.doc; |
| 188 | displayedView.dispatch({ |
| 189 | changes: lspChanges.map((change) => ({ |
| 190 | from: lspPositionToOffset(doc, change.range.start), |
| 191 | to: lspPositionToOffset(doc, change.range.end), |
| 192 | insert: change.newText, |
| 193 | })), |
| 194 | userEvent: "rename", |
| 195 | }); |
| 196 | |
| 197 | return true; |
| 198 | } |
| 199 | |
| 200 | async function doRename( |
| 201 | view: EditorView, |
no test coverage detected