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);
        }
示例#2
0
        bool TryGetSession(IContentType contentType, Project project, out LanguageClientSession session)
        {
            if (project?.ParentSolution != null)
            {
                return(solutionSessions.TryGetSession(contentType, project, out session));
            }

            return(sessions.TryGetValue(contentType.TypeName, out session));
        }
示例#3
0
        LanguageClientSession CreateSession(IContentType contentType, Project project)
        {
            ILanguageClient client = LanguageClientServices.ClientProvider.GetLanguageClient(contentType);

            var session = new LanguageClientSession(client, contentType, project.SafeGetParentSolutionBaseDirectory());

            session.Start();

            return(session);
        }
示例#4
0
        public void AddSession(LanguageClientSession session)
        {
            var solutionSessions = GetSolutionSession(session.RootPath);

            if (solutionSessions == null)
            {
                solutionSessions = new Dictionary <string, LanguageClientSession> ();
                sessions [session.RootPath.ToString()] = solutionSessions;
            }

            solutionSessions [session.Id] = session;
        }
示例#5
0
 public static void AddRange(
     this CompletionDataList completionList,
     LanguageClientSession session,
     TextEditorExtension textEditorExtension,
     IEnumerable <CompletionItem> items)
 {
     if (items?.Any() == true)
     {
         completionList.AddRange(
             items.Select(item => new LanguageClientCompletionData(session, textEditorExtension, item)));
     }
 }
示例#6
0
        public void RemoveSession(LanguageClientSession session)
        {
            var solutionSessions = GetSolutionSession(session.RootPath);

            if (solutionSessions != null)
            {
                solutionSessions.Remove(session.Id);
                if (solutionSessions.Keys.Count == 0)
                {
                    sessions.Remove(session.RootPath);
                }
            }
        }
示例#7
0
        protected override void Initialize()
        {
            var context = (LanguageClientDocumentContext)DocumentContext;

            fileName = context.FileName;

            session = context.Session;
            session.DiagnosticsPublished += OnDiagnostics;

            Editor.TextChanged += TextChanged;

            base.Initialize();
        }
示例#8
0
        public override void Dispose()
        {
            if (session != null)
            {
                session.DiagnosticsPublished -= OnDiagnostics;
                session = null;
            }

            if (Editor != null)
            {
                Editor.TextChanged -= TextChanged;
            }

            base.Dispose();
        }
        Task GetResults(
            Document activeDocument,
            ISearchResultCallback searchResultCallback,
            SearchPopupSearchPattern pattern,
            CancellationToken token)
        {
            LanguageClientSession session = LanguageClientServices.Workspace.GetSession(activeDocument, false);

            if (session?.IsWorkspaceSymbolProvider == true)
            {
                return(GetResults(session, searchResultCallback, pattern, token));
            }

            return(Task.CompletedTask);
        }
        async Task GetResults(
            LanguageClientSession session,
            ISearchResultCallback searchResultCallback,
            SearchPopupSearchPattern pattern,
            CancellationToken token)
        {
            SymbolInformation[] results = await session.GetWorkspaceSymbols(pattern.Pattern, token).ConfigureAwait(false);

            if (results != null && results.Length > 0)
            {
                foreach (var result in results)
                {
                    var searchResult = new WorkspaceSymbolSearchResult(pattern.Pattern, result);
                    searchResultCallback.ReportResult(searchResult);
                }
            }
        }
示例#11
0
        public bool TryGetSession(IContentType contentType, Project project, out LanguageClientSession session)
        {
            session = null;

            if (project?.ParentSolution == null)
            {
                return(false);
            }

            var solutionSessions = GetSolutionSession(project);

            if (solutionSessions == null)
            {
                return(false);
            }

            return(solutionSessions.TryGetValue(contentType.TypeName, out session));
        }
示例#12
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 LanguageClientCompletionData(
            LanguageClientSession session,
            TextEditorExtension textEditorExtension,
            CompletionItem item)
        {
            this.session   = session;
            CompletionItem = item;
            CompletionText = item.InsertText ?? item?.TextEdit?.NewText;

            if (CompletionText == null)
            {
                CompletionText = item.Label;
            }

            if (item.InsertTextFormat == InsertTextFormat.Snippet)
            {
                this.textEditorExtension = textEditorExtension;
                codeTemplate             = CodeTemplateFactory.ConvertToTemplate(CompletionText);
                CompletionText           = RemoveSnippet(CompletionText);
            }

            Icon = item.GetIcon();
        }
 public LanguageClientDeclarationFinder(TextEditor editor, LanguageClientSession session)
 {
     this.editor  = editor;
     this.session = session;
 }
示例#15
0
 public LanguageClientTarget(LanguageClientSession session)
 {
     this.session = session;
 }
示例#16
0
 IEnumerable <Document> GetOpenDocumentsForSession(LanguageClientSession session)
 {
     return(IdeApp.Workbench.Documents.Where(document => session.IsSupportedDocument(document)));
 }
示例#17
0
 public LanguageClientCodeAction(LanguageClientSession session, Command command)
 {
     this.session = session;
     this.command = command;
 }
示例#18
0
 bool IsAnyDocumentOpenForSession(LanguageClientSession session)
 {
     return(GetOpenDocumentsForSession(session).Any());
 }
 public DocumentFormatter(TextEditor editor, LanguageClientSession session)
 {
     this.editor  = editor;
     this.session = session;
 }
 public LanguageClientReferencesFinder(TextEditor editor, LanguageClientSession session)
 {
     this.editor  = editor;
     this.session = session;
 }