MCPcopy Create free account
hub / github.com/angular/angular / onRenameRequest

Function onRenameRequest

vscode-ng-language-service/server/src/handlers/rename.ts:13–58  ·  view source on GitHub ↗
(
  session: Session,
  params: lsp.RenameParams,
)

Source from the content-addressed store, hash-verified

11import {filePathToUri, lspPositionToTsPosition, tsTextSpanToLspRange} from '../utils';
12
13export function onRenameRequest(
14 session: Session,
15 params: lsp.RenameParams,
16): lsp.WorkspaceEdit | null {
17 const lsInfo = session.getLSAndScriptInfo(params.textDocument);
18 if (lsInfo === null) {
19 return null;
20 }
21 const {languageService, scriptInfo} = lsInfo;
22 const project = session.getDefaultProjectForScriptInfo(scriptInfo);
23 if (project === null || session.renameDisabledProjects.has(project)) {
24 return null;
25 }
26
27 const offset = lspPositionToTsPosition(scriptInfo, params.position);
28 const renameLocations = languageService.findRenameLocations(
29 scriptInfo.fileName,
30 offset,
31 /*findInStrings*/ false,
32 /*findInComments*/ false,
33 );
34 if (renameLocations === undefined) {
35 return null;
36 }
37
38 const changes = renameLocations.reduce(
39 (changes, location) => {
40 let uri: lsp.URI = filePathToUri(location.fileName);
41 if (changes[uri] === undefined) {
42 changes[uri] = [];
43 }
44 const fileEdits = changes[uri];
45
46 const lsInfo = session.getLSAndScriptInfo(location.fileName);
47 if (lsInfo === null) {
48 return changes;
49 }
50 const range = tsTextSpanToLspRange(lsInfo.scriptInfo, location.textSpan);
51 fileEdits.push({range, newText: params.newName});
52 return changes;
53 },
54 {} as {[uri: string]: lsp.TextEdit[]},
55 );
56
57 return {changes};
58}
59
60export function onPrepareRename(
61 session: Session,

Callers 1

addProtocolHandlersMethod · 0.90

Calls 9

lspPositionToTsPositionFunction · 0.90
filePathToUriFunction · 0.90
tsTextSpanToLspRangeFunction · 0.90
getLSAndScriptInfoMethod · 0.80
reduceMethod · 0.80
hasMethod · 0.65
findRenameLocationsMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected