mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-02-16 10:58:30 -05:00
Fixing a null exception error when bound tables are null. (#1327)
* Fixing a null exception error when bound tables are null. * skipping star expansion when there is no active conn * Fixing a comment
This commit is contained in:
@@ -754,6 +754,15 @@ namespace Microsoft.SqlTools.ServiceLayer.LanguageServices
|
|||||||
starObjectIdentifier = (SqlObjectIdentifier)selectStarExpression.Children.ElementAt(0);
|
starObjectIdentifier = (SqlObjectIdentifier)selectStarExpression.Children.ElementAt(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
Returning no suggestions when the bound tables are null.
|
||||||
|
This happens when there are no existing connections for the script.
|
||||||
|
*/
|
||||||
|
if (selectStarExpression.BoundTables == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
List<ITabular> boundedTableList = selectStarExpression.BoundTables.ToList();
|
List<ITabular> boundedTableList = selectStarExpression.BoundTables.ToList();
|
||||||
|
|
||||||
IList<string> columnNames = new List<string>();
|
IList<string> columnNames = new List<string>();
|
||||||
@@ -829,11 +838,11 @@ namespace Microsoft.SqlTools.ServiceLayer.LanguageServices
|
|||||||
|
|
||||||
public static SqlSelectStarExpression TryGetSelectStarStatement(SqlCodeObject currentNode, ScriptDocumentInfo scriptDocumentInfo)
|
public static SqlSelectStarExpression TryGetSelectStarStatement(SqlCodeObject currentNode, ScriptDocumentInfo scriptDocumentInfo)
|
||||||
{
|
{
|
||||||
if(currentNode == null || scriptDocumentInfo == null)
|
if (currentNode == null || scriptDocumentInfo == null)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Checking if the current node is a sql select star expression.
|
// Checking if the current node is a sql select star expression.
|
||||||
if (currentNode is SqlSelectStarExpression)
|
if (currentNode is SqlSelectStarExpression)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -947,18 +947,18 @@ namespace Microsoft.SqlTools.ServiceLayer.LanguageServices
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// parse current SQL file contents to retrieve a list of errors
|
// parse current SQL file contents to retrieve a list of errors
|
||||||
ParseResult parseResult = Parser.IncrementalParse(
|
ParseResult parseResult = Parser.IncrementalParse(
|
||||||
scriptFile.Contents,
|
scriptFile.Contents,
|
||||||
parseInfo.ParseResult,
|
parseInfo.ParseResult,
|
||||||
this.DefaultParseOptions);
|
this.DefaultParseOptions);
|
||||||
|
|
||||||
parseInfo.ParseResult = parseResult;
|
parseInfo.ParseResult = parseResult;
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
// Log the exception but don't rethrow it to prevent parsing errors from crashing SQL Tools Service
|
// Log the exception but don't rethrow it to prevent parsing errors from crashing SQL Tools Service
|
||||||
Logger.Write(TraceEventType.Error, string.Format("An unexpected error occured while parsing: {0}", e.ToString()));
|
Logger.Write(TraceEventType.Error, string.Format("An unexpected error occured while parsing: {0}", e.ToString()));
|
||||||
}
|
}
|
||||||
}, ConnectedBindingQueue.QueueThreadStackSize);
|
}, ConnectedBindingQueue.QueueThreadStackSize);
|
||||||
parseThread.Start();
|
parseThread.Start();
|
||||||
@@ -1658,12 +1658,18 @@ namespace Microsoft.SqlTools.ServiceLayer.LanguageServices
|
|||||||
// cache the current script parse info object to resolve completions later
|
// cache the current script parse info object to resolve completions later
|
||||||
this.currentCompletionParseInfo = scriptParseInfo;
|
this.currentCompletionParseInfo = scriptParseInfo;
|
||||||
resultCompletionItems = result.CompletionItems;
|
resultCompletionItems = result.CompletionItems;
|
||||||
|
|
||||||
// Expanding star expressions in query
|
/*
|
||||||
CompletionItem[] starExpansionSuggestion = AutoCompleteHelper.ExpandSqlStarExpression(scriptDocumentInfo);
|
Expanding star expressions in query only when the script is connected to a database
|
||||||
if (starExpansionSuggestion != null)
|
as the parser requires a connection to determine column names
|
||||||
|
*/
|
||||||
|
if (connInfo != null)
|
||||||
{
|
{
|
||||||
return starExpansionSuggestion;
|
CompletionItem[] starExpansionSuggestion = AutoCompleteHelper.ExpandSqlStarExpression(scriptDocumentInfo);
|
||||||
|
if (starExpansionSuggestion != null)
|
||||||
|
{
|
||||||
|
return starExpansionSuggestion;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// if there are no completions then provide the default list
|
// if there are no completions then provide the default list
|
||||||
|
|||||||
Reference in New Issue
Block a user