(content: string)
| 249 | * Formats the given ZModel content. |
| 250 | */ |
| 251 | export async function formatDocument(content: string) { |
| 252 | const services = createZModelServices().ZModelLanguage; |
| 253 | const langiumDocuments = services.shared.workspace.LangiumDocuments; |
| 254 | const document = langiumDocuments.createDocument(URI.parse('memory:///schema.zmodel'), content); |
| 255 | const formatter = services.lsp.Formatter as ZModelFormatter; |
| 256 | const identifier = { uri: document.uri.toString() }; |
| 257 | const options = formatter.getFormatOptions() ?? { |
| 258 | insertSpaces: true, |
| 259 | tabSize: 4, |
| 260 | }; |
| 261 | const edits = await formatter.formatDocument(document, { options, textDocument: identifier }); |
| 262 | return TextDocument.applyEdits(document.textDocument, edits); |
| 263 | } |
| 264 |
no test coverage detected