示例#1
0
        public IEnumerable<ICompletionData> GetCompletions(string editorText)
        {
            int cursorOffset = editorText.IndexOf("$", StringComparison.Ordinal);
            if(cursorOffset == -1)
                throw new ArgumentException("Editor text should contain a $");

            TextLocation cursorPosition = TestHelpers.GetLineAndColumnFromIndex(editorText, cursorOffset);
            string partialWord = GetPartialWord(editorText);
            editorText = editorText.Replace("$", "");

            var project = new FakeProject();
            project.AddFile(editorText);
            _solution.Projects.Add(project);
            var provider = new AutoCompleteHandler(new BufferParser(_solution), new Logger());
            var request = new AutoCompleteRequest
                {
                    FileName = "myfile",
                    WordToComplete = partialWord,
                    Buffer = editorText,
                    Line = cursorPosition.Line,
                    Column = cursorPosition.Column,
                };

            return provider.CreateProvider(request);
        }
        public IEnumerable<CompletionData> GetCompletions(string editorText, bool includeImportableTypes)
        {
            int cursorOffset = editorText.IndexOf("$", StringComparison.Ordinal);
            if(cursorOffset == -1)
                throw new ArgumentException("Editor text should contain a $");

            TextLocation cursorPosition = TestHelpers.GetLineAndColumnFromIndex(editorText, cursorOffset);
            string partialWord = GetPartialWord(editorText);
            editorText = editorText.Replace("$", "");

            var project = new FakeProject();
            project.AddFile(editorText);
            _solution.Projects.Add(project);
            var provider = new AutoCompleteHandler(_solution, new BufferParser(_solution), new Logger(Verbosity.Quiet));
            var request = new AutoCompleteRequest
                {
                    FileName = "myfile",
                    WordToComplete = partialWord,
                    Buffer = editorText,
                    Line = cursorPosition.Line,
                    Column = cursorPosition.Column,
                    WantDocumentationForEveryCompletionResult = false,
                    WantImportableTypes = includeImportableTypes,
                    WantMethodHeader = true,
                    WantReturnType = true,
                    WantSnippet = true
                };

            return provider.CreateProvider(request);
        }
示例#3
0
        public IEnumerable<ICompletionData> CreateProvider(AutoCompleteRequest request)
        {
            var editorText = request.Buffer ?? "";
            var filename = request.FileName;
            var partialWord = request.WordToComplete ?? "";

            var doc = new ReadOnlyDocument(editorText);
            var loc = new TextLocation(request.Line, request.Column - partialWord.Length);
            int cursorPosition = doc.GetOffset(loc);
            //Ensure cursorPosition only equals 0 when editorText is empty, so line 1,column 1
            //completion will work correctly.
            cursorPosition = Math.Max(cursorPosition, 1);
            cursorPosition = Math.Min(cursorPosition, editorText.Length);

            var res = _parser.ParsedContent(editorText, filename);
            var rctx = res.UnresolvedFile.GetTypeResolveContext(res.Compilation, loc);

            ICompletionContextProvider contextProvider = new DefaultCompletionContextProvider(doc, res.UnresolvedFile);
            var engine = new CSharpCompletionEngine(doc, contextProvider, new CompletionDataFactory(partialWord), res.ProjectContent, rctx)
                {
                    EolMarker = Environment.NewLine
                };

            _logger.Debug("Getting Completion Data");

            IEnumerable<ICompletionData> data = engine.GetCompletionData(cursorPosition, true);
            _logger.Debug("Got Completion Data");

            return data.Where(d => d != null && d.DisplayText.IsValidCompletionFor(partialWord))
                       .FlattenOverloads()
                       .RemoveDupes()
                       .OrderBy(d => d.DisplayText);
        }
 public CompletionDataFactory(IProject project, string partialWord, bool instantiating, AutoCompleteRequest request)
 {
     _project = project;
     _partialWord = partialWord;
     _instantiating = instantiating;
     _wantDocumentation = request.WantDocumentationForEveryCompletionResult;
     _wantMethodHeader = request.WantMethodHeader;
     _wantSnippet = request.WantSnippet;
     _wantReturnType = request.WantReturnType;
 }
示例#5
0
        public IEnumerable <CompletionData> CreateProvider(AutoCompleteRequest request)
        {
            request.Column = request.Column - request.WordToComplete.Length;
            var completionContext = new BufferContext(request, _parser);

            var partialWord = request.WordToComplete;

            var project = _solution.ProjectContainingFile(request.FileName);

            var contextProvider = new DefaultCompletionContextProvider(completionContext.Document, completionContext.ParsedContent.UnresolvedFile);

            if (project.CompilerSettings != null)
            {
                var conditionalSymbols = project.CompilerSettings.ConditionalSymbols;
                foreach (var symbol in conditionalSymbols)
                {
                    contextProvider.AddSymbol(symbol);
                }
            }

            var instantiating = IsInstantiating(completionContext.NodeCurrentlyUnderCursor);

            var engine = new CSharpCompletionEngine(completionContext.Document
                                                    , contextProvider
                                                    , new CompletionDataFactory(project
                                                                                , partialWord
                                                                                , instantiating
                                                                                , request
                                                                                , _config)
                                                    , completionContext.ParsedContent.ProjectContent
                                                    , completionContext.ResolveContext)
            {
                EolMarker = Environment.NewLine
            };

            engine.AutomaticallyAddImports = request.WantImportableTypes;
            _logger.Debug("Getting Completion Data");

            IEnumerable <CompletionData> data = engine.GetCompletionData(completionContext.CursorPosition, request.ForceSemanticCompletion.GetValueOrDefault(true)).Cast <CompletionData>();

            _logger.Debug("Got Completion Data");
            return(data.Where(d => d != null && d.CompletionText.IsValidCompletionFor(partialWord))
                   .FlattenOverloads()
                   .RemoveDupes()
                   .OrderByDescending(d => d.RequiredNamespaceImport != null ? 0 : 1)
                   .ThenByDescending(d => d.CompletionText.IsValidCompletionStartsWithExactCase(partialWord))
                   .ThenByDescending(d => d.CompletionText.IsValidCompletionStartsWithIgnoreCase(partialWord))
                   .ThenByDescending(d => d.CompletionText.IsCamelCaseMatch(partialWord))
                   .ThenByDescending(d => d.CompletionText.IsSubsequenceMatch(partialWord))
                   .ThenBy(d => d.CompletionText));
        }
        public IEnumerable<CompletionData> CreateProvider(AutoCompleteRequest request)
        {
            request.Column = request.Column - request.WordToComplete.Length;
            var completionContext = new BufferContext(request, _parser);

            var partialWord = request.WordToComplete;

            var project = _solution.ProjectContainingFile(request.FileName);

            var contextProvider = new DefaultCompletionContextProvider
                (completionContext.Document, completionContext.ParsedContent.UnresolvedFile);

            if (project.CompilerSettings != null)
            {
                var conditionalSymbols = project.CompilerSettings.ConditionalSymbols;
                foreach (var symbol in conditionalSymbols)
                {
                    contextProvider.AddSymbol (symbol);
                }
            }

            var instantiating = IsInstantiating(completionContext.NodeCurrentlyUnderCursor);

            var engine = new CSharpCompletionEngine
                ( completionContext.Document
                , contextProvider
                , new CompletionDataFactory
                  ( project
                    , partialWord
                    , instantiating
                    , request)
                , completionContext.ParsedContent.ProjectContent
                , completionContext.ResolveContext)
                {
                    EolMarker = Environment.NewLine
                };
            engine.AutomaticallyAddImports = request.WantImportableTypes;
            _logger.Debug("Getting Completion Data");

            IEnumerable<CompletionData> data = engine.GetCompletionData(completionContext.CursorPosition, true).Cast<CompletionData>();
            _logger.Debug("Got Completion Data");
            return data.Where(d => d != null && d.CompletionText.IsValidCompletionFor(partialWord))
                       .FlattenOverloads()
                       .RemoveDupes()
                       .OrderByDescending(d => d.RequiredNamespaceImport != null ? 0 : 1)
                       .ThenByDescending(d => d.CompletionText.IsValidCompletionStartsWithExactCase(partialWord))
                       .ThenByDescending(d => d.CompletionText.IsValidCompletionStartsWithIgnoreCase(partialWord))
                       .ThenByDescending(d => d.CompletionText.IsCamelCaseMatch(partialWord))
                       .ThenByDescending(d => d.CompletionText.IsSubsequenceMatch(partialWord))
                       .ThenBy(d => d.CompletionText);
        }
示例#7
0
        public IEnumerable <ICompletionData> CreateProvider(AutoCompleteRequest request)
        {
            request.Column = request.Column - request.WordToComplete.Length;

            var completionContext = new BufferContext(request, _parser);

            var partialWord = request.WordToComplete;

            var project = _solution.ProjectContainingFile(request.FileName);

            ICompletionContextProvider contextProvider = new DefaultCompletionContextProvider
                                                             (completionContext.Document, completionContext.ParsedContent.UnresolvedFile);

            var instantiating = IsInstantiating(completionContext.NodeCurrentlyUnderCursor);

            var engine = new CSharpCompletionEngine
                             (completionContext.Document
                             , contextProvider
                             , new CompletionDataFactory
                                 (project
                                 , partialWord
                                 , instantiating
                                 , request.WantDocumentationForEveryCompletionResult)
                             , completionContext.ParsedContent.ProjectContent
                             , completionContext.ResolveContext)
            {
                EolMarker = Environment.NewLine
            };

            _logger.Debug("Getting Completion Data");

            IEnumerable <ICompletionData> data = engine.GetCompletionData(completionContext.CursorPosition, true);

            _logger.Debug("Got Completion Data");
            return(data.Where(d => d != null && d.CompletionText.IsValidCompletionFor(partialWord))
                   .FlattenOverloads()
                   .RemoveDupes()
                   .OrderByDescending(d => d.CompletionText.IsValidCompletionStartsWithExactCase(partialWord))
                   .ThenByDescending(d => d.CompletionText.IsValidCompletionStartsWithIgnoreCase(partialWord))
                   .ThenByDescending(d => d.CompletionText.IsCamelCaseMatch(partialWord))
                   .ThenByDescending(d => d.CompletionText.IsSubsequenceMatch(partialWord))
                   .ThenBy(d => d.CompletionText));
        }
示例#8
0
        public IEnumerable<ICompletionData> CreateProvider(AutoCompleteRequest request)
        {
            request.Column = request.Column - request.WordToComplete.Length;

            var completionContext = new BufferContext (request, _parser);

            var partialWord = request.WordToComplete;

            var project = _solution.ProjectContainingFile(request.FileName);

            ICompletionContextProvider contextProvider = new DefaultCompletionContextProvider
                (completionContext.Document, completionContext.ParsedContent.UnresolvedFile);

            var instantiating = IsInstantiating(completionContext.NodeCurrentlyUnderCursor);

            var engine = new CSharpCompletionEngine
                ( completionContext.Document
                , contextProvider
                , new CompletionDataFactory
                  ( project
                  , partialWord
                  , instantiating
                  , request.WantDocumentationForEveryCompletionResult)
                , completionContext.ParsedContent.ProjectContent
                , completionContext.ResolveContext)
                {
                    EolMarker = Environment.NewLine
                };

            _logger.Debug("Getting Completion Data");

            IEnumerable<ICompletionData> data = engine.GetCompletionData(completionContext.CursorPosition, true);
            _logger.Debug("Got Completion Data");
            return data.Where(d => d != null && d.CompletionText.IsValidCompletionFor(partialWord))
                       .FlattenOverloads()
                       .RemoveDupes()
					   .OrderByDescending(d => d.CompletionText.IsValidCompletionStartsWithExactCase(partialWord))
					   .ThenByDescending(d => d.CompletionText.IsValidCompletionStartsWithIgnoreCase(partialWord))
					   .ThenByDescending(d => d.CompletionText.IsCamelCaseMatch(partialWord))
					   .ThenByDescending(d => d.CompletionText.IsSubsequenceMatch(partialWord))
                       .ThenBy(d => d.CompletionText);
        }
示例#9
0
        public IEnumerable <ICompletionData> CreateProvider(AutoCompleteRequest request)
        {
            var editorText  = request.Buffer ?? string.Empty;
            var filename    = request.FileName;
            var partialWord = request.WordToComplete ?? string.Empty;

            var doc            = new ReadOnlyDocument(editorText);
            var loc            = new TextLocation(request.Line, request.Column - partialWord.Length);
            int cursorPosition = doc.GetOffset(loc);

            //Ensure cursorPosition only equals 0 when editorText is empty, so line 1,column 1
            //completion will work correctly.
            cursorPosition = Math.Max(cursorPosition, 1);
            cursorPosition = Math.Min(cursorPosition, editorText.Length);


            var res  = _parser.ParsedContent(editorText, filename);
            var rctx = res.UnresolvedFile.GetTypeResolveContext(res.Compilation, loc);

            ICompletionContextProvider contextProvider = new DefaultCompletionContextProvider(doc, res.UnresolvedFile);
            var engine = new CSharpCompletionEngine(doc, contextProvider, new CompletionDataFactory(partialWord), res.ProjectContent, rctx)
            {
                EolMarker = Environment.NewLine
            };

            _logger.Debug("Getting Completion Data");

            IEnumerable <ICompletionData> data = engine.GetCompletionData(cursorPosition, true);

            _logger.Debug("Got Completion Data");
            return(data.Where(d => d != null && d.CompletionText.IsValidCompletionFor(partialWord))
                   .FlattenOverloads()
                   .RemoveDupes()
                   .OrderByDescending(d => d.CompletionText.IsValidCompletionStartsWithExactCase(partialWord))
                   .ThenByDescending(d => d.CompletionText.IsValidCompletionStartsWithIgnoreCase(partialWord))
                   .ThenByDescending(d => d.CompletionText.IsCamelCaseMatch(partialWord))
                   .ThenByDescending(d => d.CompletionText.IsSubsequenceMatch(partialWord))
                   .ThenBy(d => d.CompletionText));
        }
示例#10
0
 public CompletionDataFactory(IProject project, string partialWord, bool instantiating, AutoCompleteRequest request, OmniSharpConfiguration config)
 {
     _project           = project;
     _partialWord       = partialWord;
     _instantiating     = instantiating;
     _wantDocumentation = request.WantDocumentationForEveryCompletionResult;
     _wantMethodHeader  = request.WantMethodHeader;
     _wantSnippet       = request.WantSnippet;
     _wantReturnType    = request.WantReturnType;
     _config            = config;
 }