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