/// <summary> /// Checks if there are any active documents open -- if not tries to open/close a magic document to trigger LSP activation /// </summary> /// <returns></returns> private async Task TryTriggerLspActivationAsync() { Log.Debug($"{nameof(TryTriggerLspActivationAsync)} starting..."); var hasActiveEditor = false; DTE dte = null; try { await JoinableTaskFactory.SwitchToMainThreadAsync(); dte = GetGlobalService(typeof(DTE)) as DTE; hasActiveEditor = dte?.Documents?.Count > 0; } catch (Exception ex) { Log.Warning(ex, nameof(TryTriggerLspActivationAsync)); } bool?languageClientActivatorResult = null; if (!hasActiveEditor) { languageClientActivatorResult = await LanguageClientActivator.ActivateAsync(dte); } Log.Debug($"{nameof(TryTriggerLspActivationAsync)} HasActiveEditor={hasActiveEditor} LanguageClientActivatorResult={languageClientActivatorResult}"); await System.Threading.Tasks.Task.CompletedTask; }
public static async System.Threading.Tasks.Task TryTriggerLspActivationAsync(ILogger log) { log.Debug($"{nameof(TryTriggerLspActivationAsync)} starting..."); var hasActiveEditor = false; EnvDTE.DTE dte = null; try { dte = Package.GetGlobalService(typeof(EnvDTE.DTE)) as EnvDTE.DTE; hasActiveEditor = dte?.Documents?.Count > 0; } catch (Exception ex) { log.Warning(ex, nameof(TryTriggerLspActivationAsync)); } bool?languageClientActivatorResult = null; if (!hasActiveEditor) { languageClientActivatorResult = await LanguageClientActivator.ActivateAsync(dte); } log.Debug($"{nameof(TryTriggerLspActivationAsync)} HasActiveEditor={hasActiveEditor} LanguageClientActivatorResult={languageClientActivatorResult}"); await System.Threading.Tasks.Task.CompletedTask; }