import type * as lspTypes from "vscode-languageserver-protocol" ; import { applyLSPEdits } from "../applyLSPEdits" ; import { wrapCommand } from "../novaUtils" ; export function registerFormatDocument ( client ) { return nova . commands . register ( "apexskier.typescript.commands.formatDocument" , wrapCommand ( formatDocument ) ) ; async function formatDocument ( editor ) ; async function formatDocument ( workspace , editor ) ; async function formatDocument ( editorOrWorkspace , maybeEditor ? ) { const editor = maybeEditor ?? ( editorOrWorkspace as TextEditor ) ; const documentFormatting = { textDocument : { uri : editor . document . uri } , options : { insertSpaces : editor . softTabs , tabSize : editor . tabLength , } , } ; const changes = ( await client . sendRequest ( "textDocument/formatting" , documentFormatting ) ) as null | Array < lspTypes . TextEdit > ; if ( ! changes ) { return ; } applyLSPEdits ( editor , changes ) ; } }