private void addGlobalMember(XTypeMember member) { member.File = this._file; member.Parent = _globalType; _globalType.AddMember(member); this._currentMethod = member; }
public override void EnterMethod([NotNull] XSharpParser.MethodContext context) { Kind kind = Kind.Method; if (context.Name.Contains(":Access")) { kind = Kind.Access; } else if (context.Name.Contains(":Assign")) { kind = Kind.Assign; } // var tokens = context.Modifiers?._Tokens; XTypeMember newMethod = new XTypeMember(context.Id.GetText(), kind, decodeModifiers(tokens), decodeVisibility(tokens), new TextRange(context), new TextInterval(context), (context.Type == null) ? "Void" : context.Type.GetText(), isStatic(tokens)); // addParameters(context.Params, newMethod); addMember(newMethod); }
public void AddMember(XTypeMember member) { lock (_members) { _members.Add(member); } }
public CompletionType(XElement element) { //throw new NotImplementedException(); this._file = element.File; if (element is XType) { this._xtype = (XType)element; } else { if (element is XTypeMember) { XTypeMember member = element as XTypeMember; CheckType(member.TypeName, member.File, member.Parent.NameSpace); } else if (element.Parent is XType) { this._xtype = element.Parent as XType; } else { XTypeMember member = element.Parent as XTypeMember; if (member != null) { CheckType(member.TypeName, member.File, member.Parent.NameSpace); } } } }
public override void EnterProperty([NotNull] XSharpParser.PropertyContext context) { String name = ""; // if (context.Id != null) { name = context.Id.GetText(); } if (context.SELF() != null) { name = context.SELF()?.GetText(); } var tokens = context.Modifiers?._Tokens; XTypeMember newMethod = new XTypeMember(name, Kind.Property, decodeModifiers(tokens), decodeVisibility(tokens), new TextRange(context), new TextInterval(context), (context.Type == null) ? "Void" : context.Type.GetText(), isStatic(tokens)); // addParameters(context.Params, newMethod); // addMember(newMethod); }
public override void EnterEnummember([NotNull] XSharpParser.EnummemberContext context) { XTypeMember newMember = new XTypeMember(context.Id.GetText(), Kind.EnumMember, Modifiers.None, Modifiers.None, new TextRange(context), new TextInterval(context), "", false); // addMember(newMember); }
public override void EnterProcedure([NotNull] XSharpParser.ProcedureContext context) { var tokens = context.Modifiers?._Tokens; XTypeMember newMethod = new XTypeMember(context.Id.GetText(), Kind.Procedure, decodeModifiers(tokens), decodeVisibility(tokens), new TextRange(context), new TextInterval(context), false); // addParameters(context.Params, newMethod); addGlobalMember(newMethod); }
public override void ExitVoglobal([NotNull] XSharpParser.VoglobalContext context) { foreach (var member in _classVars) { // convert from classvars to voglobal var newMember = new XTypeMember(member.Name, Kind.VOGlobal, member.Modifiers, member.Visibility, member.Range, member.Interval, member.TypeName, _currentVarStatic); addGlobalMember(newMember); } _classVars.Clear(); endMember(context); }
public override void EnterVostructmember([NotNull] XSharpParser.VostructmemberContext context) { XTypeMember newMember = new XTypeMember(context.Id.GetText(), Kind.Field, Modifiers.Public, Modifiers.Public, new TextRange(context), new TextInterval(context), false); // // Todo additional properties ? newMember.IsArray = context.Dim != null; addMember(newMember); }
public override void EnterDestructor([NotNull] XSharpParser.DestructorContext context) { var tokens = context.Modifiers?._Tokens; XTypeMember newMethod = new XTypeMember("Destructor", Kind.Destructor, decodeModifiers(tokens), decodeVisibility(tokens), new TextRange(context), new TextInterval(context), "Void", false); // addParameters(context.Params, newMethod); addMember(newMethod); }
public CompletionType(XTypeMember element) { //throw new NotImplementedException(); this._file = element.File; if (element.Kind.HasReturnType()) { // lookup type from Return type CheckType(element.TypeName, element.File, element.Parent.NameSpace); } else { this._xtype = element.Parent as XType; } }
public override void EnterEvent_([NotNull] XSharpParser.Event_Context context) { var tokens = context.Modifiers?._Tokens; XTypeMember newMethod = new XTypeMember(context.ShortName, Kind.Event, decodeModifiers(tokens), decodeVisibility(tokens), new TextRange(context), new TextInterval(context), context.ReturnType == null ? "Void" : context.ReturnType.GetText(), isStatic(tokens)); // addParameters(context.Params, newMethod); addMember(newMethod); }
public override void EnterFunction([NotNull] XSharpParser.FunctionContext context) { var tokens = context.Modifiers?._Tokens; XTypeMember newMethod = new XTypeMember(context.Id.GetText(), Kind.Function, decodeModifiers(tokens), decodeVisibility(tokens), new TextRange(context), new TextInterval(context), (context.Type == null) ? "Void" : context.Type.GetText(), isStatic(tokens)); // addParameters(context.Params, newMethod); addGlobalMember(newMethod); }
// Delegate is strictly a type but handled as a GLobal method because it has parameters public override void EnterDelegate_([NotNull] XSharpParser.Delegate_Context context) { var tokens = context.Modifiers?._Tokens; XTypeMember newMethod = new XTypeMember(context.Id.GetText(), Kind.Delegate, decodeModifiers(tokens), decodeVisibility(tokens), new TextRange(context), new TextInterval(context), isStatic(tokens)); // // Todo additional properties ? addParameters(context.Params, newMethod); addGlobalMember(newMethod); }
private void addParameters(IList <XSharpParser.ParameterContext> ctxtParams, XTypeMember newMethod) { if (ctxtParams != null) { foreach (XSharpParser.ParameterContext param in ctxtParams) { XVariable var = new XVariable(newMethod, param.Id?.GetText(), Kind.Parameter, Modifiers.Public, new TextRange(param), new TextInterval(param), param.Type?.GetText(), true); var.File = this._file; // newMethod.Parameters.Add(var); } } }
private void addMember(XTypeMember member) { var type = this.currentType; member.File = this._file; if (type != null) { member.Parent = type; type.AddMember(member); this._currentMethod = member; } if (ModelWalker.IsSuspended && System.Threading.Thread.CurrentThread.IsBackground) { System.Threading.Thread.Sleep(100); } }
public override void EnterVodefine([NotNull] XSharpParser.VodefineContext context) { var tokens = context.Modifiers?._Tokens; XTypeMember newMethod = new XTypeMember(context.ShortName, Kind.VODefine, decodeModifiers(tokens), decodeVisibility(tokens), new TextRange(context), new TextInterval(context), context.ReturnType == null ? "Void" : context.ReturnType.GetText(), isStatic(tokens)); // if (context.Expr != null) { newMethod.Suffix = " := " + context.Expr.GetText(); } addGlobalMember(newMethod); }
public CompletionType(XVariable var, string defaultNS) { // We know the context // var.Parent // We know the Type Name // var.TypeName // We need to lookup for the XType or System.Type // To check, we will need to know also "imported" types XTypeMember member = var.Parent as XTypeMember; this._file = var.File; if (member != null) { if (!String.IsNullOrEmpty(member.Parent.NameSpace)) { defaultNS = member.Parent.NameSpace; } CheckType(var.TypeName, member.File, defaultNS); } }
internal QuickInfoTypeMember(XSharpModel.XTypeMember tm) { this.typeMember = tm; }
internal QuickInfoTypeMember(XSharpModel.XTypeMember tm, Brush kw, Brush txt) : base(kw, txt) { this.typeMember = tm; }
public override void EnterClassVarList([NotNull] XSharpParser.ClassVarListContext context) { XSharpParser.ClassVarListContext current = (XSharpParser.ClassVarListContext)context; // // structure is: /* * classvars : (Attributes=attributes)? (Modifiers=classvarModifiers)? Vars=classVarList eos * ; * * classVarList : Var+=classvar (COMMA Var+=classvar)* (As=(AS | IS) DataType=datatype)? * ; * * classvar : (Dim=DIM)? Id=identifier (LBRKT ArraySub=arraysub RBRKT)? (ASSIGN_OP Initializer=expression)? * ; */ // we want to include the stop position of the datatype in the classvar // so we set the range to the whole classvarlist var parent = context.Parent as XSharpParserRuleContext; int count, currentVar; count = current._Var.Count; currentVar = 0; foreach (var varContext in current._Var) { // var mods = _currentVarStatic ? Modifiers.Static : Modifiers.None; // when many variables then the first one is from the start of the line until the // end of its name, and the others start with the start of their name // the last one finishes at the end of the line currentVar += 1; var start = parent.Start; // LOCAL keyword or GLOBAL keyword var stop = current.Stop; // end of this line (datatype clause) if (currentVar > 1) { start = varContext.Start; } if (currentVar < count) // end at this variable name { stop = varContext.Stop; } var interval = new TextInterval(start.StartIndex, stop.StopIndex); string typeName = current.DataType != null?current.DataType.GetText() : "USUAL"; XTypeMember newClassVar = new XTypeMember(varContext.Id.GetText(), Kind.Field, mods, this._currentVarVisibility, new TextRange(start.Line, start.Column, stop.Line, stop.Column + stop.Text.Length), interval, typeName, _currentVarStatic); newClassVar.File = this._file; newClassVar.IsArray = varContext.Dim != null; // bool bAdd = true; // Suppress classvars generated by errors in the source if (_errors != null) { foreach (var err in _errors) { if (err.Span.Start.Line == newClassVar.Range.StartLine - 1) { bAdd = false; } } } if (bAdd) { this._classVars.Add(newClassVar); } } }
public void AugmentQuickInfoSession(IQuickInfoSession session, IList <object> qiContent, out ITrackingSpan applicableToSpan) { applicableToSpan = null; if (XSharpProjectPackage.Instance.DebuggerIsRunning) { return; } try { XSharpModel.ModelWalker.Suspend(); var package = XSharp.Project.XSharpProjectPackage.Instance; var optionsPage = package.GetIntellisenseOptionsPage(); if (optionsPage.DisableQuickInfo) { return; } // Map the trigger point down to our buffer. SnapshotPoint?subjectTriggerPoint = session.GetTriggerPoint(_subjectBuffer.CurrentSnapshot); if (!subjectTriggerPoint.HasValue) { return; } ITextSnapshot currentSnapshot = subjectTriggerPoint.Value.Snapshot; WriteOutputMessage($"Triggerpoint: {subjectTriggerPoint.Value.Position}"); if ((subjectTriggerPoint.Value.Position == lastTriggerPoint) && (lastVersion == currentSnapshot.Version.VersionNumber)) { if (lastHelp != null) { var description = new TextBlock(); description.Inlines.AddRange(lastHelp); qiContent.Add(description); if (lastxmldoc != null) { qiContent.Add(lastxmldoc); } WriteOutputMessage($"Return last help content: {lastHelp}"); } if (lastSpan != null) { applicableToSpan = lastSpan; } return; } // We don't want to lex the buffer. So get the tokens from the last lex run // and when these are too old, then simply bail out var tokens = _subjectBuffer.GetTokens(); if (tokens != null) { if (tokens.SnapShot.Version != currentSnapshot.Version) { return; } } lastTriggerPoint = subjectTriggerPoint.Value.Position; //look for occurrences of our QuickInfo words in the span ITextStructureNavigator navigator = _provider.NavigatorService.GetTextStructureNavigator(_subjectBuffer); TextExtent extent = navigator.GetExtentOfWord(subjectTriggerPoint.Value); string searchText = extent.Span.GetText(); // First, where are we ? int caretPos = subjectTriggerPoint.Value.Position; int lineNumber = subjectTriggerPoint.Value.GetContainingLine().LineNumber; var snapshot = session.TextView.TextBuffer.CurrentSnapshot; if (_file == null) { return; } // Then, the corresponding Type/Element if possible IToken stopToken; //ITokenStream tokenStream; XSharpModel.XTypeMember member = XSharpLanguage.XSharpTokenTools.FindMember(lineNumber, _file); XSharpModel.XType currentNamespace = XSharpLanguage.XSharpTokenTools.FindNamespace(caretPos, _file); // adjust caretpos, for other completions we need to stop before the caret. Now we include the caret List <String> tokenList = XSharpLanguage.XSharpTokenTools.GetTokenList(caretPos + 1, lineNumber, tokens.TokenStream, out stopToken, true, _file, false, member); // Check if we can get the member where we are //if (tokenList.Count > 1) //{ // tokenList.RemoveRange(0, tokenList.Count - 1); //} // LookUp for the BaseType, reading the TokenList (From left to right) XSharpLanguage.CompletionElement gotoElement; String currentNS = ""; if (currentNamespace != null) { currentNS = currentNamespace.Name; } XSharpModel.CompletionType cType = XSharpLanguage.XSharpTokenTools.RetrieveType(_file, tokenList, member, currentNS, stopToken, out gotoElement, snapshot, lineNumber, _file.Project.Dialect); // // if ((gotoElement != null) && (gotoElement.IsInitialized)) { IClassificationType kwType = _registry.GetClassificationType("keyword"); IClassificationFormatMap fmap = _formatMap.GetClassificationFormatMap(category: "text"); Microsoft.VisualStudio.Text.Formatting.TextFormattingRunProperties kwFormat = fmap.GetTextProperties(kwType); kwType = _registry.GetClassificationType("text"); fmap = _formatMap.GetClassificationFormatMap(category: "text"); Microsoft.VisualStudio.Text.Formatting.TextFormattingRunProperties txtFormat = fmap.GetTextProperties(kwType); // // Ok, find it ! Let's go ;) applicableToSpan = currentSnapshot.CreateTrackingSpan ( extent.Span.Start, searchText.Length, SpanTrackingMode.EdgeInclusive ); if (gotoElement.XSharpElement != null) { if (gotoElement.XSharpElement.Kind == XSharpModel.Kind.Constructor) { if (gotoElement.XSharpElement.Parent != null) { var xtype = gotoElement.XSharpElement.Parent as XType; var qitm = new QuickInfoTypeAnalysis(xtype, kwFormat.ForegroundBrush, txtFormat.ForegroundBrush); var description = new TextBlock(); description.Inlines.AddRange(qitm.WPFDescription); qiContent.Add(description); } } else if (gotoElement.XSharpElement is XSharpModel.XTypeMember) { QuickInfoTypeMember qitm = new QuickInfoTypeMember((XSharpModel.XTypeMember)gotoElement.XSharpElement, kwFormat.ForegroundBrush, txtFormat.ForegroundBrush); var description = new TextBlock(); description.Inlines.AddRange(qitm.WPFDescription); qiContent.Add(description); } else if (gotoElement.XSharpElement is XSharpModel.XVariable) { QuickInfoVariable qitm = new QuickInfoVariable((XSharpModel.XVariable)gotoElement.XSharpElement, kwFormat.ForegroundBrush, txtFormat.ForegroundBrush); var description = new TextBlock(); description.Inlines.AddRange(qitm.WPFDescription); qiContent.Add(description); } else if (gotoElement.XSharpElement is XSharpModel.XType) { var xtype = gotoElement.XSharpElement as XType; var qitm = new QuickInfoTypeAnalysis(xtype, kwFormat.ForegroundBrush, txtFormat.ForegroundBrush); var description = new TextBlock(); description.Inlines.AddRange(qitm.WPFDescription); qiContent.Add(description); } else { var description = new TextBlock(); Run temp; temp = new Run(gotoElement.XSharpElement.Description); temp.Foreground = txtFormat.ForegroundBrush; // description.Inlines.Add(temp); qiContent.Add(description); } } else if (gotoElement.SystemElement is TypeInfo) { var ti = gotoElement.SystemElement as TypeInfo; string xmldoc = XSharpXMLDocMember.GetTypeSummary(ti, member.File.Project); QuickInfoTypeAnalysis analysis = new QuickInfoTypeAnalysis(ti, kwFormat.ForegroundBrush, txtFormat.ForegroundBrush); var description = new TextBlock(); description.Inlines.AddRange(analysis.WPFDescription); qiContent.Add(description); if (xmldoc != null) { qiContent.Add(xmldoc); } } else { // This works with System.MemberInfo AND QuickInfoMemberAnalysis analysis = null; if (gotoElement.SystemElement is MemberInfo) { string xmldoc = XSharpXMLDocMember.GetMemberSummary(gotoElement.SystemElement, member.File.Project); analysis = new QuickInfoMemberAnalysis(gotoElement.SystemElement, kwFormat.ForegroundBrush, txtFormat.ForegroundBrush); if (analysis.IsInitialized) { if ((analysis.Kind == XSharpModel.Kind.Constructor) && (cType != null) && (cType.SType != null)) { QuickInfoTypeAnalysis typeAnalysis; typeAnalysis = new QuickInfoTypeAnalysis(cType.SType.GetTypeInfo(), kwFormat.ForegroundBrush, txtFormat.ForegroundBrush); if (typeAnalysis.IsInitialized) { var description = new TextBlock(); description.Inlines.AddRange(typeAnalysis.WPFDescription); qiContent.Add(description); } } else { var description = new TextBlock(); description.Inlines.AddRange(analysis.WPFDescription); qiContent.Add(description); } if (xmldoc != null) { qiContent.Add(xmldoc); } } } } if (qiContent.Count > 0) { TextBlock description; description = qiContent[0] as TextBlock; if (qiContent.Count > 1) { lastxmldoc = qiContent[1] as String; } else { lastxmldoc = null; } if (description != null) { lastHelp = new Inline[description.Inlines.Count]; description.Inlines.CopyTo(lastHelp, 0); lastSpan = applicableToSpan; lastVersion = currentSnapshot.Version.VersionNumber; WriteOutputMessage($"Found new help content: {lastHelp}"); } } return; } } catch (Exception ex) { XSharpProjectPackage.Instance.DisplayOutPutMessage("XSharpQuickInfo.AugmentQuickInfoSession failed : "); XSharpProjectPackage.Instance.DisplayException(ex); } finally { XSharpModel.ModelWalker.Resume(); } }
protected virtual void endMember(LanguageService.SyntaxTree.ParserRuleContext context) { _currentMethod = null; }
internal QuickInfoTypeMember(XSharpModel.XTypeMember tm, Brush kw, Brush txt) { this.typeMember = tm; this.kwBrush = kw; this.txtBrush = txt; }
public void AugmentSignatureHelpSession(ISignatureHelpSession session, IList <ISignature> signatures) { try { XSharpProjectPackage.Instance.DisplayOutPutMessage("XSharpSignatureHelpSource.AugmentSignatureHelpSession()"); XSharpModel.ModelWalker.Suspend(); ITextSnapshot snapshot = m_textBuffer.CurrentSnapshot; int position = session.GetTriggerPoint(m_textBuffer).GetPosition(snapshot); int start = (int)session.Properties["Start"]; int length = (int)session.Properties["Length"]; var comma = (bool)session.Properties["Comma"]; var file = (XFile)session.Properties["File"]; m_applicableToSpan = m_textBuffer.CurrentSnapshot.CreateTrackingSpan( new Span(start, length), SpanTrackingMode.EdgeInclusive, 0); object elt = session.Properties["Element"]; m_session = session; if (elt is XSharpModel.XElement) { XSharpModel.XElement element = elt as XSharpModel.XElement; // if (elt is XSharpModel.XTypeMember) { XSharpModel.XTypeMember xMember = elt as XSharpModel.XTypeMember; signatures.Add(CreateSignature(m_textBuffer, null, xMember.Prototype, "", ApplicableToSpan, comma, xMember.Kind == XSharpModel.Kind.Constructor, file)); List <XSharpModel.XTypeMember> namesake = xMember.Namesake(); foreach (var member in namesake) { signatures.Add(CreateSignature(m_textBuffer, null, member.Prototype, "", ApplicableToSpan, comma, member.Kind == XSharpModel.Kind.Constructor, file)); } // } else { // Type ?? signatures.Add(CreateSignature(m_textBuffer, null, element.Prototype, "", ApplicableToSpan, comma, false, file)); } // why not ? int paramCount = int.MaxValue; foreach (ISignature sig in signatures) { if (sig.Parameters.Count < paramCount) { paramCount = sig.Parameters.Count; } } // m_textBuffer.Changed += new EventHandler <TextContentChangedEventArgs>(OnSubjectBufferChanged); } else if (elt is System.Reflection.MemberInfo) { System.Reflection.MemberInfo element = elt as System.Reflection.MemberInfo; XSharpLanguage.MemberAnalysis analysis = new XSharpLanguage.MemberAnalysis(element); if (analysis.IsInitialized) { signatures.Add(CreateSignature(m_textBuffer, element, analysis.Prototype, "", ApplicableToSpan, comma, (element.MemberType == MemberTypes.Constructor), file)); // Any other member with the same name in the current Type and in the Parent(s) ? SystemNameSake(element.DeclaringType, signatures, element.Name, analysis.Prototype, comma, file); // m_textBuffer.Changed += new EventHandler <TextContentChangedEventArgs>(OnSubjectBufferChanged); } } session.Dismissed += OnSignatureHelpSessionDismiss; } catch (Exception ex) { XSharpProjectPackage.Instance.DisplayOutPutMessage("XSharpSignatureHelpSource.AugmentSignatureHelpSession Exception failed "); XSharpProjectPackage.Instance.DisplayException(ex); } finally { XSharpModel.ModelWalker.Resume(); } }