MCPcopy Create free account
hub / github.com/Acode-Foundation/Acode / applyChangesToFile

Function applyChangesToFile

src/cm/lsp/codeActions.ts:155–197  ·  view source on GitHub ↗
(
	workspace: AcodeWorkspace,
	uri: string,
	changes: LspChange[],
	mapping: { mapPosition: (uri: string, pos: Position) => number },
)

Source from the content-addressed store, hash-verified

153}
154
155async 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
199async function applyWorkspaceEdit(
200 view: EditorView,

Callers 1

applyWorkspaceEditFunction · 0.70

Calls 5

addLspLogForFunction · 0.90
getViewMethod · 0.80
displayFileMethod · 0.80
lspPositionToOffsetFunction · 0.70
getFileMethod · 0.65

Tested by

no test coverage detected