public virtual void GetPairExtents( int line, int col, out TextSpan span ) { span = new TextSpan(); // Synchronously return the matching brace location. string text = this.GetTextUpToLine(0); // Might be matching forwards so we have to search the whole file. string fname = this.GetFilePath(); ParseReason reason = ParseReason.MatchBraces; AuthoringSink sink = new AuthoringSink(reason, line, col); AuthoringScope scope = this.service.ParseSource(text, line, col, fname, sink, reason); if (sink.Spans.Count == 0) return; //transform spanList into an array of spans TextSpan[] spans = (TextSpan[])sink.Spans.ToArray(typeof(TextSpan)); int spanCount = spans.Length; //called from ViewFilter::GetPairExtents if (spans[0].iStartLine < spans[spanCount-1].iStartLine || (spans[0].iStartLine == spans[spanCount-1].iStartLine && spans[0].iStartIndex <= spans[spanCount-1].iStartIndex )) { span.iStartLine = spans[0].iStartLine; span.iStartIndex = spans[0].iStartIndex; span.iEndLine = spans[spanCount-1].iStartLine; span.iEndIndex = spans[spanCount-1].iStartIndex; } else { span.iStartLine = spans[spanCount-1].iStartLine; span.iStartIndex = spans[spanCount-1].iStartIndex; span.iEndLine = spans[0].iStartLine; span.iEndIndex = spans[0].iStartIndex; } if (span.iStartLine == span.iEndLine && span.iStartIndex == span.iEndIndex) NativeHelpers.RaiseComError(HResult.S_FALSE); return; }
public virtual string OnSyncQuickInfo(IVsTextView textView, int line, int col) { // synchronous parse and return data tip text. string text = this.GetTextUpToLine(line+1); string fname = this.GetFilePath(); ParseReason reason = ParseReason.Autos; AuthoringSink sink = new AuthoringSink(reason, line, col); AuthoringScope scope = this.service.ParseSource(text, line, col, fname, sink, reason); if (scope != null) { TextSpan span; return scope.GetDataTipText(line, col, out span); } return null; }
public virtual string OnSyncGoto(VsCommands cmd, IVsTextView textView, int line, int col, out TextSpan span) { // synchronous parse and return definition location. string text = this.GetTextUpToLine(line+1); string fname = this.GetFilePath(); ParseReason reason = ParseReason.Autos; AuthoringSink sink = new AuthoringSink(reason, line, col); AuthoringScope scope = this.service.ParseSource(text, line, col, fname, sink, reason); if (scope != null) { return scope.Goto(cmd, textView, line, col, out span); } else { span = new TextSpan(); } return null; }
public abstract void ParseAndAnalyzeCompilationUnit(string fname, string source, int line, int col, ErrorNodeList errors, Compilation compilation, AuthoringSink sink);
public abstract CompilationUnit ParseCompilationUnit(string fname, string source, ErrorNodeList errors, Compilation compilation, AuthoringSink sink);
public virtual AuthoringScope ParsePartialCompilationUnit(string fname, string text, int line, int col, AuthoringSink asink, ParseReason reason){ Compilation compilation = this.GetCompilationFor(fname); if (line >= 0 && (reason == ParseReason.MemberSelect || reason == ParseReason.MemberSelectExplicit || reason == ParseReason.CompleteWord)) text = this.Truncate(text, line, col); Module savedSymbolTable = this.currentSymbolTable; compilation.TargetModule = this.currentSymbolTable = new Module(); this.currentSymbolTable.AssemblyReferences = savedSymbolTable.AssemblyReferences; CompilationUnit partialCompilationUnit = this.ParseCompilationUnit(fname, text, new ErrorNodeList(), compilation, asink); compilation.TargetModule = this.currentSymbolTable = savedSymbolTable; if (reason != ParseReason.HighlightBraces && reason != ParseReason.MatchBraces){ MemberFinder memberFinder = this.GetMemberFinder(line+1, col+1); memberFinder.Visit(partialCompilationUnit); Member unresolvedMember = memberFinder.Member; memberFinder.Member = null; CompilationUnit cu = this.GetCompilationUnitSnippet(compilation, fname); if (cu != null){ if (unresolvedMember == null){ //Dealing with a construct that is not part of a type definition, such as a using statement this.Resolve(partialCompilationUnit); }else{ memberFinder.Visit(cu); if (memberFinder.Member != null) this.Resolve(unresolvedMember, memberFinder.Member); else this.Resolve(partialCompilationUnit); //Symbol table is out of date } } } return this.GetAuthoringScope(); }
public virtual void ReportErrors(string fileName, ErrorNodeList errors, AuthoringSink sink){ if (sink == null) return; for (int n = errors.Count, i = n-1; i >= 0; i--){ //Scan backwards so that early errors trump later errors ErrorNode enode = errors[i]; if (enode == null || enode.Severity < 0) continue; //TODO: suppress warnings of level > set in options SourceContext context = enode.SourceContext; if (context.Document == null) continue; if (context.Document.Name != fileName) continue; sink.AddError(enode); } }
public AuthoringScope ParseSource(string text, int line, int col, string fname, AuthoringSink asink, ParseReason reason){ this.currentAst = null; Compilation compilation = this.GetCompilationFor(fname); Debug.Assert(compilation != null, "no compilation for: "+fname); this.currentSymbolTable = compilation.TargetModule; switch (reason){ case ParseReason.CollapsibleRegions: case ParseReason.CompleteWord: case ParseReason.MatchBraces: case ParseReason.HighlightBraces: case ParseReason.MemberSelect: case ParseReason.MemberSelectExplicit: case ParseReason.MethodTip: case ParseReason.QuickInfo: case ParseReason.Autos:{ return this.ParsePartialCompilationUnit(fname, text, line, col, asink, reason); } case ParseReason.Check:{ ErrorNodeList errors = new ErrorNodeList(); this.ParseAndAnalyzeCompilationUnit(fname, text, line, col, errors, compilation, asink); this.ReportErrors(fname, errors, asink); return this.GetAuthoringScope(); } } return null; }
public virtual AuthoringScope GetAuthoringScopeForMethodBody(string text, Compilation/*!*/ compilation, Method/*!*/ method, AuthoringSink asink) { return null; }
public abstract int ParseStatements(StatementList statements, int startColumn, string terminator, AuthoringSink sink);
public abstract int ParseTypeMembers(TypeNode type, int startColumn, string terminator, AuthoringSink sink);
public abstract Expression ParseExpression(int startColumn, string terminator, AuthoringSink sink);
public abstract CompilationUnit ParseCompilationUnit(String source, string fname, CompilerParameters parameters, ErrorNodeList errors, AuthoringSink sink);
// public void HandleReferencedCompilationUpdate(System.Compiler.UpdateSpecification updateSpecification, System.Compiler.MemberList changedMembers){ // } // public virtual bool CompileIfNeeded(AuthoringSink sink){ // if (sink == null) return true; // System.Compiler.ErrorNodeList errors = new System.Compiler.ErrorNodeList(); // XmlElement config = this.GetActiveConfiguration(); // Project project = this.GetCompilerProject(config, errors); // if (this.ProcessErrors(sink, errors)) return true; // if (project == null) return false; // if (project.Compilation == null || project.Compilation.TargetModule.IsNormalized) return false; // System.Compiler.CompilationList referencedCompilations = this.GetReferencedCompilations(config, errors); // if (this.ProcessErrors(sink, errors)) return true; // for (int i = 0, n = referencedCompilations == null ? 0 : referencedCompilations.Length; i < n; i++){ // System.Compiler.Compilation rcomp = referencedCompilations[i]; // if (rcomp == null) continue; // if (rcomp.TargetModule == null || rcomp.TargetModule.IsNormalized) continue; // return false; //Caller will eventually compile the referenced compilation // } // //At this point all the compilations referenced by this one have been compiled already // this.CompileProject(project, errors); // this.ProcessErrors(sink, errors); // return true; // } public virtual bool ProcessErrors(AuthoringSink sink, System.Compiler.ErrorNodeList errors) { if (sink == null) { Debug.Assert(false); return true; } if (errors == null || errors.Length <= 0) return false; for (int i = 0, n = errors.Length; i < n; i++) sink.AddError(errors[i]); return true; }
public virtual Microsoft.VisualStudio.Package.AuthoringScope ParseSource(string text, int line, int col, string fname, Microsoft.VisualStudio.Package.AuthoringSink aSink, Microsoft.VisualStudio.Package.ParseReason reason){ System.Compiler.AuthoringSink scAsink = new AuthoringSink(aSink); System.Compiler.AuthoringScope scAuthScope = this.scLanguageService.ParseSource(text, line, col, fname, scAsink, (System.Compiler.ParseReason)reason); return new AuthoringScope(scAuthScope, this.glyphProvider); }
public PythonSink(AuthoringSink authoringSink) { this.authoringSink = authoringSink; }