mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-02-12 02:58:35 -05:00
Merge pull request #191 from Microsoft/customerIssue/escapeReservedWordsAutocomplete
reserved words with brackets in autocomplete
This commit is contained in:
@@ -332,7 +332,7 @@ namespace Microsoft.SqlTools.ServiceLayer.LanguageServices
|
|||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets a static instance of an empty completion list to avoid
|
/// Gets a static instance of an empty completion list to avoid
|
||||||
// unneeded memory allocations
|
/// unneeded memory allocations
|
||||||
/// </summary>
|
/// </summary>
|
||||||
internal static CompletionItem[] EmptyCompletionList
|
internal static CompletionItem[] EmptyCompletionList
|
||||||
{
|
{
|
||||||
@@ -342,6 +342,16 @@ namespace Microsoft.SqlTools.ServiceLayer.LanguageServices
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Checks whether a given word is in the reserved
|
||||||
|
/// word list or not
|
||||||
|
/// </summary>
|
||||||
|
internal static bool IsReservedWord(string text)
|
||||||
|
{
|
||||||
|
int pos = Array.IndexOf(DefaultCompletionText, text.ToLower());
|
||||||
|
return pos > -1;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the current workspace service instance
|
/// Gets or sets the current workspace service instance
|
||||||
/// Setter for internal testing purposes only
|
/// Setter for internal testing purposes only
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
using System;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using Microsoft.SqlServer.Management.SqlParser.Intellisense;
|
using Microsoft.SqlServer.Management.SqlParser.Intellisense;
|
||||||
@@ -45,7 +46,7 @@ namespace Microsoft.SqlTools.ServiceLayer.LanguageServices.Completion
|
|||||||
{
|
{
|
||||||
InsertText = GetCompletionItemInsertName();
|
InsertText = GetCompletionItemInsertName();
|
||||||
Label = DeclarationTitle;
|
Label = DeclarationTitle;
|
||||||
if (StartsWithBracket(TokenText))
|
if (StartsWithBracket(TokenText) || AutoCompleteHelper.IsReservedWord(InsertText))
|
||||||
{
|
{
|
||||||
Label = WithBracket(Label);
|
Label = WithBracket(Label);
|
||||||
InsertText = WithBracket(InsertText);
|
InsertText = WithBracket(InsertText);
|
||||||
@@ -142,7 +143,7 @@ namespace Microsoft.SqlTools.ServiceLayer.LanguageServices.Completion
|
|||||||
int row,
|
int row,
|
||||||
int startColumn,
|
int startColumn,
|
||||||
int endColumn)
|
int endColumn)
|
||||||
{
|
{
|
||||||
CompletionItem item = new CompletionItem()
|
CompletionItem item = new CompletionItem()
|
||||||
{
|
{
|
||||||
Label = label,
|
Label = label,
|
||||||
|
|||||||
@@ -13,6 +13,304 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.LanguageServer
|
|||||||
{
|
{
|
||||||
public class SqlCompletionItemTests
|
public class SqlCompletionItemTests
|
||||||
{
|
{
|
||||||
|
private static readonly string[] ReservedWords = new string[]
|
||||||
|
{
|
||||||
|
"all",
|
||||||
|
"alter",
|
||||||
|
"and",
|
||||||
|
"apply",
|
||||||
|
"as",
|
||||||
|
"asc",
|
||||||
|
"at",
|
||||||
|
"backup",
|
||||||
|
"begin",
|
||||||
|
"binary",
|
||||||
|
"bit",
|
||||||
|
"break",
|
||||||
|
"bulk",
|
||||||
|
"by",
|
||||||
|
"call",
|
||||||
|
"cascade",
|
||||||
|
"case",
|
||||||
|
"catch",
|
||||||
|
"char",
|
||||||
|
"character",
|
||||||
|
"check",
|
||||||
|
"checkpoint",
|
||||||
|
"close",
|
||||||
|
"clustered",
|
||||||
|
"column",
|
||||||
|
"columnstore",
|
||||||
|
"commit",
|
||||||
|
"connect",
|
||||||
|
"constraint",
|
||||||
|
"continue",
|
||||||
|
"create",
|
||||||
|
"cross",
|
||||||
|
"current_date",
|
||||||
|
"cursor",
|
||||||
|
"cursor_close_on_commit",
|
||||||
|
"cursor_default",
|
||||||
|
"data",
|
||||||
|
"data_compression",
|
||||||
|
"database",
|
||||||
|
"date",
|
||||||
|
"datetime",
|
||||||
|
"datetime2",
|
||||||
|
"days",
|
||||||
|
"dbcc",
|
||||||
|
"dec",
|
||||||
|
"decimal",
|
||||||
|
"declare",
|
||||||
|
"default",
|
||||||
|
"delete",
|
||||||
|
"deny",
|
||||||
|
"desc",
|
||||||
|
"description",
|
||||||
|
"disabled",
|
||||||
|
"disk",
|
||||||
|
"distinct",
|
||||||
|
"double",
|
||||||
|
"drop",
|
||||||
|
"drop_existing",
|
||||||
|
"dump",
|
||||||
|
"dynamic",
|
||||||
|
"else",
|
||||||
|
"enable",
|
||||||
|
"encrypted",
|
||||||
|
"end",
|
||||||
|
"end-exec",
|
||||||
|
"exec",
|
||||||
|
"execute",
|
||||||
|
"exists",
|
||||||
|
"exit",
|
||||||
|
"external",
|
||||||
|
"fast_forward",
|
||||||
|
"fetch",
|
||||||
|
"file",
|
||||||
|
"filegroup",
|
||||||
|
"filename",
|
||||||
|
"filestream",
|
||||||
|
"filter",
|
||||||
|
"first",
|
||||||
|
"float",
|
||||||
|
"for",
|
||||||
|
"foreign",
|
||||||
|
"from",
|
||||||
|
"full",
|
||||||
|
"function",
|
||||||
|
"geography",
|
||||||
|
"get",
|
||||||
|
"global",
|
||||||
|
"go",
|
||||||
|
"goto",
|
||||||
|
"grant",
|
||||||
|
"group",
|
||||||
|
"hash",
|
||||||
|
"hashed",
|
||||||
|
"having",
|
||||||
|
"hidden",
|
||||||
|
"hierarchyid",
|
||||||
|
"holdlock",
|
||||||
|
"hours",
|
||||||
|
"identity",
|
||||||
|
"identitycol",
|
||||||
|
"if",
|
||||||
|
"image",
|
||||||
|
"immediate",
|
||||||
|
"include",
|
||||||
|
"index",
|
||||||
|
"inner",
|
||||||
|
"insert",
|
||||||
|
"instead",
|
||||||
|
"int",
|
||||||
|
"integer",
|
||||||
|
"intersect",
|
||||||
|
"into",
|
||||||
|
"isolation",
|
||||||
|
"join",
|
||||||
|
"json",
|
||||||
|
"key",
|
||||||
|
"language",
|
||||||
|
"last",
|
||||||
|
"left",
|
||||||
|
"level",
|
||||||
|
"lineno",
|
||||||
|
"load",
|
||||||
|
"local",
|
||||||
|
"locate",
|
||||||
|
"location",
|
||||||
|
"login",
|
||||||
|
"masked",
|
||||||
|
"maxdop",
|
||||||
|
"merge",
|
||||||
|
"message",
|
||||||
|
"modify",
|
||||||
|
"move",
|
||||||
|
"namespace",
|
||||||
|
"native_compilation",
|
||||||
|
"nchar",
|
||||||
|
"next",
|
||||||
|
"no",
|
||||||
|
"nocheck",
|
||||||
|
"nocount",
|
||||||
|
"nonclustered",
|
||||||
|
"none",
|
||||||
|
"norecompute",
|
||||||
|
"not",
|
||||||
|
"now",
|
||||||
|
"null",
|
||||||
|
"numeric",
|
||||||
|
"object",
|
||||||
|
"of",
|
||||||
|
"off",
|
||||||
|
"offsets",
|
||||||
|
"on",
|
||||||
|
"online",
|
||||||
|
"open",
|
||||||
|
"openrowset",
|
||||||
|
"openxml",
|
||||||
|
"option",
|
||||||
|
"or",
|
||||||
|
"order",
|
||||||
|
"out",
|
||||||
|
"outer",
|
||||||
|
"output",
|
||||||
|
"over",
|
||||||
|
"owner",
|
||||||
|
"partial",
|
||||||
|
"partition",
|
||||||
|
"password",
|
||||||
|
"path",
|
||||||
|
"percent",
|
||||||
|
"percentage",
|
||||||
|
"period",
|
||||||
|
"persisted",
|
||||||
|
"plan",
|
||||||
|
"policy",
|
||||||
|
"precision",
|
||||||
|
"predicate",
|
||||||
|
"primary",
|
||||||
|
"print",
|
||||||
|
"prior",
|
||||||
|
"proc",
|
||||||
|
"procedure",
|
||||||
|
"public",
|
||||||
|
"query_store",
|
||||||
|
"quoted_identifier",
|
||||||
|
"raiserror",
|
||||||
|
"range",
|
||||||
|
"raw",
|
||||||
|
"read",
|
||||||
|
"read_committed_snapshot",
|
||||||
|
"read_only",
|
||||||
|
"read_write",
|
||||||
|
"readonly",
|
||||||
|
"readtext",
|
||||||
|
"real",
|
||||||
|
"rebuild",
|
||||||
|
"receive",
|
||||||
|
"reconfigure",
|
||||||
|
"recovery",
|
||||||
|
"recursive",
|
||||||
|
"recursive_triggers",
|
||||||
|
"references",
|
||||||
|
"relative",
|
||||||
|
"remove",
|
||||||
|
"reorganize",
|
||||||
|
"required",
|
||||||
|
"restart",
|
||||||
|
"restore",
|
||||||
|
"restrict",
|
||||||
|
"resume",
|
||||||
|
"return",
|
||||||
|
"returns",
|
||||||
|
"revert",
|
||||||
|
"revoke",
|
||||||
|
"rollback",
|
||||||
|
"rollup",
|
||||||
|
"row",
|
||||||
|
"rowcount",
|
||||||
|
"rowguidcol",
|
||||||
|
"rows",
|
||||||
|
"rule",
|
||||||
|
"sample",
|
||||||
|
"save",
|
||||||
|
"schema",
|
||||||
|
"schemabinding",
|
||||||
|
"scoped",
|
||||||
|
"scroll",
|
||||||
|
"secondary",
|
||||||
|
"security",
|
||||||
|
"select",
|
||||||
|
"send",
|
||||||
|
"sent",
|
||||||
|
"sequence",
|
||||||
|
"server",
|
||||||
|
"session",
|
||||||
|
"set",
|
||||||
|
"sets",
|
||||||
|
"setuser",
|
||||||
|
"simple",
|
||||||
|
"smallint",
|
||||||
|
"smallmoney",
|
||||||
|
"snapshot",
|
||||||
|
"sql",
|
||||||
|
"standard",
|
||||||
|
"start",
|
||||||
|
"started",
|
||||||
|
"state",
|
||||||
|
"statement",
|
||||||
|
"static",
|
||||||
|
"statistics",
|
||||||
|
"statistics_norecompute",
|
||||||
|
"status",
|
||||||
|
"stopped",
|
||||||
|
"sysname",
|
||||||
|
"system",
|
||||||
|
"system_time",
|
||||||
|
"table",
|
||||||
|
"take",
|
||||||
|
"target",
|
||||||
|
"then",
|
||||||
|
"throw",
|
||||||
|
"time",
|
||||||
|
"timestamp",
|
||||||
|
"tinyint",
|
||||||
|
"to",
|
||||||
|
"top",
|
||||||
|
"tran",
|
||||||
|
"transaction",
|
||||||
|
"trigger",
|
||||||
|
"truncate",
|
||||||
|
"try",
|
||||||
|
"tsql",
|
||||||
|
"type",
|
||||||
|
"uncommitted",
|
||||||
|
"union",
|
||||||
|
"unique",
|
||||||
|
"uniqueidentifier",
|
||||||
|
"updatetext",
|
||||||
|
"use",
|
||||||
|
"user",
|
||||||
|
"using",
|
||||||
|
"value",
|
||||||
|
"values",
|
||||||
|
"varchar",
|
||||||
|
"version",
|
||||||
|
"view",
|
||||||
|
"waitfor",
|
||||||
|
"when",
|
||||||
|
"where",
|
||||||
|
"while",
|
||||||
|
"with",
|
||||||
|
"within",
|
||||||
|
"without",
|
||||||
|
"writetext",
|
||||||
|
"xact_abort",
|
||||||
|
"xml",
|
||||||
|
};
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void InsertTextShouldIncludeBracketGivenNameWithSpace()
|
public void InsertTextShouldIncludeBracketGivenNameWithSpace()
|
||||||
{
|
{
|
||||||
@@ -132,6 +430,24 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.LanguageServer
|
|||||||
Assert.Equal(completionItem.Detail, expected);
|
Assert.Equal(completionItem.Detail, expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void LabelShouldIncBracketGivenReservedName()
|
||||||
|
{
|
||||||
|
foreach (string word in ReservedWords)
|
||||||
|
{
|
||||||
|
string declarationTitle = word;
|
||||||
|
string expected = "[" + declarationTitle + "]";
|
||||||
|
DeclarationType declarationType = DeclarationType.Table;
|
||||||
|
string tokenText = "[]";
|
||||||
|
SqlCompletionItem item = new SqlCompletionItem(declarationTitle, declarationType, tokenText);
|
||||||
|
CompletionItem completionItem = item.CreateCompletionItem(0, 1, 2);
|
||||||
|
|
||||||
|
Assert.Equal(completionItem.Label, expected);
|
||||||
|
Assert.Equal(completionItem.InsertText, expected);
|
||||||
|
Assert.Equal(completionItem.Detail, expected);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void KindShouldBeModuleGivenSchemaDeclarationType()
|
public void KindShouldBeModuleGivenSchemaDeclarationType()
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user