private AutoCompletionResult CreateCompletionsFromSqlParser( ConnectionInfo connInfo, ScriptParseInfo scriptParseInfo, ScriptDocumentInfo scriptDocumentInfo, MetadataDisplayInfoProvider metadataDisplayInfoProvider) { AutoCompletionResult result = new AutoCompletionResult(); IEnumerable <Declaration> suggestions = SqlParserWrapper.FindCompletions( scriptParseInfo.ParseResult, scriptDocumentInfo.ParserLine, scriptDocumentInfo.ParserColumn, metadataDisplayInfoProvider); // get the completion list from SQL Parser scriptParseInfo.CurrentSuggestions = suggestions; // convert the suggestion list to the VS Code format CompletionItem[] completionList = AutoCompleteHelper.ConvertDeclarationsToCompletionItems( scriptParseInfo.CurrentSuggestions, scriptDocumentInfo.StartLine, scriptDocumentInfo.StartColumn, scriptDocumentInfo.EndColumn, scriptDocumentInfo.TokenText); result.CompleteResult(completionList); //The bucket for number of milliseconds will take to send back auto complete list connInfo.IntellisenseMetrics.UpdateMetrics(result.Duration, 1, (k2, v2) => v2 + 1); return(result); }
public void GetDefaultCompletionListWithNoMatchesTest() { var scriptFile = new ScriptFile(); scriptFile.SetFileContents("koko wants a bananas"); ScriptParseInfo scriptInfo = new ScriptParseInfo { IsConnected = false }; var scriptDocumentInfo = new TestScriptDocumentInfo( new TextDocumentPosition() { TextDocument = new TextDocumentIdentifier() { Uri = TestObjects.ScriptUri }, Position = new Position() { Line = 0, Character = 0 } }, scriptFile, scriptInfo); AutoCompleteHelper.GetDefaultCompletionItems(scriptDocumentInfo, false); }
/// <summary> /// Test the service initialization code path and verify nothing throws /// </summary> // Test is causing failures in build lab..investigating to reenable //[Fact] public void PrepopulateCommonMetadata() { InitializeTestServices(); string sqlFilePath = GetTestSqlFile(); ScriptFile scriptFile = WorkspaceService <SqlToolsSettings> .Instance.Workspace.GetFile(sqlFilePath); string ownerUri = scriptFile.ClientFilePath; var connectionService = TestObjects.GetTestConnectionService(); var connectionResult = connectionService .Connect(new ConnectParams() { OwnerUri = ownerUri, Connection = TestObjects.GetTestConnectionDetails() }); ConnectionInfo connInfo = null; connectionService.TryFindConnection(ownerUri, out connInfo); ScriptParseInfo scriptInfo = new ScriptParseInfo(); scriptInfo.IsConnected = true; AutoCompleteHelper.PrepopulateCommonMetadata(connInfo, scriptInfo, null); }
/// <summary> /// 商品名稱下拉選單 /// </summary> public ActionResult GetItemNumber() { List <Item> items = new List <Item>(); items = AutoCompleteHelper.GetItemNumberList(); return(Json(items)); }
private AutoCompletionResult CreateDefaultCompletionItems(ScriptParseInfo scriptParseInfo, ScriptDocumentInfo scriptDocumentInfo, bool useLowerCaseSuggestions) { AutoCompletionResult result = new AutoCompletionResult(); CompletionItem[] completionList = AutoCompleteHelper.GetDefaultCompletionItems(scriptDocumentInfo, useLowerCaseSuggestions); result.CompleteResult(completionList); return(result); }
public ActionResult GetProdutos(string term) { var list = ProdutoRepository.GetByRange(term, 20); var ret = list.Select(produto => AutoCompleteHelper.GetAutoCompleteItem( produto.Id.ToString(CultureInfo.InvariantCulture), produto.Descricao, produto.Descricao, "", new { preco = produto.PrecoVenda })).ToList(); return(Json(ret, JsonRequestBehavior.AllowGet)); }
public void PrepopulateCommonMetadata() { var result = TestObjects.InitLiveConnectionInfo(); var connInfo = result.ConnectionInfo; ScriptParseInfo scriptInfo = new ScriptParseInfo { IsConnected = true }; AutoCompleteHelper.PrepopulateCommonMetadata(connInfo, scriptInfo, null); }
public void PrepopulateCommonMetadata() { ScriptFile scriptFile; ConnectionInfo connInfo = TestObjects.InitLiveConnectionInfo(out scriptFile); ScriptParseInfo scriptInfo = new ScriptParseInfo { IsConnected = true }; AutoCompleteHelper.PrepopulateCommonMetadata(connInfo, scriptInfo, null); }
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(); }
/// <summary> /// 關鍵字搜尋 /// </summary> /// <param name="keyword">關鍵字</param> /// <returns></returns> public ActionResult Keyword(String keyword) { List <AutoCompleteModel> obj = new List <AutoCompleteModel>(); if (!String.IsNullOrEmpty(keyword)) { ViewBag.keyword = keyword; String[] KeywordArr = keyword.Split(' '); obj = AutoCompleteHelper.AutoSearch(KeywordArr[0]); for (int i = 1; i < KeywordArr.Length; i++) { obj = (from baseobj in obj join joinobj in AutoCompleteHelper.AutoSearch(KeywordArr[i]) on baseobj.intSeqNo equals joinobj.intSeqNo select baseobj).ToList(); } ViewBag.searchcount = obj.Count; obj = obj.OrderByDescending(x => x.dtmUpdate).Take(30).ToList(); } return(View(obj)); }
// Disable flaky test (mairvine - 3/15/2018) // [Fact] public void CompletionItemsShouldCreatedUsingSqlParserIfTheProcessDoesNotTimeout() { ConnectedBindingQueue bindingQueue = new ConnectedBindingQueue(); ScriptDocumentInfo docInfo = CreateScriptDocumentInfo(); CompletionService completionService = new CompletionService(bindingQueue); ConnectionInfo connectionInfo = new ConnectionInfo(null, null, null); bool useLowerCaseSuggestions = true; CompletionItem[] defaultCompletionList = AutoCompleteHelper.GetDefaultCompletionItems(docInfo, useLowerCaseSuggestions); List <Declaration> declarations = new List <Declaration>(); var sqlParserWrapper = new Mock <ISqlParserWrapper>(); sqlParserWrapper.Setup(x => x.FindCompletions(docInfo.ScriptParseInfo.ParseResult, docInfo.ParserLine, docInfo.ParserColumn, It.IsAny <IMetadataDisplayInfoProvider>())).Returns(declarations); completionService.SqlParserWrapper = sqlParserWrapper.Object; AutoCompletionResult result = completionService.CreateCompletions(connectionInfo, docInfo, useLowerCaseSuggestions); Assert.NotNull(result); Assert.NotEqual(result.CompletionItems == null ? 0 : result.CompletionItems.Count(), defaultCompletionList.Count()); }
public void CompletionItemsShouldCreatedUsingDefaultListIfTheSqlParserProcessTimesout() { ConnectedBindingQueue bindingQueue = new ConnectedBindingQueue(); ScriptDocumentInfo docInfo = CreateScriptDocumentInfo(); CompletionService completionService = new CompletionService(bindingQueue); ConnectionInfo connectionInfo = new ConnectionInfo(null, null, null); bool useLowerCaseSuggestions = true; List <Declaration> declarations = new List <Declaration>(); CompletionItem[] defaultCompletionList = AutoCompleteHelper.GetDefaultCompletionItems(docInfo, useLowerCaseSuggestions); var sqlParserWrapper = new Mock <ISqlParserWrapper>(); sqlParserWrapper.Setup(x => x.FindCompletions(docInfo.ScriptParseInfo.ParseResult, docInfo.ParserLine, docInfo.ParserColumn, It.IsAny <IMetadataDisplayInfoProvider>())).Callback(() => Thread.Sleep(LanguageService.BindingTimeout + 100)).Returns(declarations); completionService.SqlParserWrapper = sqlParserWrapper.Object; AutoCompletionResult result = completionService.CreateCompletions(connectionInfo, docInfo, useLowerCaseSuggestions); Assert.NotNull(result); Assert.Equal(result.CompletionItems.Count(), defaultCompletionList.Count()); Thread.Sleep(3000); Assert.True(connectionInfo.IntellisenseMetrics.Quantile.Any()); }
/// <summary> /// 取得關鍵字搜尋 /// </summary> public JsonResult GetGuide(String key) { List <AutoCompleteModel> List = AutoCompleteHelper.AutoSearch(key); return(Json(List, JsonRequestBehavior.AllowGet)); }