import type * as lspTypes from "vscode-languageserver-protocol" ; import { applyWorkspaceEdit } from "../applyWorkspaceEdit" ; import { wrapCommand } from "../novaUtils" ; import { rangeToLspRange } from "../lspNovaConversions" ; export function registerRename ( client ) { return nova . commands . register ( "apexskier.typescript.rename" , wrapCommand ( rename ) ) ; async function rename ( editor ) { editor . selectWordsContainingCursors ( ) ; const selectedRange = editor . selectedRange ; const selectedPosition = rangeToLspRange ( editor . document , selectedRange ) ?. start ; if ( ! selectedPosition ) { nova . workspace . showErrorMessage ( "Couldn't figure out what you've selected." ) ; return ; } const newName = await new Promise < string | null > ( ( resolve ) => { nova . workspace . showInputPalette ( "New name for symbol" , { placeholder : editor . selectedText , value : editor . selectedText } , resolve ) ; } ) ; if ( ! newName || newName == editor . selectedText ) { return ; } const params = { textDocument : { uri : editor . document . uri } , position : selectedPosition , newName , } ; const response = ( await client . sendRequest ( "textDocument/rename" , params ) ) as lspTypes . WorkspaceEdit | null ; if ( response == null ) { nova . workspace . showWarningMessage ( "Couldn't rename symbol." ) ; return ; } await applyWorkspaceEdit ( response ) ; await nova . workspace . openFile ( editor . document . uri ) ; editor . scrollToCursorPosition ( ) ; } }