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

Function applyChangesToFile

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

Source from the content-addressed store, hash-verified

155}
156
157async 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
200async function doRename(
201 view: EditorView,

Callers 1

doRenameFunction · 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