private SqlWord FindWord(string text) { text = this.TrimQuotationChars(text); SqlWord word = null; if (this.dbOwners.Count > 0 && this.dbOwners.Any(item => text.ToUpper() == item.ToUpper())) { word = new SqlWord() { Type = SqlWordTokenType.Owner, Text = text }; return(word); } word = this.allWords.FirstOrDefault(item => item.Text.ToUpper() == text.ToUpper() && (item.Type == SqlWordTokenType.Table || item.Type == SqlWordTokenType.View)); if (word != null) { return(word); } else { word = new SqlWord() { Text = text }; } char quotationLeftChar = this.DbInterpreter.QuotationLeftChar; char quotationRightChar = this.DbInterpreter.QuotationRightChar; string quotationNamePattern = $@"([{quotationLeftChar}]{nameWithSpacePattern}[{quotationRightChar}])"; Regex regex = new Regex($@"({namePattern}|{quotationNamePattern})[\s\n\r]+(AS[\s\n\r]+)?\b({text})\b", RegexOptions.IgnoreCase); var matches = regex.Matches(this.txtEditor.Text); string name = ""; foreach (Match match in matches) { if (match.Value.Trim().ToUpper() != text.ToUpper()) { int lastIndexOfSpace = match.Value.LastIndexOf(' '); string value = Regex.Replace(match.Value.Substring(0, lastIndexOfSpace), @" AS[\s\n\r]?", "", RegexOptions.IgnoreCase).Trim(); if (!this.keywords.Any(item => item.ToUpper() == value.ToUpper())) { name = this.TrimQuotationChars(value); break; } } } if (string.IsNullOrEmpty(name)) { name = text; } if (this.schemaInfo.Tables.Any(item => item.Name.ToUpper() == name.ToUpper())) { word.Text = name; word.Type = SqlWordTokenType.Table; } return(word); }
private void HandleKeyUpFoIntellisense(KeyEventArgs e) { if (e.KeyValue >= 112 && e.KeyValue <= 123) { this.SetWordListViewVisible(false); return; } if (e.KeyCode == Keys.Space) { this.ClearStyleForSpace(); this.SetWordListViewVisible(false); } SqlWordToken token = this.GetLastWordToken(); if (token == null || token.Text == null || token.Type != SqlWordTokenType.None) { this.SetWordListViewVisible(false); if (token != null) { if (token.Type != SqlWordTokenType.String && token.Text.Contains("'")) { this.ClearStyle(token); } } return; } if (this.panelWords.Visible) { if (this.lvWords.Tag is SqlWord word) { if (word.Type == SqlWordTokenType.Table) { string columnName = null; int index = this.txtEditor.SelectionStart; char c = this.txtEditor.Text[index - 1]; if (c != '.') { columnName = token.Text; } this.ShowTableColumns(word.Text, columnName); } else if (word.Type == SqlWordTokenType.Owner) { this.ShowDbObjects(token.Text); } return; } } if (e.KeyData == Keys.OemPeriod) { SqlWord word = this.FindWord(token.Text); if (word.Type == SqlWordTokenType.Table) { this.ShowTableColumns(word.Text); this.lvWords.Tag = word; } else if (word.Type == SqlWordTokenType.Owner) { this.ShowDbObjects(null, word.Text); this.lvWords.Tag = word; } } else if (e.KeyCode == Keys.Back) { if (this.panelWords.Visible) { if (!this.IsMatchWord(token.Text) || this.txtEditor.Text.Length == 0) { this.SetWordListViewVisible(false); } else { this.ShowWordListByToken(token); } } if (token.Text.Length > 0 && this.DbInterpreter.CommentString.Contains(token.Text.Last())) { int start = this.txtEditor.SelectionStart; int lineIndex = this.txtEditor.GetLineFromCharIndex(start); int stop = this.txtEditor.GetFirstCharIndexFromLine(lineIndex) + this.txtEditor.Lines[lineIndex].Length - 1; RichTextBoxHelper.Highlighting(this.txtEditor, this.DatabaseType, true, start, stop); } } else if (e.KeyValue < 48 || (e.KeyValue >= 58 && e.KeyValue <= 64) || (e.KeyValue >= 91 && e.KeyValue <= 96) || e.KeyValue > 122) { this.SetWordListViewVisible(false); } else { this.ShowWordListByToken(token); } }