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(), new FindUsagesHandler(bufferParser, solution, new ProjectFinder(solution))); var response = renameHandler.Rename(request); return(response.Changes); }
internal override FileNode RenameFileNode(string oldFileName, string newFileName) { var res = base.RenameFileNode(oldFileName, newFileName); if (newFileName.EndsWith(PythonConstants.FileExtension, StringComparison.OrdinalIgnoreCase)) { TryRename(oldFileName + "c", newFileName + "c"); TryRename(oldFileName + "o", newFileName + "o"); } if (res != null) { var analyzer = ((PythonProjectNode)this.ProjectMgr).GetAnalyzer(); var analysis = GetAnalysisEntry(); if (analysis != null) { analyzer.UnloadFileAsync(analysis).DoNotWait(); } var textBuffer = GetTextBuffer(false); BufferParser parser = analysis?.BufferParser; if (parser != null) { analyzer.ReAnalyzeTextBuffers(parser); } } return(res); }
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 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); 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 RenameHandler(ISolution solution, BufferParser bufferParser, OmniSharpConfiguration config) { _solution = solution; _bufferParser = bufferParser; _findUsagesHandler = new FindUsagesHandler(bufferParser, solution); _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()); refactoringContext.Services.AddService(typeof(CodeGenerationService), new DefaultCodeGenerationService()); return(refactoringContext); }
public Dispatcher(UserConnection userConnection) { _bufferParser = new BufferParser(); _userConnection = userConnection; _authorizePleaseHandler = new AuthorizeHandler(); _userServiceDB = new UserServiceDB(); }
public AutoCompleteHandler(ISolution solution, BufferParser parser, Logger logger, OmniSharpConfiguration config) { _solution = solution; _parser = parser; _logger = logger; _config = config; }
public void BufferSync_Issue3570() { // https://github.com/Microsoft/PTVS/issues/3570 var buffer = new MockTextBuffer("line"); var bi = PythonTextBufferInfo.ForBuffer(null, buffer); bi.AddSentSnapshot(buffer.CurrentSnapshot); Assert.AreEqual(new SourceLocation(1, 5), bi.LocationTracker.GetSourceLocation(4, 0)); using (var e = buffer.CreateEdit()) { e.Insert(e.Snapshot.Length, "\r\n"); e.Apply(); } using (var e = buffer.CreateEdit()) { e.Insert(e.Snapshot.Length, " c"); e.Apply(); } using (var e = buffer.CreateEdit()) { e.Insert(e.Snapshot.Length, "o"); e.Apply(); } var updates = BufferParser.GetUpdatesForSnapshot(bi, buffer.CurrentSnapshot).ToArray(); var changeInfo = string.Join(", ", updates .Select(u => string.Join(", ", u.changes.Select(c => $"({c.startLine},{c.startColumn},'{c.newText}')"))) .Select(u => $"[{u}]")); Assert.AreEqual("[(1,5,'\r\n')], [(2,1,' c')], [(2,6,'o')]", changeInfo); }
public UpdateBufferModule(BufferParser bufferParser) { Post["UpdateBuffer", "/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); }
private static BufferWriter GetWriter(MetadataIdentity source, IRelationHeader header) { RelationCacheKey key = new RelationCacheKey(source, header); return(cache.GetOrAdd(key, _ => { BufferParser parser = new BufferParser(); BufferTree tree = parser.Parse(source, header); RelationCompiler compiler = new RelationCompiler(); return compiler.Compile(tree); })); }
public static FixUsingsResponse GetFixUsingsResponse(this string buffer) { var solution = new FakeSolutionBuilder().AddFile(buffer).Build(); var bufferParser = new BufferParser(solution); var handler = new FixUsingsHandler(bufferParser, new Logger(Verbosity.Quiet), new OmniSharpConfiguration()); var request = new Request(); request.Buffer = buffer; request.FileName = "myfile"; // line number should be irrelevant request.Line = int.MaxValue; var response = handler.FixUsings(request); return(response); }
/// <summary> /// Handle a shutdown notification message. /// </summary> /// <param name="Message">Supplies the message.</param> /// <param name="Source">Supplies the message sender.</param> private void OnRecvMessageShutdownNotify(NetworkMessage Message, GameServer Source) { BufferParser Parser = Message.GetParser(); int SourceServerId = Parser.ReadInt32(); Parser.FinishParsing(); if (SourceServerId != Source.ServerId) { return; } // // Tear down any state between the two servers. // }
/// <summary> /// Parses the specified text buffer. Continues to monitor the parsed buffer and updates /// the parse tree asynchronously as the buffer changes. /// </summary> /// <param name="buffer"></param> private BufferParser EnqueueBuffer(IProjectEntry projEntry, ITextBuffer buffer) { // only attach one parser to each buffer, we can get multiple enqueue's // for example if a document is already open when loading a project. BufferParser bufferParser; if (!buffer.Properties.TryGetProperty<BufferParser>(typeof(BufferParser), out bufferParser)) { bufferParser = new BufferParser(projEntry, this, buffer); var curSnapshot = buffer.CurrentSnapshot; bufferParser.EnqueingEntry(); EnqueWorker(() => { ParseBuffers(bufferParser, curSnapshot); }); } else { bufferParser.AttachedViews++; } return bufferParser; }
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(); }
/// <summary> /// Handle an IPC wakeup message received. /// </summary> /// <param name="Message">Supplies the message.</param> /// <param name="Source">Supplies the message sender.</param> private void OnRecvMessageIPCWake(NetworkMessage Message, GameServer Source) { BufferParser Parser = Message.GetParser(); int SourceServerId = Parser.ReadInt32(); int DestinationServerId = Parser.ReadInt32(); Parser.FinishParsing(); if (SourceServerId != Source.ServerId || LocalServerId != DestinationServerId) { return; } // // Signal the world manager that it should break out of the polling // wait and immediately check for new IPC messages that are // available to process. // WorldManager.SignalIPCEventWakeup(); }
/// <summary> /// Handle a database status notification. /// </summary> /// <param name="Message">Supplies the message.</param> /// <param name="Source">Supplies the message sender.</param> private void OnRecvMessageNotifyDatabaseStatus(NetworkMessage Message, GameServer Source) { BufferParser Parser = Message.GetParser(); int SourceServerId = Parser.ReadInt32(); bool DatabaseOnline = (Parser.ReadByte() == 0 ? false : true); Parser.FinishParsing(); if (SourceServerId != Source.ServerId) { return; } lock (WorldManager) { if (Source.Online) { Source.DatabaseOnline = DatabaseOnline; } } }
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); }
/// <summary> /// Parses the specified text buffer. Continues to monitor the parsed buffer and updates /// the parse tree asynchronously as the buffer changes. /// </summary> /// <param name="buffer"></param> public void EnqueueBuffer(ITextView textView) { ITextBuffer buffer = textView.TextBuffer; var curSnapshot = buffer.CurrentSnapshot; EnqueWorker(new[] { GetContentProvider(buffer, curSnapshot) }); // only attach one parser to each buffer, we can get multiple enqueue's // for example if a document is already open when loading a project. if (!buffer.Properties.ContainsProperty(typeof(BufferParser))) { BufferParser parser = new BufferParser(this, buffer); buffer.ChangedLowPriority += parser.BufferChangedLowPriority; textView.Closed += (sender, args) => { buffer.ChangedLowPriority -= parser.BufferChangedLowPriority; buffer.Properties.RemoveProperty(typeof(BufferParser)); }; buffer.Properties.AddProperty(typeof(BufferParser), parser); } }
/// <summary> /// Parses the specified text buffer. Continues to monitor the parsed buffer and updates /// the parse tree asynchronously as the buffer changes. /// </summary> /// <param name="buffer"></param> private BufferParser EnqueueBuffer(IProjectEntry projEntry, ITextBuffer buffer) { // only attach one parser to each buffer, we can get multiple enqueue's // for example if a document is already open when loading a project. BufferParser bufferParser; if (!buffer.Properties.TryGetProperty <BufferParser>(typeof(BufferParser), out bufferParser)) { bufferParser = new BufferParser(projEntry, this, buffer); var curSnapshot = buffer.CurrentSnapshot; bufferParser.EnqueingEntry(); EnqueWorker(() => { ParseBuffers(bufferParser, curSnapshot); }); } else { bufferParser.AttachedViews++; } return(bufferParser); }
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 GotoImplementationHandler(ISolution solution, BufferParser bufferParser, ProjectFinder projectFinder) { _solution = solution; _bufferParser = bufferParser; _projectFinder = projectFinder; }
public TypeLookupHandler(ISolution solution, BufferParser bufferParser, OmniSharpConfiguration config) { _config = config; _bufferParser = bufferParser; _solution = solution; }
public BufferContext (Request request, BufferParser bufferParser) { this.Initialize(request, bufferParser); }
public GotoDefinitionHandler(BufferParser bufferParser) { _bufferParser = bufferParser; }
private void ViewDetached(ITextBuffer buffer, BufferParser bufferParser) { bufferParser.RemoveBuffer(buffer); lock (_activeBufferParsers) { _activeBufferParsers.Remove(bufferParser); } #if FALSE _unresolvedSquiggles.StopListening(bufferParser._currentProjEntry as IPythonProjectEntry); #endif TaskProvider.ClearErrorSource(bufferParser._currentProjEntry, ParserTaskMoniker); if (_implicitProject) { UnloadFile(bufferParser._currentProjEntry); } }
/// <summary> /// Creates a new ProjectEntry for the collection of buffers. /// /// _openFiles must be locked when calling this function. /// </summary> private void ReAnalyzeTextBuffers(BufferParser bufferParser) { if (!_fullyLoaded) { lock (_loadingDeltas) { if (!_fullyLoaded) { _loadingDeltas.Add(() => ReAnalyzeTextBuffers(bufferParser)); return; } } } ITextBuffer[] buffers = bufferParser.Buffers; if (buffers.Length > 0) { var projEntry = GetOrCreateProjectEntry(buffers[0], new SnapshotCookie(buffers[0].CurrentSnapshot)); foreach (var buffer in buffers) { buffer.Properties.RemoveProperty(typeof(IProjectEntry)); buffer.Properties.AddProperty(typeof(IProjectEntry), projEntry); var classifier = buffer.GetNodejsClassifier(); if (classifier != null) { classifier.NewVersion(); } ConnectErrorList(projEntry, buffer); } bufferParser._currentProjEntry = projEntry; bufferParser._parser = this; #if FALSE // TODO: Add back for navigation bar support foreach (var buffer in buffers) { // A buffer may have multiple DropDownBarClients, given one may open multiple CodeWindows // over a single buffer using Window/New Window List<DropDownBarClient> clients; if (buffer.Properties.TryGetProperty<List<DropDownBarClient>>(typeof(DropDownBarClient), out clients)) { foreach (var client in clients) { client.UpdateProjectEntry(projEntry); } } } #endif bufferParser.Requeue(); } }
public FindUsagesHandler(BufferParser parser, ISolution solution) { _parser = parser; _solution = solution; }
public FindUsagesHandler(BufferParser parser, ISolution solution, ProjectFinder projectFinder) { _projectFinder = projectFinder; _parser = parser; _solution = solution; }
public CodeIssuesHandler(BufferParser bufferParser, OmniSharpConfiguration config) { _bufferParser = bufferParser; _config = config; }
public AutoCompleteHandler(BufferParser parser, Logger logger) { _parser = parser; _logger = logger; }
public GetCodeActionsHandler(BufferParser bufferParser, OmniSharpConfiguration config) { _bufferParser = bufferParser; _config = config; }
private void ParseBuffers(BufferParser bufferParser, params ITextSnapshot[] snapshots) { IProjectEntry entry = bufferParser._currentProjEntry; IJsProjectEntry jsProjEntry = entry as IJsProjectEntry; List<JsAst> asts = new List<JsAst>(); foreach (var snapshot in snapshots) { if (snapshot.TextBuffer.Properties.ContainsProperty(NodejsReplEvaluator.InputBeforeReset)) { continue; } if (snapshot.IsReplBufferWithCommand()) { continue; } if (jsProjEntry != null && snapshot.TextBuffer.ContentType.IsOfType(NodejsConstants.Nodejs)) { JsAst ast; CollectingErrorSink errorSink; var reader = new SnapshotSpanSourceCodeReader(new SnapshotSpan(snapshot, new Span(0, snapshot.Length))); ParseNodejsCode(reader, out ast, out errorSink); if (ast != null) { asts.Add(ast); } // update squiggles for the buffer UpdateErrorsAndWarnings(entry, snapshot, errorSink); } else { // other file such as XAML IExternalProjectEntry externalEntry; if ((externalEntry = (entry as IExternalProjectEntry)) != null) { var snapshotContent = new SnapshotSpanSourceCodeReader(new SnapshotSpan(snapshot, new Span(0, snapshot.Length))); externalEntry.ParseContent(snapshotContent, new SnapshotCookie(snapshotContent.Snapshot)); if (ShouldEnqueue()) { _analysisQueue.Enqueue(entry, AnalysisPriority.High); } } } } if (jsProjEntry != null) { if (asts.Count > 0) { JsAst finalAst; if (asts.Count == 1) { finalAst = asts[0]; } else { // multiple ASTs, merge them together var block = new Block(default(EncodedSpan)); var statements = new List<Statement>(); foreach (var code in asts) { statements.Add(code.Block); } block.Statements = statements.ToArray(); finalAst = asts.Last().CloneWithNewBlock(block); } jsProjEntry.UpdateTree(finalAst, new SnapshotCookie(snapshots[0])); // SnapshotCookie is not entirely right, we should merge the snapshots if (ShouldEnqueue()) { _analysisQueue.Enqueue(entry, AnalysisPriority.High); } } else { // indicate that we are done parsing. JsAst prevTree; IAnalysisCookie prevCookie; jsProjEntry.GetTreeAndCookie(out prevTree, out prevCookie); jsProjEntry.UpdateTree(prevTree, prevCookie); } } }
/// <summary> /// Creates a new ProjectEntry for the collection of buffers. /// /// _openFiles must be locked when calling this function. /// </summary> private void ReAnalyzeTextBuffers(BufferParser bufferParser) { WhenFullyLoaded(() => { ITextBuffer[] buffers = bufferParser.Buffers; if (buffers.Length > 0) { var projEntry = GetOrCreateProjectEntry(buffers[0], new SnapshotCookie(buffers[0].CurrentSnapshot)); foreach (var buffer in buffers) { buffer.Properties.RemoveProperty(typeof(IProjectEntry)); buffer.Properties.AddProperty(typeof(IProjectEntry), projEntry); var classifier = buffer.GetNodejsClassifier(); if (classifier != null) { classifier.NewVersion(); } ConnectErrorList(projEntry, buffer); } bufferParser._currentProjEntry = projEntry; bufferParser._parser = this; bufferParser.Requeue(); } }); }