@@ -108,14 +108,28 @@ enum SQLCompletionProvider {
108 let context = determineContext(text: text, position: wordStart)
108 let context = determineContext(text: text, position: wordStart)
110 // A table completion supplies its own surrounding quotes. If the user has
110 // A table completion supplies its own surrounding quotes. If the user has
111− // already typed an opening double-quote (common for stream names with
111+ // already typed quotes directly around the word (common for stream names
112− // spaces, e.g. `FROM "my`), absorb it into the replacement range so the
112+ // with spaces, e.g. `FROM "my"`), absorb them into the replacement range so
113− // inserted `"name"` replaces the stray quote instead of producing `""name"`.
113+ // the inserted `"name"` replaces the stray quotes instead of producing
114+ // `""name""`. Mirror `insertCompletion`, which absorbs leading and trailing
115+ // quotes independently for any `.table` item — so apply this wherever table
116+ // completions are offered (`.tableRef` and `.general`), not just `.tableRef`.
114 var replaceStart = wordStart
117 var replaceStart = wordStart
118+ var replaceEnd = wordEnd
119+ let offersTable: Bool
121+ case .tableRef, .general: offersTable = true
122+ default: offersTable = false
115− if case .tableRef = context, wordStart > 0, nsText.character(at: wordStart - 1) == 0x22 {
125+ if wordStart > 0, nsText.character(at: wordStart - 1) == 0x22 {
116− replaceStart -= 1
126+ replaceStart -= 1
128+ if wordEnd < nsText.length, nsText.character(at: wordEnd) == 0x22 {
118− let range = NSRange(location: replaceStart, length: wordEnd - replaceStart)
132+ let range = NSRange(location: replaceStart, length: replaceEnd - replaceStart)
119 let uppercasePrefix = prefix.uppercased()
133 let uppercasePrefix = prefix.uppercased()
121 var items: [SQLCompletionItem] = []
135 var items: [SQLCompletionItem] = []