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 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);
            }
        }
示例#4
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);
            }
        }
        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);
            }
        }
示例#6
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);
            }
        }
        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);
            }
        }
示例#8
0
 void Log(string message, JToken arg)
 {
     LanguageClientLoggingService.Log("{0}\n{1}\n", message, arg);
 }
        void Log(string message)
        {
            string fullMessage = string.Format(GetLogMessageFormat(), Id, message);

            LanguageClientLoggingService.Log(fullMessage);
        }