I’m developing a VSCode extension to format files via the context menu. When my option is clicked, I execute the vscode.executeFormatDocumentProvider
command to get the edits without opening the file in editor.
When I try to format a file without opening any other file of the same language, the edit array comes empty. However, if I open another file of the same language and then try to format my file, it returns the edits correctly. I tried setting a timeout after the openTextFile
method and before the vscode.executeFormatDocumentProvider
command and it works.
I supose it happens because the openTextFile
doesn’t await the language service to start. I also tried using the onDidChangeDiagnostics
event to await the language service startup, but if it has already started, the event is not triggered.
Is there any way to await the language service’s startup when I call the openTextFile
method, or maybe a different solution for my problem?
Vinícius Iancovski is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.