Пример #1
0
        public async Task<List<string>> AutoComplete(Request req)
        {
            var document = _workspace.AddDocument(_project.Id, "AdhocDocument", SourceText.From(req.Buffer));
            var sourceText = await document.GetTextAsync();
            var position = sourceText.Lines.GetPosition(new LinePosition(req.Line, req.Column));
            var model = await document.GetSemanticModelAsync();

            var symbols = Recommender.GetRecommendedSymbolsAtPosition(model, position, _workspace);

            return symbols.Select(s => s.Name).ToList();
        }
Пример #2
0
        public async Task<string> Rename(Request req)
        {
            var document = _workspace.AddDocument(_project.Id, "AdhocDocument", SourceText.From(req.Buffer));
            var sourceText = await document.GetTextAsync();
            var symbolPosition = sourceText.Lines.GetPosition(new LinePosition(req.Line, req.Column));
            var symbol = await SymbolFinder.FindSymbolAtPositionAsync(document, symbolPosition);

            if (symbol != null)
            {
                var newSolution = await Renamer.RenameSymbolAsync(_workspace.CurrentSolution, symbol, req.RenameTo, _workspace.Options);

                var solutionChanges = newSolution.GetChanges(_workspace.CurrentSolution);

                var projectChanges = solutionChanges.GetProjectChanges();
                var documentChanges = projectChanges.First().GetChangedDocuments();
                var changedDocument = newSolution.GetDocument(documentChanges.First());

                var newSourceText = await changedDocument.GetTextAsync();

                return newSourceText.ToString();
            }

            return null;
        }