예제 #1
0
        private string Rename(string buffer, string renameTo)
        {
            var location = TestHelpers.GetLineAndColumnFromDollar(buffer);
            buffer = buffer.Replace("$", "");
            
            var solution = new FakeSolutionBuilder()
                .AddFile(buffer)
                .Build();
            
            var bufferParser = new BufferParser(solution);
            var renameHandler = new RenameHandler(solution, bufferParser, new OmniSharpConfiguration(), new FindUsagesHandler(bufferParser, solution, new ProjectFinder(solution)));
            var request = new RenameRequest
                {
                    Buffer = buffer,
                    Column = location.Column - 1,
                    Line = location.Line,
                    RenameTo = renameTo,
                    FileName = "myfile"
                };

            var response = renameHandler.Rename(request);
            if(response.Changes.Any())
                return response.Changes.First().Buffer;
            return buffer;
        }
예제 #2
0
 public AutoCompleteHandler(ISolution solution, BufferParser parser, Logger logger, OmniSharpConfiguration config)
 {
     _solution = solution;
     _parser = parser;
     _logger = logger;
     _config = config;
 }
        public static OmniSharpRefactoringContext GetContext(BufferParser bufferParser, Request request)
        {
            var q = bufferParser.ParsedContent(request.Buffer, request.FileName);
            var resolver = new CSharpAstResolver(q.Compilation, q.SyntaxTree, q.UnresolvedFile);
            var doc = new StringBuilderDocument(request.Buffer);
            var location = new TextLocation(request.Line, request.Column);
            OmniSharpRefactoringContext refactoringContext;
            if(request is CodeActionRequest)
            {
                var car = request as CodeActionRequest;
                if(car.SelectionStartColumn.HasValue)
                {
                    var startLocation
                        = new TextLocation(car.SelectionStartLine.Value, car.SelectionStartColumn.Value);
                    var endLocation
                        = new TextLocation(car.SelectionEndLine.Value, car.SelectionEndColumn.Value);

                    refactoringContext = new OmniSharpRefactoringContext(doc, resolver, location, startLocation, endLocation);
                }
                else
                {
                    refactoringContext = new OmniSharpRefactoringContext(doc, resolver, location);
                }
            }
            else
            {
                refactoringContext = new OmniSharpRefactoringContext(doc, resolver, location);
            }
            refactoringContext.Services.AddService (typeof(NamingConventionService), new DefaultNameService ());
            return refactoringContext;
        }
예제 #4
0
        public RenameResponse Rename(RenameRequest req)
        {
            var project = _solution.ProjectContainingFile(req.FileName);
            var syntaxTree = project.CreateParser().Parse(req.Buffer, req.FileName);
            var sourceNode = syntaxTree.GetNodeAt(req.Line, req.Column);
            if(sourceNode == null)
                return new RenameResponse();
            var originalName = sourceNode.GetText();

            IEnumerable<AstNode> nodes = _findUsagesHandler.FindUsageNodes(req).ToArray();

            var response = new RenameResponse();

            var modfiedFiles = new List<ModifiedFileResponse>();
            response.Changes = modfiedFiles;

            foreach (IGrouping<string, AstNode> groupedNodes in nodes.GroupBy(n => n.GetRegion().FileName.FixPath()))
            {
                string fileName = groupedNodes.Key;
                OmniSharpRefactoringContext context;
                if (groupedNodes.Key != req.FileName)
                {
                    var file = _solution.GetFile(fileName);
                    var bufferParser = new BufferParser(_solution);
                    var content = bufferParser.ParsedContent(file.Document.Text, file.FileName);
                    var resolver = new CSharpAstResolver(content.Compilation, content.SyntaxTree, content.UnresolvedFile);
                    context = new OmniSharpRefactoringContext(file.Document, resolver);
                }
                else
                {
                    context = OmniSharpRefactoringContext.GetContext(_bufferParser, req);
                }
                string modifiedBuffer = null;
                foreach (var node in groupedNodes.Where(n => n.GetText() == originalName))
                {
                    using (var script = new OmniSharpScript(context))
                    {
                        script.Rename(node, req.RenameTo);
                        modifiedBuffer = script.CurrentDocument.Text;
                    }
                }

                if (modifiedBuffer != null)
                {
                    var modifiedFile = new ModifiedFileResponse
                    {
                        FileName
                        = fileName,
                        Buffer = modifiedBuffer
                    };
                    modfiedFiles.Add(modifiedFile);
                    response.Changes = modfiedFiles;

                    _bufferParser.ParsedContent(modifiedBuffer, fileName);
                    _solution.GetFile(fileName).Update(modifiedBuffer);
                }
            }

            return response;
        }
예제 #5
0
 public RenameHandler(ISolution solution, BufferParser bufferParser, OmniSharpConfiguration config, FindUsagesHandler findUsagesHandler)
 {
     _solution = solution;
     _bufferParser = bufferParser;
     _findUsagesHandler = findUsagesHandler;
     _config = config;
 }
예제 #6
0
        public void Should_insert_stub_method_override()
        {
            var buffer = 
@"
public class WeirdString : String
{
$
}";
            var location = TestHelpers.GetLineAndColumnFromDollar(buffer);
            buffer = buffer.Replace("$","");
            var request = new RunOverrideTargetRequest { Buffer = buffer, FileName = "myfile.cs", Line = location.Line, Column = location.Column };
            var solution = new FakeSolutionBuilder().AddFile(buffer, "myfile.cs").Build();
            var parser = new BufferParser(solution);
            var handler = new OverrideHandler (parser, new OmniSharpConfiguration ());
            request.OverrideTargetName = "public virtual string ToString ();";
            var response = handler.RunOverrideTarget (request);
            string expected = 
@"
public class WeirdString : String
{

    public override string ToString()
    {
        throw new System.NotImplementedException();
    }
}";
            string result = response.Buffer.Replace ("\r\n", "\n");
            result.ShouldEqual(expected);
        }
        private IEnumerable<ModifiedFileResponse> Rename(string renameTo, params Buffer[] buffers)
        {
            RenameRequest request = null;
            var solutionBuilder = new FakeSolutionBuilder();
            foreach (var buffer in buffers)
            {
                if (buffer.Text.Contains("$"))
                {
                    var location = TestHelpers.GetLineAndColumnFromDollar(buffer.Text);
                    buffer.Text = buffer.Text.Replace("$", "");
                    request = new RenameRequest
                    {
                        Buffer = buffer.Text,
                        Column = location.Column - 1,
                        Line = location.Line,
                        RenameTo = renameTo,
                        FileName = buffer.Filename
                    };
                }
                //solutionBuilder = solutionBuilder.AddProject();
                solutionBuilder = solutionBuilder.AddFile(buffer.Text, buffer.Filename);
            }
            var solution = solutionBuilder.Build();
            var bufferParser = new BufferParser(solution);
            var renameHandler = new RenameHandler(solution, bufferParser, new OmniSharpConfiguration());

            var response = renameHandler.Rename(request);
            return response.Changes;
        }
예제 #8
0
		public UpdateBufferModule(BufferParser bufferParser)
		{
			Post["/updatebuffer"] = x =>
        	{
				var req = this.Bind<Common.Request>();
				bufferParser.ParsedContent(req.Buffer, req.FileName);
				return Response.AsJson(true);
			};
        }
 public static OmniSharpRefactoringContext GetContext(BufferParser bufferParser, Request request)
 {
     var q = bufferParser.ParsedContent(request.Buffer, request.FileName);
     var resolver = new CSharpAstResolver(q.Compilation, q.SyntaxTree, q.UnresolvedFile);
     var doc = new StringBuilderDocument(request.Buffer);
     var location = new TextLocation(request.Line, request.Column);
     var refactoringContext = new OmniSharpRefactoringContext(doc, resolver, location);
     return refactoringContext;
 }
예제 #10
0
        public OverrideContext
            (Request request, BufferParser parser) {

            this.BufferParser = parser;
            this.CompletionContext = new BufferContext
                (request, this.BufferParser);

            this.CurrentType = this.CompletionContext.ParsedContent
                .UnresolvedFile.GetInnermostTypeDefinition
                    (this.CompletionContext.TextLocation)
                .Resolve(this.CompletionContext.ResolveContext);

            this.OverrideTargets =
                GetOverridableMembers()
                .Select(m => new GetOverrideTargetsResponse
                        (m, this.CompletionContext.ResolveContext))
                .ToArray();
        }
예제 #11
0
        void Initialize(Request request, BufferParser parser) {
            this.Request = request;
            this.BufferParser = parser;

            this.Document = new ReadOnlyDocument(request.Buffer ?? "");
            this.TextLocation = new TextLocation
                (line: request.Line, 
                column: request.Column);
            
            int cursorPosition = this.Document.GetOffset(this.TextLocation);
            //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, request.Buffer.Length);
            this.CursorPosition = cursorPosition;

            this.ParsedContent = this.BufferParser.ParsedContent(request.Buffer, request.FileName);
            this.ResolveContext = this.ParsedContent.UnresolvedFile.GetTypeResolveContext(this.ParsedContent.Compilation, this.TextLocation);
        }
예제 #12
0
        public void Should_not_offer_already_overridden_method()
        {
            var buffer = @"
public class WeirdString : String
{
    public override string ToString()
    {
        return ""weird"";
    }
$
}";
            var location = TestHelpers.GetLineAndColumnFromDollar(buffer);
            var request = new Request { Buffer = buffer, FileName = "myfile.cs", Line = location.Line, Column = location.Column };
            var solution = new FakeSolutionBuilder().AddFile(buffer, "myfile.cs").Build();
            var parser = new BufferParser(solution);
           
            var context = new OverrideContext(request, parser);
            var overrides = context.OverrideTargets.Select(m => m.OverrideTargetName).ToArray();
            overrides.ShouldNotContain("public virtual string ToString ();");

        }
예제 #13
0
 public OverrideHandler(BufferParser parser, OmniSharpConfiguration config) {
     _parser = parser;
     _config = config;
 }
예제 #14
0
 public TypeLookupHandler(ISolution solution, BufferParser bufferParser)
 {
     _bufferParser = bufferParser;
     _solution = solution;
 }
예제 #15
0
 public CurrentFileMembersHandler(BufferParser parser) {
     _parser = parser;
 }
예제 #16
0
 public OverrideHandler(BufferParser parser) {
     _parser = parser;
 }
예제 #17
0
 public TypeLookupHandler(ISolution solution, BufferParser bufferParser, OmniSharpConfiguration config)
 {
     _config = config;
     _bufferParser = bufferParser;
     _solution = solution;
 }
예제 #18
0
 public AutoCompleteHandler(BufferParser parser, Logger logger)
 {
     _parser = parser;
     _logger = logger;
 }
예제 #19
0
 public GetCodeActionsHandler(BufferParser bufferParser, OmniSharpConfiguration config)
 {
     _bufferParser = bufferParser;
     _config = config;
 }
예제 #20
0
 public CodeIssuesHandler(BufferParser bufferParser, OmniSharpConfiguration config)
 {
     _bufferParser = bufferParser;
     _config = config;
 }
예제 #21
0
 public FixUsingsHandler(BufferParser bufferParser, Logger logger, OmniSharpConfiguration config)
 {
     _bufferParser = bufferParser;
     _logger = logger;
     _config = config;
 }
예제 #22
0
 public GotoDefinitionHandler(BufferParser bufferParser)
 {
     _bufferParser = bufferParser;
 }
 public GetTestContextHandler(ISolution solution, BufferParser parser)
 {
     _solution = solution;
     _parser = parser;
 }
예제 #24
0
 public GotoRegionHandler(BufferParser parser) {
     _parser = parser;
 }
 public GotoImplementationHandler(ISolution solution, BufferParser bufferParser)
 {
     _solution = solution;
     _bufferParser = bufferParser;
 }
예제 #26
0
 public RenameHandler(ISolution solution, BufferParser bufferParser)
 {
     _solution = solution;
     _bufferParser = bufferParser;
     _findUsagesHandler = new FindUsagesHandler(bufferParser, solution);
 }
예제 #27
0
 public AutoCompleteHandler(ISolution solution, BufferParser parser, Logger logger)
 {
     _solution = solution;
     _parser = parser;
     _logger = logger;
 }
예제 #28
0
 public GetCodeActionsHandler(BufferParser bufferParser)
 {
     _bufferParser = bufferParser;
 }
 public GotoImplementationHandler(ISolution solution, BufferParser bufferParser, ProjectFinder projectFinder)
 {
     _solution = solution;
     _bufferParser = bufferParser;
     _projectFinder = projectFinder;
 }
예제 #30
0
 public CodeIssuesHandler(BufferParser bufferParser, OmniSharpConfiguration config)
 {
     _bufferParser = bufferParser;
     _config = config;
     _ignoredCodeIssues = ConfigurationLoader.Config.IgnoredCodeIssues;
 }