private static bool TryGetLocalScopeInfo(TexlNode node, TexlBinding binding, out ScopedNameLookupInfo info) { Contracts.AssertValue(node); Contracts.AssertValue(binding); if (node.Kind == NodeKind.FirstName) { FirstNameNode curNode = node.CastFirstName(); var firstNameInfo = binding.GetInfo(curNode); if (firstNameInfo.Kind == BindKind.ScopeArgument) { info = (ScopedNameLookupInfo)firstNameInfo.Data; return(true); } } info = new ScopedNameLookupInfo(); return(false); }
internal override bool TryAddSuggestionsForNodeKind(IntellisenseData.IntellisenseData intellisenseData) { Contracts.AssertValue(intellisenseData); TexlNode curNode = intellisenseData.CurNode; int cursorPos = intellisenseData.CursorPos; FirstNameNode firstNameNode = curNode.CastFirstName(); Identifier ident = firstNameNode.Ident; int min = ident.Token.Span.Min; IdentToken tok = ident.Token; if (cursorPos < min) { // Cursor is before the beginning of the identifier or of the global token if present. // Suggest possibilities that can result in a value. IntellisenseHelper.AddSuggestionsForValuePossibilities(intellisenseData, curNode); intellisenseData.AddAdditionalSuggestionsForKeywordSymbols(curNode); } else if (cursorPos <= tok.Span.Lim) { // Cursor is part of the identifier or global token if present. // Get the matching string as a substring from the script so that the whitespace is preserved. IEnumerable <string> possibleFirstNames = intellisenseData.Binding.GetFirstNames().Select(firstNameInfo => firstNameInfo.Name.Value) .Union(intellisenseData.Binding.GetGlobalNames().Select(firstNameInfo => firstNameInfo.Name.Value)) .Union(intellisenseData.Binding.GetAliasNames().Select(firstNameInfo => firstNameInfo.Name.Value)) .Union(intellisenseData.SuggestableFirstNames); int replacementLength = IntellisenseHelper.GetReplacementLength(intellisenseData, tok.Span.Min, tok.Span.Lim, possibleFirstNames); intellisenseData.SetMatchArea(tok.Span.Min, cursorPos, replacementLength); intellisenseData.BoundTo = intellisenseData.Binding.ErrorContainer.HasErrors(firstNameNode) ? string.Empty : ident.Name; if (ident.AtToken != null || tok.Kind == TokKind.At) { // Suggest globals if cursor is after '@'. AddSuggestionsForScopedGlobals(intellisenseData); } else if (tok.HasDelimiters && cursorPos > tok.Span.Min) { // Suggest top level fields and globals if cursor is after a opening square bracket. IntellisenseHelper.AddSuggestionsForRuleScope(intellisenseData); IntellisenseHelper.AddSuggestionsForTopLevel(intellisenseData, curNode); IntellisenseHelper.AddSuggestionsForGlobals(intellisenseData); intellisenseData.AddAdditionalSuggestionsForLocalSymbols(); } else { // Suggest value posssibilities otherwise. IntellisenseHelper.AddSuggestionsForValuePossibilities(intellisenseData, curNode); } intellisenseData.AddAdditionalSuggestionsForKeywordSymbols(curNode); } else if (IsBracketOpen(tok.Span.Lim, cursorPos, intellisenseData.Script)) { AddSuggestionsForScopeFields(intellisenseData, intellisenseData.Binding.GetType(firstNameNode)); } else if (IntellisenseHelper.CanSuggestAfterValue(cursorPos, intellisenseData.Script)) { // Verify that cursor is after a space after the identifier. // Suggest binary keywords. IntellisenseHelper.AddSuggestionsForAfterValue(intellisenseData, intellisenseData.Binding.GetType(firstNameNode)); } return(true); }