Example #1
0
 private string WithDelimitedIdentifier(DelimitedIdentifier delimitedIdentifier, string text)
 {
     if (!HasDelimitedIdentifier(delimitedIdentifier, text))
     {
         return(string.Format(CultureInfo.InvariantCulture, "{0}{1}{2}", delimitedIdentifier.Start, text, delimitedIdentifier.End));
     }
     else
     {
         return(text);
     }
 }
Example #2
0
        private void Init()
        {
            InsertText = DeclarationTitle;
            Label      = DeclarationTitle;
            DelimitedIdentifier delimitedIdentifier = GetDelimitedIdentifier(TokenText);

            // If we're not already going to quote this then handle special cases for various
            // DeclarationTypes
            if (delimitedIdentifier == null && !string.IsNullOrEmpty(DeclarationTitle))
            {
                switch (this.DeclarationType)
                {
                case DeclarationType.Server:
                case DeclarationType.Database:
                case DeclarationType.Table:
                case DeclarationType.Column:
                case DeclarationType.View:
                case DeclarationType.Schema:
                    // Only quote if we need to - i.e. if this isn't a valid name (has characters that need escaping such as [)
                    // or if it's a reserved word
                    if (!ValidSqlNameRegex.IsMatch(DeclarationTitle) || AutoCompleteHelper.IsReservedWord(InsertText))
                    {
                        InsertText = WithDelimitedIdentifier(BracketedIdentifiers, DeclarationTitle);
                    }
                    break;

                case DeclarationType.BuiltInFunction:
                case DeclarationType.ScalarValuedFunction:
                case DeclarationType.TableValuedFunction:
                    // Add ()'s for all functions except global variable system functions (which all start with @@)
                    if (!DeclarationTitle.StartsWith("@@"))
                    {
                        InsertText = WithDelimitedIdentifier(FunctionPostfix, DeclarationTitle);
                    }
                    break;
                }
            }

            // If the user typed a token that starts with a delimiter then always quote both
            // the display label and text to be inserted
            if (delimitedIdentifier != null)
            {
                Label      = WithDelimitedIdentifier(delimitedIdentifier, Label);
                InsertText = WithDelimitedIdentifier(delimitedIdentifier, InsertText);
            }
            Detail = Label;
            Kind   = CreateCompletionItemKind();
        }
        private void Init()
        {
            InsertText = DeclarationTitle;
            DelimitedIdentifier delimitedIdentifier = GetDelimitedIdentifier(TokenText);

            Label = DeclarationTitle;

            if (delimitedIdentifier == null && !string.IsNullOrEmpty(DeclarationTitle) &&
                (!ValidSqlNameRegex.IsMatch(DeclarationTitle) || AutoCompleteHelper.IsReservedWord(InsertText)))
            {
                InsertText = WithDelimitedIdentifier(BracketedIdentifiers, DeclarationTitle);
            }
            if (delimitedIdentifier != null)
            {
                Label      = WithDelimitedIdentifier(delimitedIdentifier, Label);
                InsertText = WithDelimitedIdentifier(delimitedIdentifier, InsertText);
            }
            Detail = Label;
            Kind   = CreateCompletionItemKind();
        }
Example #4
0
 private bool HasDelimitedIdentifier(DelimitedIdentifier delimiteIidentifier, string text)
 {
     return(text != null && delimiteIidentifier != null && text.StartsWith(delimiteIidentifier.Start) &&
            text.EndsWith(delimiteIidentifier.End));
 }