Пример #1
0
        public TypeLookupResponse GetTypeLookupResponse(TypeLookupRequest request)
        {
            var res = _bufferParser.ParsedContent(request.Buffer, request.FileName);
            var loc = new TextLocation(request.Line, request.Column);
            var resolveResult = ResolveAtLocation.Resolve(res.Compilation, res.UnresolvedFile, res.SyntaxTree, loc);
            var response = new TypeLookupResponse();
            var ambience = new CSharpAmbience()
            {
                ConversionFlags = AmbienceFlags,
            };


            if (resolveResult == null || resolveResult is NamespaceResolveResult)
                response.Type = "";
            else
            {
                response.Type = resolveResult.Type.ToString();
                IEntity entity = null;
                if (resolveResult is CSharpInvocationResolveResult)
                {
                    var result = resolveResult as CSharpInvocationResolveResult;
                    entity = result.Member;
                    response.Type = ambience.ConvertSymbol(result.Member);
                }
                else if (resolveResult is LocalResolveResult)
                {
                    var result = resolveResult as LocalResolveResult;
                    response.Type = ambience.ConvertVariable(result.Variable);
                }
                else if (resolveResult is MemberResolveResult)
                {
                    var result = resolveResult as MemberResolveResult;
                    entity = result.Member;
                    response.Type = ambience.ConvertSymbol(result.Member);
                }
                else if (resolveResult is TypeResolveResult)
                {
                    ambience.ConversionFlags |= ConversionFlags.UseFullyQualifiedTypeNames;
                    response.Type = ambience.ConvertType(resolveResult.Type);
                }

                if (resolveResult.Type is UnknownType)
                    response.Type = "Unknown Type: " + resolveResult.Type.Name;
                if (resolveResult.Type == SpecialType.UnknownType)
                    response.Type = "Unknown Type";

                if (request.IncludeDocumentation && entity != null)
                {
                    var project = _solution.ProjectContainingFile(request.FileName);
                    response.Documentation = new DocumentationFetcher().GetDocumentation(project, entity, _config);
                }
            }

            return response;
        }
Пример #2
0
        public TypeLookupResponse GetTypeLookupResponse(TypeLookupRequest request)
        {
            var res           = _bufferParser.ParsedContent(request.Buffer, request.FileName);
            var loc           = new TextLocation(request.Line, request.Column);
            var resolveResult = ResolveAtLocation.Resolve(res.Compilation, res.UnresolvedFile, res.SyntaxTree, loc);
            var response      = new TypeLookupResponse();
            var ambience      = new CSharpAmbience()
            {
                ConversionFlags = AmbienceFlags,
            };


            if (resolveResult == null || resolveResult is NamespaceResolveResult)
            {
                response.Type = "";
            }
            else if (resolveResult != null)
            {
                response.Type = resolveResult.Type.ToString();

                if (resolveResult is CSharpInvocationResolveResult)
                {
                    var result = resolveResult as CSharpInvocationResolveResult;
                    response.Type = ambience.ConvertEntity(result.Member);
                }
                else if (resolveResult is LocalResolveResult)
                {
                    var result = resolveResult as LocalResolveResult;
                    response.Type = ambience.ConvertVariable(result.Variable);
                }
                else if (resolveResult is MemberResolveResult)
                {
                    var result = resolveResult as MemberResolveResult;
                    response.Type = ambience.ConvertEntity(result.Member);
                }
                else if (resolveResult is TypeResolveResult)
                {
                    ambience.ConversionFlags |= ConversionFlags.UseFullyQualifiedTypeNames;
                    response.Type             = ambience.ConvertType(resolveResult.Type);
                }

                if (resolveResult.Type is UnknownType)
                {
                    response.Type = "Unknown Type: " + resolveResult.Type.Name;
                }
                if (resolveResult.Type == SpecialType.UnknownType)
                {
                    response.Type = "Unknown Type";
                }
            }

            return(response);
        }
Пример #3
0
        public TypeLookupResponse GetTypeLookupResponse(TypeLookupRequest request)
        {
            var res = _bufferParser.ParsedContent(request.Buffer, request.FileName);
            var loc = new TextLocation(request.Line, request.Column);
            var resolveResult = ResolveAtLocation.Resolve(res.Compilation, res.UnresolvedFile, res.SyntaxTree, loc);
            var response = new TypeLookupResponse();
            var ambience = new CSharpAmbience()
                {
                    ConversionFlags = AmbienceFlags,
                };

            if (resolveResult == null || resolveResult is NamespaceResolveResult)
                response.Type = "";
            else if (resolveResult != null)
            {
                response.Type = resolveResult.Type.ToString();

                if (resolveResult is CSharpInvocationResolveResult)
                {
                    var result = resolveResult as CSharpInvocationResolveResult;
                    response.Type = ambience.ConvertEntity(result.Member);
                }
                else if (resolveResult is LocalResolveResult)
                {
                    var result = resolveResult as LocalResolveResult;
                    response.Type = ambience.ConvertVariable(result.Variable);
                }
                else if (resolveResult is MemberResolveResult)
                {
                    var result = resolveResult as MemberResolveResult;
                    response.Type = ambience.ConvertEntity(result.Member);
                }
                else if (resolveResult is TypeResolveResult)
                {
                    ambience.ConversionFlags |= ConversionFlags.UseFullyQualifiedTypeNames;
                    response.Type = ambience.ConvertType(resolveResult.Type);
                }

                if (resolveResult.Type is UnknownType)
                    response.Type = "Unknown Type: " + resolveResult.Type.Name;
                if (resolveResult.Type == SpecialType.UnknownType)
                    response.Type = "Unknown Type";
            }

            return response;
        }
Пример #4
0
        public static string LookupType(this string editorText)
        {
            int cursorOffset = editorText.IndexOf("$", StringComparison.Ordinal);
            var cursorPosition = TestHelpers.GetLineAndColumnFromIndex(editorText, cursorOffset);
            editorText = editorText.Replace("$", "");

            var solution = new FakeSolution();
            var project = new FakeProject();
            project.AddFile(editorText);
            solution.Projects.Add(project);

            var handler = new TypeLookupHandler(new BufferParser(solution));
            var request = new TypeLookupRequest()
                {
                    Buffer = editorText,
                    FileName = "myfile",
                    Line = cursorPosition.Line,
                    Column = cursorPosition.Column,
                };

            return handler.GetTypeLookupResponse(request).Type;
        }
Пример #5
0
        public TypeLookupResponse GetTypeLookupResponse(TypeLookupRequest request)
        {
            var res           = _bufferParser.ParsedContent(request.Buffer, request.FileName);
            var loc           = new TextLocation(request.Line, request.Column);
            var resolveResult = ResolveAtLocation.Resolve(res.Compilation, res.UnresolvedFile, res.SyntaxTree, loc);
            var response      = new TypeLookupResponse();
            var ambience      = new CSharpAmbience()
            {
                ConversionFlags = AmbienceFlags,
            };


            if (resolveResult == null || resolveResult is NamespaceResolveResult)
            {
                response.Type = "";
            }
            else
            {
                response.Type = resolveResult.Type.ToString();
                IEntity entity = null;
                if (resolveResult is CSharpInvocationResolveResult)
                {
                    var result = resolveResult as CSharpInvocationResolveResult;
                    entity        = result.Member;
                    response.Type = ambience.ConvertSymbol(result.Member);
                }
                else if (resolveResult is LocalResolveResult)
                {
                    var result = resolveResult as LocalResolveResult;
                    response.Type = ambience.ConvertVariable(result.Variable);
                }
                else if (resolveResult is MemberResolveResult)
                {
                    var result = resolveResult as MemberResolveResult;
                    entity        = result.Member;
                    response.Type = ambience.ConvertSymbol(result.Member);
                }
                else if (resolveResult is TypeResolveResult)
                {
                    ambience.ConversionFlags |= ConversionFlags.UseFullyQualifiedTypeNames;
                    response.Type             = ambience.ConvertType(resolveResult.Type);
                }

                if (resolveResult.Type is UnknownType)
                {
                    response.Type = "Unknown Type: " + resolveResult.Type.Name;
                }
                if (resolveResult.Type == SpecialType.UnknownType)
                {
                    response.Type = "Unknown Type";
                }

                if (request.IncludeDocumentation && entity != null)
                {
                    var project = _solution.ProjectContainingFile(request.FileName);
                    response.Documentation = new DocumentationFetcher().GetDocumentation(project, entity, _config);
                }
            }

            return(response);
        }