mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-02-02 09:35:38 -05:00
Adding completion extension loading and execution logic (#833)
* Adding ICompletionExtension interface * Adding extension loading and execution logic * Fixing compilation error in VS 2017 * Using MEF for completion extension discovery * using await on GetCompletionItems * Adding an integration test for completion extension and update the completion extension interface * Update the completion extension test * Fix issues based on review comments * Remove try/cache based on review comments, fix a integration test. * More changes based on review comments * Fixing SendResult logic for completion extension loading * Only load completion extension from the assembly passed in, add more comments in the test * Adding right assert messages in the test. * More fixes based on review comments * Dropping ICompletionExtensionProvider, load assembly only if it's loaded at the first time or updated since last load. * Fix based on the latest review comments * Adding missing TSQL functions in default completion list * Update jsonrpc documentation for completion/extLoad
This commit is contained in:
@@ -29,305 +29,394 @@ namespace Microsoft.SqlTools.ServiceLayer.LanguageServices
|
||||
private static CompletionItem[] emptyCompletionList = new CompletionItem[0];
|
||||
|
||||
private static readonly string[] DefaultCompletionText = new string[]
|
||||
{
|
||||
"all",
|
||||
"alter",
|
||||
"and",
|
||||
"apply",
|
||||
"as",
|
||||
"asc",
|
||||
"at",
|
||||
"backup",
|
||||
"begin",
|
||||
"between",
|
||||
"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",
|
||||
"except",
|
||||
"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",
|
||||
"nvarchar",
|
||||
"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",
|
||||
"update",
|
||||
"updatetext",
|
||||
"use",
|
||||
"user",
|
||||
"using",
|
||||
"value",
|
||||
"values",
|
||||
"varchar",
|
||||
"version",
|
||||
"view",
|
||||
"waitfor",
|
||||
"when",
|
||||
"where",
|
||||
"while",
|
||||
"with",
|
||||
"within",
|
||||
"without",
|
||||
"writetext",
|
||||
"xact_abort",
|
||||
"xml",
|
||||
{
|
||||
"abs",
|
||||
"acos",
|
||||
"all",
|
||||
"alter",
|
||||
"and",
|
||||
"apply",
|
||||
"approx_count_distinct",
|
||||
"as",
|
||||
"asc",
|
||||
"ascii",
|
||||
"asin",
|
||||
"at",
|
||||
"atan",
|
||||
"atn2",
|
||||
"avg",
|
||||
"backup",
|
||||
"begin",
|
||||
"between",
|
||||
"binary",
|
||||
"bit",
|
||||
"break",
|
||||
"bulk",
|
||||
"by",
|
||||
"call",
|
||||
"cascade",
|
||||
"case",
|
||||
"cast",
|
||||
"catch",
|
||||
"ceiling",
|
||||
"char",
|
||||
"character",
|
||||
"charindex",
|
||||
"check",
|
||||
"checkpoint",
|
||||
"checksum_agg",
|
||||
"close",
|
||||
"clustered",
|
||||
"coalesce",
|
||||
"column",
|
||||
"columnstore",
|
||||
"commit",
|
||||
"concat",
|
||||
"concat_ws",
|
||||
"connect",
|
||||
"constraint",
|
||||
"continue",
|
||||
"convert",
|
||||
"cos",
|
||||
"cot",
|
||||
"count",
|
||||
"count_big",
|
||||
"create",
|
||||
"cross",
|
||||
"current_date",
|
||||
"current_timestamp",
|
||||
"current_user",
|
||||
"cursor",
|
||||
"cursor_close_on_commit",
|
||||
"cursor_default",
|
||||
"data",
|
||||
"data_compression",
|
||||
"database",
|
||||
"datalength",
|
||||
"date",
|
||||
"dateadd",
|
||||
"datediff",
|
||||
"datefromparts",
|
||||
"datename",
|
||||
"datepart",
|
||||
"datetime",
|
||||
"datetime2",
|
||||
"day",
|
||||
"days",
|
||||
"dbcc",
|
||||
"dec",
|
||||
"decimal",
|
||||
"declare",
|
||||
"default",
|
||||
"degrees",
|
||||
"delete",
|
||||
"deny",
|
||||
"desc",
|
||||
"description",
|
||||
"difference",
|
||||
"disabled",
|
||||
"disk",
|
||||
"distinct",
|
||||
"double",
|
||||
"drop",
|
||||
"drop_existing",
|
||||
"dump",
|
||||
"dynamic",
|
||||
"else",
|
||||
"enable",
|
||||
"encrypted",
|
||||
"end",
|
||||
"end-exec",
|
||||
"except",
|
||||
"exec",
|
||||
"execute",
|
||||
"exists",
|
||||
"exit",
|
||||
"exp",
|
||||
"external",
|
||||
"fast_forward",
|
||||
"fetch",
|
||||
"file",
|
||||
"filegroup",
|
||||
"filename",
|
||||
"filestream",
|
||||
"filter",
|
||||
"first",
|
||||
"float",
|
||||
"floor",
|
||||
"for",
|
||||
"foreign",
|
||||
"format",
|
||||
"from",
|
||||
"full",
|
||||
"function",
|
||||
"geography",
|
||||
"get",
|
||||
"getdate",
|
||||
"getutcdate",
|
||||
"global",
|
||||
"go",
|
||||
"goto",
|
||||
"grant",
|
||||
"group",
|
||||
"grouping",
|
||||
"grouping_id",
|
||||
"hash",
|
||||
"hashed",
|
||||
"having",
|
||||
"hidden",
|
||||
"hierarchyid",
|
||||
"holdlock",
|
||||
"hours",
|
||||
"identity",
|
||||
"identitycol",
|
||||
"if",
|
||||
"iif",
|
||||
"image",
|
||||
"immediate",
|
||||
"include",
|
||||
"index",
|
||||
"inner",
|
||||
"insert",
|
||||
"instead",
|
||||
"int",
|
||||
"integer",
|
||||
"intersect",
|
||||
"into",
|
||||
"isdate",
|
||||
"isnull",
|
||||
"isnumeric",
|
||||
"isolation",
|
||||
"join",
|
||||
"json",
|
||||
"key",
|
||||
"language",
|
||||
"last",
|
||||
"left",
|
||||
"len",
|
||||
"level",
|
||||
"lineno",
|
||||
"load",
|
||||
"local",
|
||||
"locate",
|
||||
"location",
|
||||
"log",
|
||||
"log10",
|
||||
"login",
|
||||
"lower",
|
||||
"ltrim",
|
||||
"masked",
|
||||
"max",
|
||||
"maxdop",
|
||||
"merge",
|
||||
"message",
|
||||
"min",
|
||||
"modify",
|
||||
"month",
|
||||
"move",
|
||||
"namespace",
|
||||
"native_compilation",
|
||||
"nchar",
|
||||
"next",
|
||||
"no",
|
||||
"nocheck",
|
||||
"nocount",
|
||||
"nonclustered",
|
||||
"none",
|
||||
"norecompute",
|
||||
"not",
|
||||
"now",
|
||||
"null",
|
||||
"nullif",
|
||||
"numeric",
|
||||
"nvarchar",
|
||||
"object",
|
||||
"of",
|
||||
"off",
|
||||
"offsets",
|
||||
"on",
|
||||
"online",
|
||||
"open",
|
||||
"openrowset",
|
||||
"openxml",
|
||||
"option",
|
||||
"or",
|
||||
"order",
|
||||
"out",
|
||||
"outer",
|
||||
"output",
|
||||
"over",
|
||||
"owner",
|
||||
"partial",
|
||||
"partition",
|
||||
"password",
|
||||
"path",
|
||||
"patindex",
|
||||
"percent",
|
||||
"percentage",
|
||||
"period",
|
||||
"persisted",
|
||||
"pi",
|
||||
"plan",
|
||||
"policy",
|
||||
"power",
|
||||
"precision",
|
||||
"predicate",
|
||||
"primary",
|
||||
"print",
|
||||
"prior",
|
||||
"proc",
|
||||
"procedure",
|
||||
"public",
|
||||
"query_store",
|
||||
"quoted_identifier",
|
||||
"quotename",
|
||||
"radians",
|
||||
"raiserror",
|
||||
"rand",
|
||||
"range",
|
||||
"raw",
|
||||
"read",
|
||||
"read_committed_snapshot",
|
||||
"read_only",
|
||||
"read_write",
|
||||
"readonly",
|
||||
"readtext",
|
||||
"real",
|
||||
"rebuild",
|
||||
"receive",
|
||||
"reconfigure",
|
||||
"recovery",
|
||||
"recursive",
|
||||
"recursive_triggers",
|
||||
"references",
|
||||
"relative",
|
||||
"remove",
|
||||
"reorganize",
|
||||
"replace",
|
||||
"replicate",
|
||||
"required",
|
||||
"restart",
|
||||
"restore",
|
||||
"restrict",
|
||||
"resume",
|
||||
"return",
|
||||
"returns",
|
||||
"reverse",
|
||||
"revert",
|
||||
"revoke",
|
||||
"right",
|
||||
"rollback",
|
||||
"rollup",
|
||||
"round",
|
||||
"row",
|
||||
"rowcount",
|
||||
"rowguidcol",
|
||||
"rows",
|
||||
"rtrim",
|
||||
"rule",
|
||||
"sample",
|
||||
"save",
|
||||
"schema",
|
||||
"schemabinding",
|
||||
"scoped",
|
||||
"scroll",
|
||||
"secondary",
|
||||
"security",
|
||||
"select",
|
||||
"send",
|
||||
"sent",
|
||||
"sequence",
|
||||
"server",
|
||||
"session",
|
||||
"session_user",
|
||||
"sessionproperty",
|
||||
"set",
|
||||
"sets",
|
||||
"setuser",
|
||||
"sign",
|
||||
"simple",
|
||||
"sin",
|
||||
"smallint",
|
||||
"smallmoney",
|
||||
"snapshot",
|
||||
"soundex",
|
||||
"space",
|
||||
"sql",
|
||||
"sqrt",
|
||||
"square",
|
||||
"standard",
|
||||
"start",
|
||||
"started",
|
||||
"state",
|
||||
"statement",
|
||||
"static",
|
||||
"statistics",
|
||||
"statistics_norecompute",
|
||||
"status",
|
||||
"stdev",
|
||||
"stdevp",
|
||||
"stopped",
|
||||
"str",
|
||||
"string_agg",
|
||||
"stuff",
|
||||
"substring",
|
||||
"sum",
|
||||
"sysdatetime",
|
||||
"sysname",
|
||||
"system",
|
||||
"system_time",
|
||||
"system_user",
|
||||
"table",
|
||||
"take",
|
||||
"tan",
|
||||
"target",
|
||||
"then",
|
||||
"throw",
|
||||
"time",
|
||||
"timestamp",
|
||||
"tinyint",
|
||||
"to",
|
||||
"top",
|
||||
"tran",
|
||||
"transaction",
|
||||
"translate",
|
||||
"trigger",
|
||||
"trim",
|
||||
"truncate",
|
||||
"try",
|
||||
"tsql",
|
||||
"type",
|
||||
"uncommitted",
|
||||
"unicode",
|
||||
"union",
|
||||
"unique",
|
||||
"uniqueidentifier",
|
||||
"update",
|
||||
"updatetext",
|
||||
"upper",
|
||||
"use",
|
||||
"user",
|
||||
"user_name",
|
||||
"using",
|
||||
"value",
|
||||
"values",
|
||||
"var",
|
||||
"varchar",
|
||||
"varp",
|
||||
"version",
|
||||
"view",
|
||||
"waitfor",
|
||||
"when",
|
||||
"where",
|
||||
"while",
|
||||
"with",
|
||||
"within",
|
||||
"without",
|
||||
"writetext",
|
||||
"xact_abort",
|
||||
"xml",
|
||||
"year",
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
@@ -367,7 +456,7 @@ namespace Microsoft.SqlTools.ServiceLayer.LanguageServices
|
||||
int startColumn = scriptDocumentInfo.StartColumn;
|
||||
int endColumn = scriptDocumentInfo.EndColumn;
|
||||
string tokenText = scriptDocumentInfo.TokenText;
|
||||
// determine how many default completion items there will be
|
||||
// determine how many default completion items there will be
|
||||
int listSize = DefaultCompletionText.Length;
|
||||
if (!string.IsNullOrWhiteSpace(tokenText))
|
||||
{
|
||||
@@ -392,14 +481,14 @@ namespace Microsoft.SqlTools.ServiceLayer.LanguageServices
|
||||
int completionItemIndex = 0;
|
||||
foreach (var completionText in DefaultCompletionText)
|
||||
{
|
||||
// add item to list if the tokenText is null (meaning return whole list)
|
||||
// add item to list if the tokenText is null (meaning return whole list)
|
||||
// or if the completion item begins with the tokenText
|
||||
if (string.IsNullOrWhiteSpace(tokenText) || completionText.StartsWith(tokenText, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
completionItems[completionItemIndex] = CreateDefaultCompletionItem(
|
||||
useLowerCase ? completionText.ToLowerInvariant() : completionText.ToUpperInvariant(),
|
||||
row,
|
||||
startColumn,
|
||||
row,
|
||||
startColumn,
|
||||
endColumn);
|
||||
++completionItemIndex;
|
||||
}
|
||||
@@ -417,8 +506,8 @@ namespace Microsoft.SqlTools.ServiceLayer.LanguageServices
|
||||
/// <param name="endColumn"></param>
|
||||
private static CompletionItem CreateDefaultCompletionItem(
|
||||
string label,
|
||||
int row,
|
||||
int startColumn,
|
||||
int row,
|
||||
int startColumn,
|
||||
int endColumn)
|
||||
{
|
||||
return SqlCompletionItem.CreateCompletionItem(label, label + " keyword", label, CompletionItemKind.Keyword, row, startColumn, endColumn);
|
||||
@@ -450,14 +539,14 @@ namespace Microsoft.SqlTools.ServiceLayer.LanguageServices
|
||||
/// <param name="cursorColumn"></param>
|
||||
/// <returns></returns>
|
||||
internal static CompletionItem[] ConvertDeclarationsToCompletionItems(
|
||||
IEnumerable<Declaration> suggestions,
|
||||
IEnumerable<Declaration> suggestions,
|
||||
int row,
|
||||
int startColumn,
|
||||
int endColumn,
|
||||
int endColumn,
|
||||
string tokenText = null)
|
||||
{
|
||||
{
|
||||
List<CompletionItem> completions = new List<CompletionItem>();
|
||||
|
||||
|
||||
foreach (var autoCompleteItem in suggestions)
|
||||
{
|
||||
SqlCompletionItem sqlCompletionItem = new SqlCompletionItem(autoCompleteItem, tokenText);
|
||||
@@ -489,7 +578,7 @@ namespace Microsoft.SqlTools.ServiceLayer.LanguageServices
|
||||
markedStrings[0] = new MarkedString()
|
||||
{
|
||||
Language = "SQL",
|
||||
Value = quickInfo.Text
|
||||
Value = quickInfo.Text
|
||||
};
|
||||
|
||||
return new Hover()
|
||||
@@ -535,7 +624,7 @@ namespace Microsoft.SqlTools.ServiceLayer.LanguageServices
|
||||
// Signature label format: <name> param1, param2, ..., paramn RETURNS <type>
|
||||
Label = method.Name + " " + method.Parameters.Select(parameter => parameter.Display).Aggregate((l, r) => l + "," + r) + " " + method.Type,
|
||||
Documentation = method.Description,
|
||||
Parameters = method.Parameters.Select(parameter =>
|
||||
Parameters = method.Parameters.Select(parameter =>
|
||||
{
|
||||
return new ParameterInformation()
|
||||
{
|
||||
@@ -560,7 +649,7 @@ namespace Microsoft.SqlTools.ServiceLayer.LanguageServices
|
||||
if (locations.ParamStartLocation != null)
|
||||
{
|
||||
// Is the cursor past the function name?
|
||||
var location = locations.ParamStartLocation.Value;
|
||||
var location = locations.ParamStartLocation.Value;
|
||||
if (line > location.LineNumber || (line == location.LineNumber && line == location.LineNumber && column >= location.ColumnNumber))
|
||||
{
|
||||
currentParameter = 0;
|
||||
@@ -577,7 +666,7 @@ namespace Microsoft.SqlTools.ServiceLayer.LanguageServices
|
||||
if (locations.ParamEndLocation != null)
|
||||
{
|
||||
// Is the cursor past the end of the parameter list on a different token?
|
||||
var location = locations.ParamEndLocation.Value;
|
||||
var location = locations.ParamEndLocation.Value;
|
||||
if (line > location.LineNumber || (line == location.LineNumber && line == location.LineNumber && column > location.ColumnNumber))
|
||||
{
|
||||
currentParameter = -1;
|
||||
|
||||
Reference in New Issue
Block a user