Exemplo n.º 1
0
            GetCurrentFileMembersAsTree(CurrentFileMembersRequest request) {
            var context = new BufferContext(request, this._parser);

            var typesDefinedInThisFile = context.ParsedContent
                .UnresolvedFile.TopLevelTypeDefinitions;

            return new CurrentFileMembersAsTreeResponse
                (typesDefinedInThisFile, context.Document);
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 4
0
            GetFileRegions(Request request) {
            var context = new BufferContext(request, this._parser);

            var declarationCollector = new GetDirectivesAstVisitor();
            context.ParsedContent.SyntaxTree
                .AcceptVisitor(declarationCollector);

            var regions = declarationCollector.Directives
                .Where(d => d.Type == PreProcessorDirectiveType.Region
                       || d.Type == PreProcessorDirectiveType.Endregion)
                .Select(d => QuickFix.ForFirstLineInRegion
                        (d.GetRegion(), context.Document));

            return new QuickFixResponse(regions);
        }
Exemplo n.º 5
0
        public IEnumerable<QuickFix> GetCurrentFileMembersAsFlatWithoutAccessModifiers(CurrentFileMembersRequest request)
        {
            var context = new BufferContext(request, this._parser);

            var result = new List<QuickFix>();
           

            foreach (var item in context.ParsedContent.UnresolvedFile.TopLevelTypeDefinitions)
            {
                result.Add(new QuickFix()
                    {
                        FileName = item.Region.FileName
                            , Line = item.Region.BeginLine
                            , Column = item.Region.BeginColumn
                            , EndLine = item.Region.EndLine
                            , EndColumn = item.Region.EndColumn
                            , Text = item.Name
                    });
            }

            var members = context.ParsedContent.UnresolvedFile.TopLevelTypeDefinitions
                .SelectMany(x => x.Members);



            foreach (var item in members)
            {
                var ambience = new CSharpAmbience();
                ambience.ConversionFlags = ConversionFlags.ShowParameterList | ConversionFlags.ShowParameterNames;
                var memberTitle = ambience.ConvertSymbol(item.Resolve(context.ResolveContext));

                var qf = new QuickFix()
                {
                    FileName = item.Region.FileName
                            , Line = item.Region.BeginLine
                            , Column = item.Region.BeginColumn
                            , EndLine = item.Region.EndLine
                            , EndColumn = item.Region.EndColumn
                            , Text = memberTitle
                };

                result.Add(qf);
            }

            return result.OrderBy(x => x.Text);

        }
        public GetContextResponse GetContextResponse(TestCommandRequest request)
        {
            string methodName = null;

            var bufferContext = new BufferContext(request, _parser);
			var node = bufferContext.NodeCurrentlyUnderCursor;

            TypeDeclaration type = null;
			NamespaceDeclaration namespaceDeclaration = null;
			if(node != null)
			{
				var method = (MethodDeclaration) node.AncestorsAndSelf.FirstOrDefault(n => n is MethodDeclaration);
				if (method != null)
					methodName = method.Name;
				type = (TypeDeclaration)node.AncestorsAndSelf.FirstOrDefault(n => n is TypeDeclaration);
				namespaceDeclaration = (NamespaceDeclaration)node.AncestorsAndSelf.FirstOrDefault(n => n is NamespaceDeclaration);
			}

            if (type == null)
			{
				var tree = bufferContext.ParsedContent.SyntaxTree;
				type = (TypeDeclaration)tree.DescendantsAndSelf.FirstOrDefault(n => n is TypeDeclaration);
				namespaceDeclaration = (NamespaceDeclaration)tree.DescendantsAndSelf.FirstOrDefault(n => n is NamespaceDeclaration);
			}

			string typeName = type.Name;

            if (namespaceDeclaration != null)
                typeName = namespaceDeclaration.FullName + "." + typeName;

            var project = _solution.ProjectContainingFile(request.FileName);
            var directory = new FileInfo(project.FileName).Directory.FullName;

            var assemblyName = "\"" +
                               Path.Combine(directory, "bin", "Debug", project.ProjectContent.FullAssemblyName + ".dll")
                               + "\"";

            return new GetContextResponse
            {
                AssemblyName = assemblyName,
                TypeName = typeName,
                MethodName = methodName
            };

        }
Exemplo n.º 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));
        }
Exemplo n.º 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);
        }