Skip to content

feat: Add "Copy as SQL List" context menu commands for SQL editors#529

Open
bobcozzi wants to merge 1 commit intocodefori:mainfrom
bobcozzi:feature/delimited-list-clipboard
Open

feat: Add "Copy as SQL List" context menu commands for SQL editors#529
bobcozzi wants to merge 1 commit intocodefori:mainfrom
bobcozzi:feature/delimited-list-clipboard

Conversation

@bobcozzi
Copy link
Copy Markdown

Summary

Adds two new right-click context menu commands to SQL editors, available whenever text is selected. This addresses a feature request from the IBM i OSS community where users wanted a quick way to convert a plain newline-separated list of values (e.g. product codes, order numbers) into a SQL-friendly quoted, comma-separated list for use in IN clauses and similar constructs — without leaving VS Code to use another tool like dBeaver.

Community request: https://chat.ibmioss.org/#narrow/channel/8-vscode/topic/Seb's.20Extension.20Example.20Part.20deux/with/4188


New Commands

Db2 for i: Copy as SQL List

Instantly copies the selected newline-separated values to the clipboard using the user's current settings. No prompt — fast path for users who code quickly and want a single keystroke-style experience.

Db2 for i: Copy as SQL List (Prompt Format)

Shows a QuickPick menu with format options before copying. When the selection contains numeric values, additional unquoted variants are offered:

Option Example output
Copy as list 'S10_1678', 'S10_1949', 'S10_2016'
Copy as list (numbers unquoted) 'ABC', 123, 'DEF'
Copy wrapped in parentheses ('S10_1678', 'S10_1949', 'S10_2016')
Copy wrapped in parentheses (numbers unquoted) ('ABC', 123, 'DEF')

Both commands only appear in the context menu and command palette when a SQL file has an active text selection (editorLangId == sql && editorHasSelection).


New Settings

Setting Type Default Description
vscode-db2i.delimitedList.quoteNumbers boolean true Whether the instant-copy command quotes numeric values
vscode-db2i.delimitedList.wrapInParentheses boolean false Whether the instant-copy command wraps the list in parentheses

Implementation Notes

  • SQL-safe quoting: Internal single quotes are escaped as '' (e.g. O'Brien'O''Brien')
  • Blank line filtering: Empty/whitespace-only lines in the selection are silently ignored
  • Large selection guard: A modal confirmation is shown if more than 256 values are selected
  • Clipboard error handling: clipboard.writeText() failures surface a descriptive error message rather than failing silently
  • New file: src/language/clipboard.ts — follows the same initialise(context) pattern as src/language/json.ts

Adds two new right-click editor commands for SQL files when text is selected:

- 'Copy as SQL List' - instant clipboard copy using user settings
- 'Copy as SQL List (Prompt Format)' - QuickPick with format options

Values are single-quoted and internal single quotes are escaped (SQL-safe).
When the selection contains numeric values, additional unquoted variants
are offered in the prompt.

New settings:
  vscode-db2i.delimitedList.quoteNumbers (default: true)
  vscode-db2i.delimitedList.wrapInParentheses (default: false)

Addresses community request: https://chat.ibmioss.org/#narrow/channel/8-vscode/topic/Seb's.20Extension.20Example.20Part.20deux/with/4188
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant