/// <summary> /// Search the item under the caret. /// If a Field, it is stored in _memberentity /// </summary> /// <returns>True if the caret is placed on a Field</returns> private bool SearchField() { _memberEntity = null; if (m_textBuffer.Properties == null) { return(false); } // SnapshotPoint caret = this.m_textView.Caret.Position.BufferPosition; var location = this.m_textBuffer.FindLocation(caret); CompletionState state; var tokenList = XSharpTokenTools.GetTokensUnderCursor(location, out state); // LookUp for the BaseType, reading the TokenList (From left to right) var lookupresult = new List <IXSymbol>(); lookupresult.AddRange(XSharpLookup.RetrieveElement(location, tokenList, state, out var notProcessed, true)); // if (lookupresult.Count > 0) { var element = lookupresult[0]; if (element is XSourceMemberSymbol mem && mem.Kind == Kind.Field) { _memberEntity = mem; return(true); } } return(false); }
internal static XSharpSearchLocation FindLocation(this ITextBuffer buffer, SnapshotPoint point) { if (buffer == null) { return(null); } int line = point.GetContainingLine().LineNumber; var file = buffer.GetFile(); var snapshot = buffer.CurrentSnapshot; var member = XSharpLookup.FindMember(line, file); var ns = XSharpTokenTools.FindNamespace(point, file); string currentNS = ""; if (ns != null) { currentNS = ns.FullName; } var location = new XSharpSearchLocation(file, member, snapshot, line, point, currentNS); return(location); }
public void AugmentCompletionSession(ICompletionSession session, IList <CompletionSet> completionSets) { WriteOutputMessage("-->> AugmentCompletionSessions"); try { if (XSettings.DisableCodeCompletion) { return; } XSharpModel.ModelWalker.Suspend(); if (_disposed) { throw new ObjectDisposedException("XSharpCompletionSource"); } _showTabs = XSettings.EditorCompletionListTabs; _keywordsInAll = XSettings.EditorKeywordsInAll; // Where does the StartSession has been triggered ? ITextSnapshot snapshot = _buffer.CurrentSnapshot; var triggerPoint = (SnapshotPoint)session.GetTriggerPoint(snapshot); if (triggerPoint == null) { return; } // What is the character were it starts ? var line = triggerPoint.GetContainingLine(); //var triggerposinline = triggerPoint.Position - 2 - line.Start; //var afterChar = line.GetText()[triggerposinline]; //if (afterChar == ' ' || afterChar == '\t') // return; // The "parameters" coming from CommandFilter uint cmd = 0; char typedChar = '\0'; bool autoType = false; session.Properties.TryGetProperty(XsCompletionProperties.Command, out cmd); VSConstants.VSStd2KCmdID nCmdId = (VSConstants.VSStd2KCmdID)cmd; session.Properties.TryGetProperty(XsCompletionProperties.Char, out typedChar); session.Properties.TryGetProperty(XsCompletionProperties.AutoType, out autoType); bool showInstanceMembers = (typedChar == ':') || ((typedChar == '.') && _file.Project.ParseOptions.AllowDotForInstanceMembers); //////////////////////////////////////////// // SnapshotSpan lineSpan = new SnapshotSpan(line.Start, line.Length); SnapshotPoint caret = triggerPoint; var tagAggregator = aggregator.CreateTagAggregator <IClassificationTag>(_buffer); var tags = tagAggregator.GetTags(lineSpan); IMappingTagSpan <IClassificationTag> lastTag = null; foreach (var tag in tags) { //tagList.Add(tag); SnapshotPoint ptStart = tag.Span.Start.GetPoint(_buffer, PositionAffinity.Successor).Value; SnapshotPoint ptEnd = tag.Span.End.GetPoint(_buffer, PositionAffinity.Successor).Value; if ((ptStart != null) && (ptEnd != null)) { if (caret.Position >= ptEnd) { lastTag = tag; } } } if (lastTag != null) { var name = lastTag.Tag.ClassificationType.Classification.ToLower(); // No Intellisense in Comment if (name == "comment" || name == "xsharp.text") { return; } } //////////////////////////////////////////// SnapshotPoint start = triggerPoint; var applicableTo = snapshot.CreateTrackingSpan(new SnapshotSpan(start, triggerPoint), SpanTrackingMode.EdgeInclusive); // if (_file == null) { // Uhh !??, Something went wrong return; } // The Completion list we are building XCompletionList compList = new XCompletionList(_file); XCompletionList kwdList = new XCompletionList(_file); IXTypeSymbol type = null; if (session.Properties.ContainsProperty(XsCompletionProperties.Type)) { type = (IXTypeSymbol)session.Properties[XsCompletionProperties.Type]; } // Start of Process string filterText = ""; // Check if we can get the member where we are // Standard TokenList Creation (based on colon Selector ) bool includeKeywords; session.Properties.TryGetProperty(XsCompletionProperties.IncludeKeywords, out includeKeywords); CompletionState state; var member = session.TextView.FindMember(triggerPoint); var location = session.TextView.TextBuffer.FindLocation(triggerPoint); if (location == null) { return; } var tokenList = XSharpTokenTools.GetTokenList(location, out state, includeKeywords); // We might be here due to a COMPLETEWORD command, so we have no typedChar // but we "may" have a incomplete word like System.String.To // Try to Guess what TypedChar could be if (typedChar == '\0' && autoType) { if (tokenList.Count > 0) { string extract = tokenList[tokenList.Count - 1].Text; typedChar = extract[extract.Length - 1]; if ((typedChar != '.') && (typedChar != ':')) { if (tokenList.Count == 1) { // filterText = tokenList[0].Text; int dotPos = extract.LastIndexOf("."); if (dotPos > -1) { string startToken = extract.Substring(0, dotPos); filterText = extract.Substring(dotPos + 1); typedChar = '.'; tokenList[0].Text = startToken + "."; } } else { // So, we get the last Token as a Filter filterText = tokenList[tokenList.Count - 1].Text; } // Include the filter as the text to replace start -= filterText.Length; applicableTo = snapshot.CreateTrackingSpan(new SnapshotSpan(start, triggerPoint), SpanTrackingMode.EdgeInclusive); } } } bool dotSelector = (typedChar == '.'); // TODO: Based on the Project.Settings, we should add the Vulcan.VO namespace int tokenType = XSharpLexer.UNRECOGNIZED; var symbol = XSharpLookup.RetrieveElement(location, tokenList, CompletionState.General, out var notProcessed).FirstOrDefault(); var memberName = ""; // Check for members, locals etc and convert the type of these to IXTypeSymbol if (symbol != null) { if (symbol is IXTypeSymbol xtype) { type = xtype; } else if (symbol is IXMemberSymbol xmember) { var typeName = xmember.TypeName; if (xmember is XSourceMemberSymbol sourcemem) { type = sourcemem.File.FindType(typeName); } else { type = location.FindType(typeName); } memberName = xmember.Name; } else if (symbol is IXVariableSymbol xvar) { var typeName = ""; if (xvar is XSourceUndeclaredVariableSymbol) { type = null; state = CompletionState.General; filterText = xvar.Name; } else if (xvar is XSourceVariableSymbol sourcevar) { typeName = sourcevar.TypeName; if (sourcevar.ResolvedType != null) { type = sourcevar.ResolvedType; typeName = type.FullName; } else { type = sourcevar.File.FindType(typeName); } } else if (xvar is XPEParameterSymbol par) { typeName = par.TypeName; type = location.FindType(typeName); } memberName = xvar.Name; } else if (symbol.Kind == Kind.Keyword) { filterText = symbol.Name; } else if (symbol.Kind == Kind.Namespace) { filterText = symbol.Name + "."; } if (type != null) { switch (type.FullName) { case XSharpTypeNames.XSharpUsual: case XSharpTypeNames.VulcanUsual: type = null; break; } } session.Properties[XsCompletionProperties.Type] = type; } if (type == null) { showInstanceMembers = false; } if ((dotSelector || state != CompletionState.None)) { if (string.IsNullOrEmpty(filterText) && type == null) { filterText = helpers.TokenListAsString(tokenList); if (filterText.Length > 0 && !filterText.EndsWith(".") && state != CompletionState.General) { filterText += "."; } } if (type == null && state.HasFlag(CompletionState.Namespaces)) { helpers.AddNamespaces(compList, location, filterText); } if (type == null && state.HasFlag(CompletionState.Interfaces)) { helpers.AddTypeNames(compList, location, filterText, afterDot: true, onlyInterfaces: true); helpers.AddXSharpKeywordTypeNames(kwdList, filterText); } if (type == null && state.HasFlag(CompletionState.Types)) { helpers.AddTypeNames(compList, location, filterText, afterDot: true, onlyInterfaces: false); helpers.AddXSharpKeywordTypeNames(kwdList, filterText); } if (state.HasFlag(CompletionState.StaticMembers)) { if (type != null && symbol is IXTypeSymbol) { // First we need to keep only the text AFTER the last dot int dotPos = filterText.LastIndexOf('.'); filterText = filterText.Substring(dotPos + 1, filterText.Length - dotPos - 1); helpers.BuildCompletionListMembers(location, compList, type, Modifiers.Public, true, filterText); } } if (type.IsVoStruct() && typedChar == '.') { // vostruct or union in other assembly showInstanceMembers = true; filterText = ""; } if (state.HasFlag(CompletionState.InstanceMembers)) { showInstanceMembers = true; filterText = ""; } } if (showInstanceMembers) { // Member call if (type != null) { Modifiers visibleAs = Modifiers.Public; if (type is XSourceTypeSymbol sourceType && sourceType.File.Project == member.File.Project) { visibleAs = Modifiers.Internal; switch (memberName.ToLower()) { case "self": case "this": visibleAs = Modifiers.Private; break; case "super": visibleAs = Modifiers.Protected; break; default: if (member.ParentName == type.FullName) { visibleAs = Modifiers.Private; } break; } } // Now, Fill the CompletionList with the available members, from there helpers.BuildCompletionListMembers(location, compList, type, visibleAs, false, filterText); } } // if (!dotSelector && !showInstanceMembers) { switch (tokenType) { case XSharpLexer.USING: // It can be a namespace helpers.AddNamespaces(compList, location, filterText); break; case XSharpLexer.AS: case XSharpLexer.IS: case XSharpLexer.REF: case XSharpLexer.INHERIT: // It can be a namespace helpers.AddNamespaces(compList, location, filterText); // It can be Type, FullyQualified // we should also walk all the USINGs, and the current Namespace if any, to search Types helpers.AddTypeNames(compList, location, filterText, onlyInterfaces: false, afterDot: false); // helpers.AddXSharpKeywordTypeNames(kwdList, filterText); break; case XSharpLexer.IMPLEMENTS: // It can be a namespace helpers.AddNamespaces(compList, location, filterText); helpers.AddTypeNames(compList, location, filterText, onlyInterfaces: true, afterDot: false); break; default: //if (state.HasFlag(CompletionState.General)) //{ // filterText = notProcessed; // helpers.AddGenericCompletion(compList, location, filterText); //} break; } } if ((kwdList.Count > 0) && _keywordsInAll /*&& XSettings.CompleteKeywords*/) { foreach (var item in kwdList.Values) { compList.Add(item); } } // Sort in alphabetical order // and put in the SelectionList var values = compList.Values; // Create the All Tab completionSets.Add(new CompletionSet("All", "All", applicableTo, values, Enumerable.Empty <Completion>())); if (_showTabs) { helpers.BuildTabs(compList, completionSets, applicableTo); } // Keywords are ALWAYS in a separate Tab anyway if (kwdList.Count > 0) { completionSets.Add(new CompletionSet("Keywords", "Keywords", applicableTo, kwdList.Values, Enumerable.Empty <Completion>())); } } catch (Exception ex) { XSettings.LogException(ex, "AugmentCompletionSessions failed"); } finally { XSharpModel.ModelWalker.Resume(); } WriteOutputMessage("<<-- AugmentCompletionSessions"); }
internal bool StartSignatureSession(bool comma, IXTypeSymbol type = null, string methodName = null, char triggerchar = '\0') { WriteOutputMessage("StartSignatureSession()"); if (_signatureSession != null) { return(false); } IXMemberSymbol currentElement = null; SnapshotPoint ssp = this._textView.Caret.Position.BufferPosition; if (triggerchar == '(' && ssp.Position < ssp.Snapshot.Length && ssp.GetChar() == ')') { ssp -= 1; } var location = _textView.FindLocation(ssp); if (location == null || location.Member == null) { return(false); } if (location.Member.Range.StartLine == location.LineNumber) { return(false); } var props = new XSharpSignatureProperties(location); props.triggerChar = triggerchar; props.triggerPosition = this._textView.Caret.Position.BufferPosition.Position; if (type != null && methodName != null) { var findStatic = triggerchar == '.'; currentElement = XSharpLookup.SearchMethod(location, type, methodName, Modifiers.Private, findStatic).FirstOrDefault(); } else { currentElement = findElementAt(comma, ssp, props); } if (currentElement == null) { return(false); } SnapshotPoint caret = _textView.Caret.Position.BufferPosition; ITextSnapshot caretsnapshot = caret.Snapshot; // if (_signatureBroker.IsSignatureHelpActive(_textView)) { _signatureSession = _signatureBroker.GetSessions(_textView)[0]; } else { _signatureSession = _signatureBroker.CreateSignatureHelpSession(_textView, caretsnapshot.CreateTrackingPoint(caret, PointTrackingMode.Positive), true); } _signatureSession.Properties[typeof(XSharpSignatureProperties)] = props; if (location.Member.Kind.IsGlobalTypeMember()) { props.Visibility = Modifiers.Public; } else { props.Visibility = Modifiers.Protected; } _signatureSession.Dismissed += OnSignatureSessionDismiss; props.Element = currentElement; if (comma) { var tokenList = XSharpTokenTools.GetTokenListBeforeCaret(location, out var state); bool done = false; int nested = 0; for (int i = tokenList.Count - 1; i >= 0 && !done; i--) { var token = tokenList[i]; switch (token.Type) { case XSharpLexer.LPAREN: case XSharpLexer.LCURLY: case XSharpLexer.LBRKT: done = nested == 0; if (done) { props.Start = token.Position; props.Length = _textView.Caret.Position.BufferPosition.Position - token.Position; } nested -= 1; break; case XSharpLexer.RPAREN: case XSharpLexer.RCURLY: case XSharpLexer.RBRKT: nested += 1; break; } } } else { props.Start = ssp.Position; props.Length = _textView.Caret.Position.BufferPosition.Position - ssp.Position; } try { _signatureSession.Start(); } catch (Exception e) { XSettings.LogException(e, "Start Signature session failed:"); } // return(true); }
IXMemberSymbol findElementAt(bool comma, SnapshotPoint ssp, XSharpSignatureProperties props) { // when coming from the completion list then there is no need to check a lot of stuff // we can then simply lookup the method and that is it. // Also no need to filter on visibility since that has been done in the completionlist already ! // First, where are we ? var location = props.Location; // When we have a multi line source line this is the line where the open paren or open curly is if (location.Member != null && location.Member.Range.StartLine == ssp.GetContainingLine().LineNumber) { // if we are at the start of an entity then do not start a signature session return(null); } // Then, the corresponding Type/Element if possible // Check if we can get the member where we are var tokenList = XSharpTokenTools.GetTokenListBeforeCaret(location, out var state); // tokenlist may look like ID1 ( ID2 ( e1 , e2) // after the closing paren we come here and want to completely remove the ID2 ( e1, e2 ) part // when we have this ID1 ( e1 ) then there should be no parameter completion at all // The same for ID1 { e1 } // so we need to see if LPAREN / RPAREN is closed and if LCURLY / RCURLY is closed and if LBRKT / RBRKT is closed int nested = 0; var openTokens = new Stack <XSharpToken>(); for (int i = 0; i < tokenList.Count; i++) { var token = tokenList[i]; switch (token.Type) { case XSharpLexer.LPAREN: case XSharpLexer.LCURLY: case XSharpLexer.LBRKT: openTokens.Push(token); break; case XSharpLexer.RPAREN: if (openTokens.Count > 0 && openTokens.Peek().Type == XSharpLexer.LPAREN) { openTokens.Pop(); } break; case XSharpLexer.RCURLY: if (openTokens.Count > 0 && openTokens.Peek().Type == XSharpLexer.LCURLY) { openTokens.Pop(); } break; case XSharpLexer.RBRKT: if (openTokens.Count > 0 && openTokens.Peek().Type == XSharpLexer.LBRKT) { openTokens.Pop(); } break; case XSharpLexer.STRING_CONST: case XSharpLexer.INTERPOLATED_STRING_CONST: case XSharpLexer.CHAR_CONST: if (token.Position < location.Position && location.Position < token.Position + token.Text.Length) { // comma inside literal ! return(null); } break; } } if (openTokens.Count == 0) { tokenList.Clear(); } else { var pos = tokenList.IndexOf(openTokens.Peek()); if (pos >= 0) { tokenList.RemoveRange(pos + 1, tokenList.Count - pos - 1); } } if (comma) { // check to see if there is a lparen or lcurly before the comma bool done = false; nested = 0; while (tokenList.Count > 0 && !done) { var token = tokenList[tokenList.Count - 1]; bool delete = false; switch (token.Type) { case XSharpLexer.RPAREN: case XSharpLexer.RBRKT: case XSharpLexer.RCURLY: nested += 1; delete = true; break; case XSharpLexer.LBRKT: nested -= 1; delete = true; break; case XSharpLexer.LPAREN: case XSharpLexer.LCURLY: nested -= 1; if (nested < 0) { done = true; } else { delete = true; } break; default: delete = true; break; } if (delete) { tokenList.RemoveAt(tokenList.Count - 1); } } } IXMemberSymbol currentElement = null; // We don't care of the corresponding Type, we are looking for the currentElement var element = XSharpLookup.RetrieveElement(location, tokenList, state, out var notProcessed, true).FirstOrDefault(); if (element is IXMemberSymbol mem) { currentElement = mem; if (currentElement.Kind == Kind.Constructor) { bool done = false; for (int i = tokenList.Count - 1; !done && i > 0; i--) { var token = tokenList[i]; switch (token.Type) { case XSharpLexer.LPAREN: case XSharpLexer.LCURLY: props.triggerToken = tokenList[i - 1].Text; break; } } } } else if (element is IXTypeSymbol xtype) { currentElement = xtype.Members.Where(m => m.Kind == Kind.Constructor).FirstOrDefault(); } return(currentElement); }
//static bool skipFirst = true; public async Task <QuickInfoItem> GetQuickInfoItemAsync(IAsyncQuickInfoSession session, CancellationToken cancellationToken) { if (XSettings.DebuggerIsRunning || XSettings.DisableQuickInfo) { await session.DismissAsync(); return(null); } var triggerPoint = session.GetTriggerPoint(_textBuffer.CurrentSnapshot); if (triggerPoint == null) { await session.DismissAsync(); return(null); } try { ModelWalker.Suspend(); var ssp = triggerPoint.Value; // Map the trigger point down to our buffer. ITextSnapshot currentSnapshot = ssp.Snapshot; bool abort = false; var tokens = _textBuffer.GetDocument(); if (tokens == null) { return(null); } if (cancellationToken.IsCancellationRequested) { return(null); } if (!abort) { WriteOutputMessage($"Triggerpoint: {triggerPoint.Value.Position}"); // 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 abort = tokens == null || tokens.SnapShot.Version != currentSnapshot.Version; } if (abort) { await session.DismissAsync(); return(null); } if (cancellationToken.IsCancellationRequested) { return(null); } var location = _textBuffer.FindLocation(ssp); CompletionState state; var tokenList = XSharpTokenTools.GetTokensUnderCursor(location, out state); // LookUp for the BaseType, reading the TokenList (From left to right) if (cancellationToken.IsCancellationRequested) { return(null); } var lookupresult = new List <IXSymbol>(); lookupresult.AddRange(XSharpLookup.RetrieveElement(location, tokenList, state, out var notProcessed, true)); var lastToken = tokenList.LastOrDefault(); // if (lookupresult.Count > 0) { var element = lookupresult[0]; var qiContent = new List <object>(); if (element.Kind == Kind.Constructor && lastToken?.Type != XSharpLexer.CONSTRUCTOR && lastToken?.Type != XSharpLexer.LPAREN) { if (element.Parent != null) { var xtype = element.Parent as IXTypeSymbol; var qitm = new XTypeAnalysis(xtype); AddImage(qiContent, qitm.Image); var description = new ClassifiedTextElement(qitm.WPFDescription); qiContent.Add(description); } } else if (element is IXMemberSymbol mem) { QuickInfoTypeMember qitm = new QuickInfoTypeMember(mem); AddImage(qiContent, qitm.Image); var description = new ClassifiedTextElement(qitm.WPFDescription); qiContent.Add(description); } else if (element is IXVariableSymbol var) { QuickInfoVariable qitm = new QuickInfoVariable(var); AddImage(qiContent, qitm.Image); var description = new ClassifiedTextElement(qitm.WPFDescription); qiContent.Add(description); } else if (element is IXTypeSymbol xtype) { var qitm = new XTypeAnalysis(xtype); AddImage(qiContent, qitm.Image); var description = new ClassifiedTextElement(qitm.WPFDescription); qiContent.Add(description); } else { var qitm = new XAnalysis(element); AddImage(qiContent, qitm.Image); var description = new ClassifiedTextElement(qitm.WPFDescription); qiContent.Add(description); } if (cancellationToken.IsCancellationRequested) { return(null); } var result = new ContainerElement(ContainerElementStyle.Wrapped, qiContent); var line = ssp.GetContainingLine(); var lineSpan = _textBuffer.CurrentSnapshot.CreateTrackingSpan(line.Extent, SpanTrackingMode.EdgeInclusive); return(new QuickInfoItem(lineSpan, result)); } } catch (Exception ex) { XSettings.LogException(ex, "XSharpQuickInfo.AugmentQuickInfoSession failed : "); } finally { ModelWalker.Resume(); } await session.DismissAsync(); return(null); }
internal static XSourceMemberSymbol FindMemberAtPosition(this ITextBuffer buffer, SnapshotPoint point) { var file = buffer.GetFile(); return(XSharpLookup.FindMemberAtPosition(point.Position, file)); }
internal static XSourceMemberSymbol FindMember(this ITextBuffer buffer, SnapshotPoint point) { var file = buffer.GetFile(); return(XSharpLookup.FindMember(point.GetContainingLine().LineNumber, file)); }
public void AugmentPeekSession(IPeekSession session, IList <IPeekableItem> peekableItems) { try { XSharpModel.ModelWalker.Suspend(); if (!string.Equals(session.RelationshipName, PredefinedPeekRelationships.Definitions.Name, StringComparison.OrdinalIgnoreCase)) { return; } // var tp = session.GetTriggerPoint(_textBuffer.CurrentSnapshot); if (!tp.HasValue) { return; } var triggerPoint = tp.Value; // LookUp for the BaseType, reading the TokenList (From left to right) var location = _textBuffer.FindLocation(triggerPoint); if (location == null) { return; } CompletionState state; var tokenList = XSharpTokenTools.GetTokensUnderCursor(location, out state); var result = new List <IXSymbol>(); result.AddRange(XSharpLookup.RetrieveElement(location, tokenList, state, out var notProcessed, true)); // if (result.Count > 0) { if (result[0] is XSourceSymbol symbol) { peekableItems.Add(new XSharpDefinitionPeekItem(symbol, _peekResultFactory)); } else if (result[0] is XPESymbol pesymbol) { XPETypeSymbol petype; if (pesymbol is XPETypeSymbol) { petype = (XPETypeSymbol)pesymbol; } else if (pesymbol is XPEMemberSymbol member) { petype = (XPETypeSymbol)member.Parent; } else { return; } var file = XSharpGotoDefinition.CreateFileForSystemType(petype, pesymbol); var entity = XSharpGotoDefinition.FindElementInFile(file, petype, pesymbol); if (entity != null) { peekableItems.Add(new XSharpDefinitionPeekItem(entity, _peekResultFactory)); } } } } catch (Exception ex) { XSettings.LogException(ex, "XSharpPeekItemSource.AugmentPeekSession failed : "); } finally { ModelWalker.Resume(); } }
internal static void GotoDefn(ITextView TextView) { try { if (XSettings.DisableGotoDefinition) { return; } var file = TextView.TextBuffer.GetFile(); if (file == null || file.XFileType != XFileType.SourceCode) { return; } WriteOutputMessage("CommandFilter.GotoDefn()"); ModelWalker.Suspend(); var snapshot = TextView.TextBuffer.CurrentSnapshot; // 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 = TextView.TextBuffer.GetDocument(); if (tokens != null) { if (tokens.SnapShot.Version != snapshot.Version) { return; } } string currentNS = TextView.FindNamespace(); var location = TextView.FindLocation(); var state = CompletionState.General | CompletionState.Types | CompletionState.Namespaces; var tokenList = XSharpTokenTools.GetTokensUnderCursor(location, out state); // LookUp for the BaseType, reading the TokenList (From left to right) var result = new List <IXSymbol>(); result.AddRange(XSharpLookup.RetrieveElement(location, tokenList, state, out var notProcessed)); // Microsoft.VisualStudio.Shell.ThreadHelper.ThrowIfNotOnUIThread(); if (result.Count > 0) { var element = result[0]; if (element is XSourceEntity source) { source.OpenEditor(); } else if (element is XPETypeSymbol petype) { GotoSystemType(TextView, petype, petype); } else if (element is XPEMemberSymbol pemember) { var petype2 = pemember.Parent as XPETypeSymbol; GotoSystemType(TextView, petype2, pemember); } return; } // if (tokenList.Count > 1) { // try again with just the last element in the list var token = tokenList[tokenList.Count - 1]; tokenList.Clear(); tokenList.Add(token); location = location.With(currentNS); result.AddRange(XSharpLookup.RetrieveElement(location, tokenList, state, out notProcessed)); } if (result.Count > 0) { var element = result[0]; if (element is XSourceEntity source) { source.OpenEditor(); } //else //{ // openInObjectBrowser(element.FullName); //} //return; } } catch (Exception ex) { XSettings.LogException(ex, "Goto failed"); } finally { ModelWalker.Resume(); } }
private void formatToken(ITextEdit editSession, int offSet, IToken token) { if (token.Channel == XSharpLexer.Hidden || token.Channel == XSharpLexer.PREPROCESSORCHANNEL || token.Type == XSharpLexer.TEXT_STRING_CONST) { return; } bool syncKeyword = false; // Some exceptions are (pseudo) functions. These should not be formatted switch (token.Type) { case XSharpLexer.UDC_KEYWORD: syncKeyword = XSettings.UDCKeywordCase; break; case XSharpLexer.NAMEOF: case XSharpLexer.SIZEOF: case XSharpLexer.TYPEOF: // these are keywords but should be excluded I think syncKeyword = false; break; case XSharpLexer.TRUE_CONST: case XSharpLexer.FALSE_CONST: case XSharpLexer.MACRO: case XSharpLexer.LOGIC_AND: case XSharpLexer.LOGIC_OR: case XSharpLexer.LOGIC_NOT: case XSharpLexer.LOGIC_XOR: case XSharpLexer.VO_AND: case XSharpLexer.VO_OR: case XSharpLexer.VO_NOT: case XSharpLexer.VO_XOR: syncKeyword = true; break; default: if (token.Type >= XSharpLexer.FIRST_NULL && token.Type <= XSharpLexer.LAST_NULL) { syncKeyword = true; } else if (XSharpLexer.IsKeyword(token.Type)) { syncKeyword = token.Text[0] != '#'; } break; } if (syncKeyword) { var keyword = token.Text; var transform = XSettings.FormatKeyword(keyword, _settings.KeywordCase); if (String.Compare(transform, keyword) != 0) { int startpos = offSet + token.StartIndex; editSession.Replace(startpos, transform.Length, transform); } } if (token.Type == XSharpLexer.ID && XSettings.IdentifierCase) { var identifier = token.CleanText(); var lineNumber = getCurrentLine(); var currentMember = _textView.FindMember(); // if (currentMember == null) { return; } IXVariableSymbol element = null; // Search in Parameters if (currentMember.Parameters != null) { element = currentMember.Parameters.Where(x => XSharpTokenTools.StringEquals(x.Name, identifier)).FirstOrDefault(); } if (element == null) { // then Locals var location = new XSharpSearchLocation(currentMember.File, currentMember, null, lineNumber); var locals = currentMember.GetLocals(location); if (locals != null) { element = locals.Where(x => XSharpTokenTools.StringEquals(x.Name, identifier)).FirstOrDefault(); } if (element == null) { if (currentMember.Parent is IXTypeSymbol type) { var field = XSharpLookup.SearchPropertyOrField(location, type, identifier, Modifiers.Private).FirstOrDefault(); } } } } }