@@ -108,14 +108,28 @@ enum SQLCompletionProvider {
108108 let context = determineContext(text: text, position: wordStart)
109109
110110 // A table completion supplies its own surrounding quotes. If the user has
111− // already typed an opening double-quote (common for stream names with
112− // spaces, e.g. `FROM "my`), absorb it into the replacement range so the
113− // inserted `"name"` replaces the stray quote instead of producing `""name"`.
111+ // already typed quotes directly around the word (common for stream names
112+ // with spaces, e.g. `FROM "my"`), absorb them into the replacement range so
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`.
114117 var replaceStart = wordStart
115− if case .tableRef = context, wordStart > 0, nsText.character(at: wordStart - 1) == 0x22 {
116− replaceStart -= 1
118+ var replaceEnd = wordEnd
119+ let offersTable: Bool
120+ switch context {
121+ case .tableRef, .general: offersTable = true
122+ default: offersTable = false
123+ }
124+ if offersTable {
125+ if wordStart > 0, nsText.character(at: wordStart - 1) == 0x22 {
126+ replaceStart -= 1
127+ }
128+ if wordEnd < nsText.length, nsText.character(at: wordEnd) == 0x22 {
129+ replaceEnd += 1
130+ }
117131 }
118− let range = NSRange(location: replaceStart, length: wordEnd - replaceStart)
132+ let range = NSRange(location: replaceStart, length: replaceEnd - replaceStart)
119133 let uppercasePrefix = prefix.uppercased()
120134
121135 var items: [SQLCompletionItem] = []