private void AddKeywords(SemanticModel model, int position, bool wantKind, string wordToComplete)
        {
            var context = CSharpSyntaxContext.CreateContext(_workspace, model, position, CancellationToken.None);
            var keywordHandler = new KeywordContextHandler();
            var keywords = keywordHandler.Get(context, model, position);

            foreach (var keyword in keywords.Where(k => k.IsValidCompletionFor(wordToComplete)))
            {
                _completions.Add(new AutoCompleteResponse
                {
                    CompletionText = keyword,
                    DisplayText = keyword,
                    Snippet = keyword,
                    Kind = wantKind ? "Keyword" : null
                });
            }
        }
示例#2
0
        private void AddKeywords(SemanticModel model, int position, bool wantKind, string wordToComplete)
        {
            var context        = CSharpSyntaxContext.CreateContext(_workspace, model, position);
            var keywordHandler = new KeywordContextHandler();
            var keywords       = keywordHandler.Get(context, model, position);

            foreach (var keyword in keywords.Where(k => k.IsValidCompletionFor(wordToComplete)))
            {
                _completions.Add(new AutoCompleteResponse
                {
                    CompletionText = keyword,
                    DisplayText    = keyword,
                    Snippet        = keyword,
                    Kind           = wantKind ? "Keyword" : null
                });
            }
        }
        public async Task <IActionResult> AutoComplete([FromBody] AutoCompleteRequest request)
        {
            _workspace.EnsureBufferUpdated(request);

            var completions = new List <AutoCompleteResponse>();

            var documents = _workspace.GetDocuments(request.FileName);

            foreach (var document in documents)
            {
                var sourceText = await document.GetTextAsync();

                var position = sourceText.Lines.GetPosition(new LinePosition(request.Line - 1, request.Column - 1));
                var model    = await document.GetSemanticModelAsync();

                var symbols        = Recommender.GetRecommendedSymbolsAtPosition(model, position, _workspace);
                var context        = CSharpSyntaxContext.CreateContext(_workspace, model, position);
                var keywordHandler = new KeywordContextHandler();
                var keywords       = keywordHandler.Get(context, model, position);

                foreach (var keyword in keywords)
                {
                    completions.Add(new AutoCompleteResponse
                    {
                        CompletionText = keyword,
                        DisplayText    = keyword,
                        Snippet        = keyword
                    });
                }

                foreach (var symbol in symbols.Where(s => s.Name.StartsWith(request.WordToComplete, StringComparison.OrdinalIgnoreCase)))
                {
                    if (request.WantSnippet)
                    {
                        completions.AddRange(MakeSnippetedResponses(request, symbol));
                    }
                    else
                    {
                        completions.Add(MakeAutoCompleteResponse(request, symbol));
                    }
                }
            }

            return(new ObjectResult(completions));
        }