public async Task FindReferences(FilePath fileName, DocumentLocation location) { try { using (var monitor = LanguageClientProgressMonitors.GetSearchProgressMonitor()) { Location[] locations = await session.GetReferences( fileName, location.CreatePosition(), monitor.CancellationToken); if (locations == null) { monitor.ReportResults(Enumerable.Empty <SearchResult> ()); } else { List <SearchResult> references = ToSearchResults(locations).ToList(); monitor.ReportResults(references); } } } catch (OperationCanceledException) { LanguageClientLoggingService.Log("Find references was canceled."); } catch (Exception ex) { LanguageClientLoggingService.LogError("FindReferences error.", ex); } }
public async Task OpenDeclaration(FilePath fileName, DocumentLocation location) { ProgressMonitor monitor = null; try { using (monitor = LanguageClientProgressMonitors.GetOpenDeclarationProgressMonitor()) { Location[] locations = await session.FindDefinitions( fileName, location.CreatePosition(), monitor.CancellationToken); if (locations == null || locations.Length == 0) { monitor.ReportNoDeclarationFound(); } else if (locations.Length == 1) { OpenDeclaration(locations [0]); } else { ShowMultipleDeclarations(locations); } } } catch (OperationCanceledException) { LanguageClientLoggingService.Log("Go to declaration canceled."); if (monitor != null) { monitor.ReportGoToDeclarationCanceled(); } } catch (Exception ex) { LanguageClientLoggingService.LogError("OpenDeclaration error.", ex); } }
public async Task Rename(FilePath fileName, DocumentLocation location, string newName) { try { using (var monitor = LanguageClientProgressMonitors.GetSearchProgressMonitorForRename()) { WorkspaceEdit edit = await session.Rename( fileName, location.CreatePosition(), newName, monitor.CancellationToken); if (edit?.Changes == null) { monitor.ReportNothingToRename(); } else { WorkspaceEditHandler.ApplyChanges(edit); } } } catch (OperationCanceledException) { LanguageClientLoggingService.Log("Rename was canceled."); } catch (Exception ex) { LanguageClientLoggingService.LogError("Rename error.", ex); } }
public override async Task <TooltipItem> GetItem( TextEditor editor, DocumentContext ctx, int offset, CancellationToken token = default(CancellationToken)) { try { // DocumentContext is null so get the document information again. Document doc = IdeApp.Workbench.ActiveDocument; if (doc == null) { return(null); } LanguageClientSession session = LanguageClientServices.Workspace.GetSession(doc, false); if (session != null) { DocumentLocation location = editor.OffsetToLocation(offset); Hover result = await session.Hover(doc.FileName, location, token); return(CreateTooltipItem(editor, result)); } } catch (OperationCanceledException) { // Ignore. } catch (Exception ex) { LanguageClientLoggingService.LogError("TooltipProvider error.", ex); } return(null); }
public void OnDocumentOpened(LanguageClientDocumentContext context, string text) { try { context.Session.OpenDocument(context.FileName, text); } catch (Exception ex) { LanguageClientLoggingService.LogError("Error opening document.", ex); } }
public static void LogFault(this Task task) { task.ContinueWith(t => { if (t.IsFaulted) { LanguageClientLoggingService.LogError("Async operation failed", t.Exception); } }); }
void TextChanged(object sender, TextChangeEventArgs e) { try { documentVersion++; session.TextChanged(fileName, documentVersion, e, Editor) .LogFault(); } catch (Exception ex) { LanguageClientLoggingService.LogError("TextChanged error.", ex); } }
public void OnPublishDiagnostics(JToken arg) { try { Log(Methods.TextDocumentPublishDiagnosticsName, arg); var message = arg.ToObject <PublishDiagnosticParams> (); session.OnPublishDiagnostics(message); } catch (Exception ex) { LanguageClientLoggingService.LogError("OnPublishDiagnostics error.", ex); } }
public void OnWindowShowMessage(JToken arg) { try { Log(Methods.WindowShowMessageName, arg); var message = arg.ToObject <ShowMessageParams> (); LanguageClientMessageService.ShowMessage(message); } catch (Exception ex) { LanguageClientLoggingService.LogError("OnWindowShowMessage error.", ex); } }
public async Task FormatDocument(CancellationToken token = default(CancellationToken)) { try { var edits = await FormatDocumentInternal(token); editor.ApplyEdits(edits); } catch (OperationCanceledException) { // Ignore. } catch (Exception ex) { LanguageClientLoggingService.LogError("Format document error.", ex); } }
public object OnWindowShowRequestMessage(JToken arg) { try { Log(Methods.WindowShowMessageRequestName, arg); var message = arg.ToObject <ShowMessageRequestParams> (); return(LanguageClientMessageService.ShowMessage(message)); } catch (Exception ex) { LanguageClientLoggingService.LogError("OnWindowShowRequestMessage error.", ex); } return(null); }
internal static void EnsureInitialized() { if (provider != null) { return; } try { Initialize(); } catch (Exception ex) { LanguageClientLoggingService.LogError("Unable to initialize LanguageServerServices.", ex); } }
public void OnWorkspaceApplyEdit(JToken arg) { try { Log(Methods.WorkspaceApplyEditName, arg); var message = arg.ToObject <ApplyWorkspaceEditParams> (); Runtime.RunInMainThread(() => { WorkspaceEditHandler.ApplyChanges(message.Edit); }).LogFault(); } catch (Exception ex) { LanguageClientLoggingService.LogError("OnWorkspaceApplyEdit error.", ex); } }
public override Task <ParameterHintingResult> HandleParameterCompletionAsync( CodeCompletionContext completionContext, SignatureHelpTriggerInfo triggerInfo, CancellationToken token = default(CancellationToken)) { if (ShouldTriggerParameterCompletion(triggerInfo)) { try { return(GetParameterCompletionAsync(completionContext, token)); } catch (Exception ex) { LanguageClientLoggingService.LogError("HandleParameterCompletionAsync error.", ex); } } return(base.HandleParameterCompletionAsync(completionContext, triggerInfo, token)); }
void Dispose() { try { if (jsonRpc != null) { jsonRpc.Dispose(); jsonRpc = null; } if (connection != null) { connection.Dispose(); connection = null; } } catch (IOException ex) { // Ignore. LanguageClientLoggingService.LogError("JsonRpc.Dispose error.", ex); } }
public override Task <TooltipInformation> CreateTooltipInformation( bool smartWrap, CancellationToken cancelToken) { if (!session.IsCompletionResolveProvider || resolved) { return(base.CreateTooltipInformation(smartWrap, cancelToken)); } try { return(CreateTooltipWithResolvedCompletionItem(smartWrap, cancelToken)); } catch (OperationCanceledException) { // Ignore. return(base.CreateTooltipInformation(smartWrap, cancelToken)); } catch (Exception ex) { LanguageClientLoggingService.LogError("Unable to resolve completion item.", ex); return(base.CreateTooltipInformation(smartWrap, cancelToken)); } }
internal async Task <LanguageClientCodeAction[]> GetCodeActions(CancellationToken token) { try { Range range = Editor.GetCodeActionRange(); Diagnostic[] diagnostics = GetDiagnostics(range); LanguageServerProtocol.Command[] commands = await session.GetCodeActions(Editor.FileName, range, diagnostics, token); if (commands != null) { return(commands.Select(command => new LanguageClientCodeAction(session, command)) .ToArray()); } return(null); } catch (OperationCanceledException) { // Ignore. } catch (Exception ex) { LanguageClientLoggingService.LogError("GetCodeActions error.", ex); } return(null); }
async Task Initialize(FileDocumentController fileController, Properties status) { await base.Initialize(status); context = new LanguageClientDocumentContext(fileController); context.Session = LanguageClientServices.Workspace.GetSession(context); if (context.Session == null) { LanguageClientLoggingService.LogError(string.Format("Unable to get language client session for {0}", context.FileName)); context = null; return; } if (!context.Session.IsStarted) { context.Session.Started += SessionStarted; } }
async Task ShutdownSession(LanguageClientSession session) { try { LanguageClientLoggingService.Log("Shutting down language client[{0}]", session.Id); if (session.RootPath.IsNull) { sessions.Remove(session.Id); } else { solutionSessions.RemoveSession(session); } await session.Stop(); LanguageClientLoggingService.Log("Language client[{0}] shutdown.", session.Id); } catch (Exception ex) { LanguageClientLoggingService.LogError("Error shutting down language client.", ex); } }
public async override Task <ICompletionDataList> HandleCodeCompletionAsync( CodeCompletionContext completionContext, CompletionTriggerInfo triggerInfo, CancellationToken token = default(CancellationToken)) { if (Editor.EditMode == EditMode.TextLink) { return(null); } if (!session.IsCompletionProvider) { return(null); } try { WordAtPosition word = Editor.GetWordAtPosition(completionContext); if (!ShouldTriggerCompletion(word, completionContext, triggerInfo)) { return(null); } var completionList = await session.GetCompletionList(fileName, completionContext, this, token); if (!word.IsEmpty) { completionList.TriggerWordLength = word.Length; completionContext.TriggerLineOffset = word.StartColumn; } return(completionList); } catch (OperationCanceledException) { // Ignore. } catch (Exception ex) { LanguageClientLoggingService.LogError("HandleCodeCompletionAsync error.", ex); } return(null); }
public async Task RenameOccurrences(FilePath fileName, DocumentLocation location) { try { using (var monitor = LanguageClientProgressMonitors.GetSearchProgressMonitorForRename()) { Location[] locations = await session.GetReferences( fileName, location.CreatePosition(), monitor.CancellationToken); if (locations == null) { monitor.ReportNoReferencesFound(); return; } List <SearchResult> references = ToSearchResults(locations).ToList(); if (!references.Any()) { monitor.ReportNoReferencesFound(); } else if (AllSearchResultsExistInCurrentEditor(references)) { editor.StartTextEditorRename(references); } else { // Multiple files - cannot use text editor edit links. string oldName = GetSearchResultItemText(references [0]); string newName = RenameItemDialog.PromptForNewName(oldName); WorkspaceEditHandler.ApplyChanges(locations, newName); } } } catch (OperationCanceledException) { LanguageClientLoggingService.Log("Rename was canceled."); } catch (Exception ex) { LanguageClientLoggingService.LogError("RenameOccurrences error.", ex); } }
void LogError(string message, Exception ex) { string fullMessage = string.Format(GetLogMessageFormat(), Id, message); LanguageClientLoggingService.LogError(fullMessage, ex); }