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; }
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; }
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; }
public RenameHandler(ISolution solution, BufferParser bufferParser, OmniSharpConfiguration config, FindUsagesHandler findUsagesHandler) { _solution = solution; _bufferParser = bufferParser; _findUsagesHandler = findUsagesHandler; _config = config; }
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; }
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; }
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(); }
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); }
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 ();"); }
public OverrideHandler(BufferParser parser, OmniSharpConfiguration config) { _parser = parser; _config = config; }
public TypeLookupHandler(ISolution solution, BufferParser bufferParser) { _bufferParser = bufferParser; _solution = solution; }
public CurrentFileMembersHandler(BufferParser parser) { _parser = parser; }
public OverrideHandler(BufferParser parser) { _parser = parser; }
public TypeLookupHandler(ISolution solution, BufferParser bufferParser, OmniSharpConfiguration config) { _config = config; _bufferParser = bufferParser; _solution = solution; }
public AutoCompleteHandler(BufferParser parser, Logger logger) { _parser = parser; _logger = logger; }
public GetCodeActionsHandler(BufferParser bufferParser, OmniSharpConfiguration config) { _bufferParser = bufferParser; _config = config; }
public CodeIssuesHandler(BufferParser bufferParser, OmniSharpConfiguration config) { _bufferParser = bufferParser; _config = config; }
public FixUsingsHandler(BufferParser bufferParser, Logger logger, OmniSharpConfiguration config) { _bufferParser = bufferParser; _logger = logger; _config = config; }
public GotoDefinitionHandler(BufferParser bufferParser) { _bufferParser = bufferParser; }
public GetTestContextHandler(ISolution solution, BufferParser parser) { _solution = solution; _parser = parser; }
public GotoRegionHandler(BufferParser parser) { _parser = parser; }
public GotoImplementationHandler(ISolution solution, BufferParser bufferParser) { _solution = solution; _bufferParser = bufferParser; }
public RenameHandler(ISolution solution, BufferParser bufferParser) { _solution = solution; _bufferParser = bufferParser; _findUsagesHandler = new FindUsagesHandler(bufferParser, solution); }
public AutoCompleteHandler(ISolution solution, BufferParser parser, Logger logger) { _solution = solution; _parser = parser; _logger = logger; }
public GetCodeActionsHandler(BufferParser bufferParser) { _bufferParser = bufferParser; }
public GotoImplementationHandler(ISolution solution, BufferParser bufferParser, ProjectFinder projectFinder) { _solution = solution; _bufferParser = bufferParser; _projectFinder = projectFinder; }
public CodeIssuesHandler(BufferParser bufferParser, OmniSharpConfiguration config) { _bufferParser = bufferParser; _config = config; _ignoredCodeIssues = ConfigurationLoader.Config.IgnoredCodeIssues; }