private onRenameRequest()

in server/src/session.ts [832:867]


  private onRenameRequest(params: lsp.RenameParams): lsp.WorkspaceEdit|null {
    const lsInfo = this.getLSAndScriptInfo(params.textDocument);
    if (lsInfo === null) {
      return null;
    }
    const {languageService, scriptInfo} = lsInfo;
    const project = this.getDefaultProjectForScriptInfo(scriptInfo);
    if (project === null || this.renameDisabledProjects.has(project)) {
      return null;
    }

    const offset = lspPositionToTsPosition(scriptInfo, params.position);
    const renameLocations = languageService.findRenameLocations(
        scriptInfo.fileName, offset, /*findInStrings*/ false, /*findInComments*/ false);
    if (renameLocations === undefined) {
      return null;
    }

    const changes = renameLocations.reduce((changes, location) => {
      let uri: lsp.URI = filePathToUri(location.fileName);
      if (changes[uri] === undefined) {
        changes[uri] = [];
      }
      const fileEdits = changes[uri];

      const lsInfo = this.getLSAndScriptInfo(location.fileName);
      if (lsInfo === null) {
        return changes;
      }
      const range = tsTextSpanToLspRange(lsInfo.scriptInfo, location.textSpan);
      fileEdits.push({range, newText: params.newName});
      return changes;
    }, {} as {[uri: string]: lsp.TextEdit[]});

    return {changes};
  }