diff --git a/src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs b/src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs index c8029aed5..9c7134def 100644 --- a/src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs +++ b/src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs @@ -1380,6 +1380,12 @@ protected async Task HandleDocumentFormattingRequestAsync( DocumentFormattingParams formattingParams, RequestContext requestContext) { + if (this.editorSession.AnalysisService == null) + { + await requestContext.SendErrorAsync("Script analysis is not enabled in this session"); + return; + } + var result = await FormatAsync( formattingParams.TextDocument.Uri, formattingParams.options, @@ -1399,6 +1405,12 @@ protected async Task HandleDocumentRangeFormattingRequestAsync( DocumentRangeFormattingParams formattingParams, RequestContext requestContext) { + if (this.editorSession.AnalysisService == null) + { + await requestContext.SendErrorAsync("Script analysis is not enabled in this session"); + return; + } + var result = await FormatAsync( formattingParams.TextDocument.Uri, formattingParams.Options,