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 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 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 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);
            }
        }
Exemplo n.º 5
0
 public void OnDocumentOpened(LanguageClientDocumentContext context, string text)
 {
     try {
         context.Session.OpenDocument(context.FileName, text);
     } catch (Exception ex) {
         LanguageClientLoggingService.LogError("Error opening document.", ex);
     }
 }
Exemplo n.º 6
0
 public static void LogFault(this Task task)
 {
     task.ContinueWith(t => {
         if (t.IsFaulted)
         {
             LanguageClientLoggingService.LogError("Async operation failed", t.Exception);
         }
     });
 }
Exemplo n.º 7
0
 void TextChanged(object sender, TextChangeEventArgs e)
 {
     try {
         documentVersion++;
         session.TextChanged(fileName, documentVersion, e, Editor)
         .LogFault();
     } catch (Exception ex) {
         LanguageClientLoggingService.LogError("TextChanged error.", ex);
     }
 }
Exemplo n.º 8
0
        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);
            }
        }
Exemplo n.º 9
0
        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);
            }
        }
Exemplo n.º 11
0
        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);
        }
Exemplo n.º 12
0
        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);
            }
        }
Exemplo n.º 13
0
        internal static void EnsureInitialized()
        {
            if (provider != null)
            {
                return;
            }

            try {
                Initialize();
            } catch (Exception ex) {
                LanguageClientLoggingService.LogError("Unable to initialize LanguageServerServices.", ex);
            }
        }
Exemplo n.º 14
0
 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));
 }
Exemplo n.º 15
0
        public void LogClientsFound()
        {
            if (!clients.Any())
            {
                LanguageClientLoggingService.Log("No LanguageClients found.");
            }

            LanguageClientLoggingService.Log("LanguageClients:");

            foreach (KeyValuePair <string, ILanguageClient> mapping in contentTypeMappings)
            {
                LanguageClientLoggingService.Log(
                    "    Name: '{0}', ContentType: '{1}'",
                    mapping.Value.Name,
                    mapping.Key);
            }
        }
 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);
     }
 }
        static void ApplyChanges(string fileName, IEnumerable <TextEdit> edits)
        {
            bool          open     = false;
            ITextDocument document = TextFileProvider.Instance.GetTextEditorData(fileName, out open);

            if (document != null)
            {
                document.ApplyEdits(edits);
                if (!open)
                {
                    document.Save();
                }
            }
            else
            {
                LanguageClientLoggingService.Log("Unable to find text editor for file: '{0}'", fileName);
            }
        }
        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));
            }
        }
Exemplo n.º 19
0
        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);
        }
Exemplo n.º 20
0
        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;
            }
        }
Exemplo n.º 21
0
        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);
            }
        }
Exemplo n.º 22
0
        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);
            }
        }
Exemplo n.º 24
0
 void Log(string message, JToken arg)
 {
     LanguageClientLoggingService.Log("{0}\n{1}\n", message, arg);
 }
        void LogError(string message, Exception ex)
        {
            string fullMessage = string.Format(GetLogMessageFormat(), Id, message);

            LanguageClientLoggingService.LogError(fullMessage, ex);
        }
        void Log(string message)
        {
            string fullMessage = string.Format(GetLogMessageFormat(), Id, message);

            LanguageClientLoggingService.Log(fullMessage);
        }