From 2230defb70cec7eeec3b1d2e7a4588d5f96dae16 Mon Sep 17 00:00:00 2001 From: EmilySeville7cfg Date: Sat, 29 Jul 2023 16:35:14 +1000 Subject: [PATCH 01/10] feat(snippets): make more user friendly --- server/src/snippets.ts | 458 ++++++++++++++++++++++++++++++++++++----- 1 file changed, 402 insertions(+), 56 deletions(-) diff --git a/server/src/snippets.ts b/server/src/snippets.ts index 5ecb2e3c8..f9107ad15 100644 --- a/server/src/snippets.ts +++ b/server/src/snippets.ts @@ -1,7 +1,6 @@ /** * Naming convention for `documentation`: * - for Bash operators it's ' operator' - * - for Bash parameter expansions it's ' expansion' * - for Bash documentation it's 'documentation definition' or '"" documentation definition' * - for Bash functions it's 'function definition' or '"" function definition' * - for Bash builtins it's '"" invocation' @@ -10,7 +9,7 @@ * - for anything else it's any string * * Naming convention for `label`: - * - for shell shebang it's 'shebang' + * - for shell shebang it's 'shebang' or 'shebang-with-arguments' * - for Bash operators it's '[]', where: * - is Bash operator * - is 'test' @@ -41,91 +40,438 @@ export const SNIPPETS: BashCompletionItem[] = [ insertText: '#!/usr/bin/env ${1|bash,sh|}', }, { - documentation: 'if operator', + documentation: 'shebang-with-arguments', + label: 'shebang-with-arguments', + insertText: '#!/usr/bin/env ${1|-S,--split-string|} ${2|bash,sh|} ${3|argument ...|}', + }, + { + label: 'and', + documentation: 'and operator', + insertText: '${1:first-expression} && ${2:second-expression}', + }, + { + label: 'or', + documentation: 'or operator', + insertText: '${1:first-expression} || ${2:second-expression}', + }, + { label: 'if', - insertText: ['if ${1:command}; then', '\t$0', 'fi'].join('\n'), + documentation: 'if operator', + insertText: ['if ${1:condition}; then', '\t${2:command ...}', 'fi'].join('\n'), }, { - documentation: 'if else operator', label: 'if-else', - insertText: ['if ${1:command}; then', '\t${2:echo}', 'else', '\t$0', 'fi'].join('\n'), + documentation: 'if-else operator', + insertText: [ + 'if ${1:condition}; then', + '\t${2:command ...}', + 'else', + '\t${3:command ...}', + 'fi', + ].join('\n'), }, { - documentation: 'if operator', - label: 'if-test', + label: 'if-less', + documentation: 'if with number comparison', insertText: [ - 'if [[ ${1:variable} ${2|-ef,-nt,-ot,==,=~,!=,<,>,-lt,-le,-gt,-ge|} ${3:variable} ]]; then', - '\t$0', + 'if (( "${1:first-expression}" < "${2:second-expression}" )); then', + '\t${3:command ...}', 'fi', ].join('\n'), }, { - documentation: 'if else operator', - label: 'if-else-test', + label: 'if-greater', + documentation: 'if with number comparison', insertText: [ - 'if [[ ${1:variable} ${2|-ef,-nt,-ot,==,=~,!=,<,>,-lt,-le,-gt,-ge|} ${3:variable} ]]; then', - 'else', - '\t$0', + 'if (( "${1:first-expression}" > "${2:second-expression}" )); then', + '\t${3:command ...}', 'fi', ].join('\n'), }, { - documentation: 'while operator', - label: 'while', - insertText: ['while ${1:command}; do', '\t$0', 'done'].join('\n'), + label: 'if-less-or-equal', + documentation: 'if with number comparison', + insertText: [ + 'if (( "${1:first-expression}" <= "${2:second-expression}" )); then', + '\t${3:command ...}', + 'fi', + ].join('\n'), + }, + { + label: 'if-greater-or-equal', + documentation: 'if with number comparison', + insertText: [ + 'if (( "${1:first-expression}" >= "${2:second-expression}" )); then', + '\t${3:command ...}', + 'fi', + ].join('\n'), + }, + { + label: 'if-equal', + documentation: 'if with number comparison', + insertText: [ + 'if (( "${1:first-expression}" == "${2:second-expression}" )); then', + '\t${3:command ...}', + 'fi', + ].join('\n'), + }, + { + label: 'if-not-equal', + documentation: 'if with number comparison', + insertText: [ + 'if (( "${1:first-expression}" != "${2:second-expression}" )); then', + '\t${3:command ...}', + 'fi', + ].join('\n'), + }, + { + label: 'if-string-equal', + documentation: 'if with string comparison', + insertText: [ + 'if [[ "${1:first-expression}" == "${2:second-expression}" ]]; then', + '\t${3:command ...}', + 'fi', + ].join('\n'), + }, + { + label: 'if-string-not-equal', + documentation: 'if with string comparison', + insertText: [ + 'if [[ "${1:first-expression}" != "${2:second-expression}" ]]; then', + '\t${3:command ...}', + 'fi', + ].join('\n'), + }, + { + label: 'if-string-empty', + documentation: 'if with string comparison (has [z]ero length)', + insertText: ['if [[ -z "${1:expression}" ]]; then', '\t${2:command ...}', 'fi'].join( + '\n', + ), + }, + { + label: 'if-string-not-empty', + documentation: 'if with string comparison ([n]ot empty)', + insertText: ['if [[ -n "${1:expression}" ]]; then', '\t${2:command ...}', 'fi'].join( + '\n', + ), + }, + { + label: 'if-defined', + documentation: 'if with variable existence check', + insertText: ['if [[ -n "${${1:variable}+x}" ]]', '\t${2:command ...}', 'fi'].join( + '\n', + ), }, { + label: 'if-not-defined', + documentation: 'if with variable existence check', + insertText: ['if [[ -z "${${1:variable}+x}" ]]', '\t${2:command ...}', 'fi'].join( + '\n', + ), + }, + { + label: 'while', documentation: 'while operator', - label: 'while-test', + insertText: ['while ${1:condition}; do', '\t${2:command ...}', 'done'].join('\n'), + }, + { + label: 'while-else', + documentation: 'while-else operator', insertText: [ - 'while [[ ${1:variable} ${2|-ef,-nt,-ot,==,=~,!=,<,>,-lt,-le,-gt,-ge|} ${3:variable} ]]; do', - '\t$0', + 'while ${1:condition}; do', + '\t${2:command ...}', + 'else', + '\t${3:command ...}', 'done', ].join('\n'), }, { - documentation: 'until operator', - label: 'until', - insertText: ['until ${1:command}; do', '\t$0', 'done'].join('\n'), + label: 'while-less', + documentation: 'while with number comparison', + insertText: [ + 'while (( "${1:first-expression}" < "${2:second-expression}" )); do', + '\t${3:command ...}', + 'done', + ].join('\n'), + }, + { + label: 'while-greater', + documentation: 'while with number comparison', + insertText: [ + 'while (( "${1:first-expression}" > "${2:second-expression}" )); do', + '\t${3:command ...}', + 'done', + ].join('\n'), + }, + { + label: 'while-less-or-equal', + documentation: 'while with number comparison', + insertText: [ + 'while (( "${1:first-expression}" <= "${2:second-expression}" )); do', + '\t${3:command ...}', + 'done', + ].join('\n'), + }, + { + label: 'while-greater-or-equal', + documentation: 'while with number comparison', + insertText: [ + 'while (( "${1:first-expression}" >= "${2:second-expression}" )); do', + '\t${3:command ...}', + 'done', + ].join('\n'), + }, + { + label: 'while-equal', + documentation: 'while with number comparison', + insertText: [ + 'while (( "${1:first-expression}" == "${2:second-expression}" )); do', + '\t${3:command ...}', + 'done', + ].join('\n'), + }, + { + label: 'while-not-equal', + documentation: 'while with number comparison', + insertText: [ + 'while (( "${1:first-expression}" != "${2:second-expression}" )); do', + '\t${3:command ...}', + 'done', + ].join('\n'), + }, + { + label: 'while-string-equal', + documentation: 'while with string comparison', + insertText: [ + 'while [[ "${1:first-expression}" == "${2:second-expression}" ]]; do', + '\t${3:command ...}', + 'done', + ].join('\n'), + }, + { + label: 'while-string-not-equal', + documentation: 'while with string comparison', + insertText: [ + 'while [[ "${1:first-expression}" != "${2:second-expression}" ]]; do', + '\t${3:command ...}', + 'done', + ].join('\n'), + }, + { + label: 'while-string-empty', + documentation: 'while with string comparison (has [z]ero length)', + insertText: [ + 'while [[ -z "${1:expression}" ]]; do', + '\t${2:command ...}', + 'done', + ].join('\n'), }, { + label: 'while-string-not-empty', + documentation: 'while with string comparison ([n]ot empty)', + insertText: [ + 'while [[ -n "${1:expression}" ]]; do', + '\t${2:command ...}', + 'done', + ].join('\n'), + }, + { + label: 'while-defined', + documentation: 'while with variable existence check', + insertText: [ + 'while [[ -n "${${1:variable}+x}" ]]', + '\t${2:command ...}', + 'done', + ].join('\n'), + }, + { + label: 'while-not-defined', + documentation: 'while with variable existence check', + insertText: [ + 'while [[ -z "${${1:variable}+x}" ]]', + '\t${2:command ...}', + 'done', + ].join('\n'), + }, + { + label: 'until', documentation: 'until operator', - label: 'until-test', + insertText: ['until ${1:condition}; do', '\t${2:command ...}', 'done'].join('\n'), + }, + { + label: 'until-else', + documentation: 'until-else operator', insertText: [ - 'until [[ ${1:variable} ${2|-ef,-nt,-ot,==,=~,!=,<,>,-lt,-le,-gt,-ge|} ${3:variable} ]]; do', - '\t$0', + 'until ${1:condition}; do', + '\t${2:command ...}', + 'else', + '\t${3:command ...}', 'done', ].join('\n'), }, { - documentation: 'for operator', - label: 'for', - insertText: ['for ${1:variable} in ${2:list}; do', '\t$0', 'done'].join('\n'), + label: 'until-less', + documentation: 'until with number comparison', + insertText: [ + 'until (( "${1:first-expression}" < "${2:second-expression}" )); do', + '\t${3:command ...}', + 'done', + ].join('\n'), }, { - documentation: 'for operator', - label: 'for.range', - insertText: ['for ${1:variable} in $(seq ${2:to}); do', '\t$0', 'done'].join('\n'), + label: 'until-greater', + documentation: 'until with number comparison', + insertText: [ + 'until (( "${1:first-expression}" > "${2:second-expression}" )); do', + '\t${3:command ...}', + 'done', + ].join('\n'), }, { - documentation: 'for operator', - label: 'for.file', - insertText: ['for ${1:variable} in *; do', '\t$0', 'done'].join('\n'), + label: 'until-less-or-equal', + documentation: 'until with number comparison', + insertText: [ + 'until (( "${1:first-expression}" <= "${2:second-expression}" )); do', + '\t${3:command ...}', + 'done', + ].join('\n'), + }, + { + label: 'until-greater-or-equal', + documentation: 'until with number comparison', + insertText: [ + 'until (( "${1:first-expression}" >= "${2:second-expression}" )); do', + '\t${3:command ...}', + 'done', + ].join('\n'), + }, + { + label: 'until-equal', + documentation: 'until with number comparison', + insertText: [ + 'until (( "${1:first-expression}" == "${2:second-expression}" )); do', + '\t${3:command ...}', + 'done', + ].join('\n'), + }, + { + label: 'until-not-equal', + documentation: 'until with number comparison', + insertText: [ + 'until (( "${1:first-expression}" != "${2:second-expression}" )); do', + '\t${3:command ...}', + 'done', + ].join('\n'), + }, + { + label: 'until-string-equal', + documentation: 'until with string comparison', + insertText: [ + 'until [[ "${1:first-expression}" == "${2:second-expression}" ]]; do', + '\t${3:command ...}', + 'done', + ].join('\n'), + }, + { + label: 'until-string-not-equal', + documentation: 'until with string comparison', + insertText: [ + 'until [[ "${1:first-expression}" != "${2:second-expression}" ]]; do', + '\t${3:command ...}', + 'done', + ].join('\n'), + }, + { + label: 'until-string-empty', + documentation: 'until with string comparison (has [z]ero length)', + insertText: [ + 'until [[ -z "${1:expression}" ]]; do', + '\t${2:command ...}', + 'done', + ].join('\n'), + }, + { + label: 'until-string-not-empty', + documentation: 'until with string comparison ([n]ot empty)', + insertText: [ + 'until [[ -n "${1:expression}" ]]; do', + '\t${2:command ...}', + 'done', + ].join('\n'), + }, + { + label: 'until-defined', + documentation: 'until with variable existence check', + insertText: [ + 'until [[ -n "${${1:variable}+x}" ]]', + '\t${2:command ...}', + 'done', + ].join('\n'), + }, + { + label: 'until-not-defined', + documentation: 'until with variable existence check', + insertText: [ + 'until [[ -z "${${1:variable}+x}" ]]', + '\t${2:command ...}', + 'done', + ].join('\n'), }, { + label: 'for', documentation: 'for operator', - label: 'for.directory', - insertText: ['for ${1:variable} in */; do', '\t$0', 'done'].join('\n'), + insertText: [ + 'for ${1:item} in ${2:expression}; do', + '\t${3:command ...}', + 'done', + ].join('\n'), }, { - documentation: 'function definition', - label: 'function', - insertText: ['${1:function_name}() {', '\t$0', '}'].join('\n'), + label: 'for-range', + documentation: 'for with range', + insertText: [ + 'for ${1:item} in $(seq ${2:from} ${3:to}); do', + '\t${4:command ...}', + 'done', + ].join('\n'), }, { - documentation: '"main" function definition', - label: 'main', - insertText: ['main() {', '\t$0', '}'].join('\n'), + label: 'for-stepped-range', + documentation: 'for with stepped range', + insertText: [ + 'for ${1:item} in $(seq ${2:from} ${3:step} ${4:to}); do', + '\t${5:command ...}', + 'done', + ].join('\n'), + }, + { + label: 'for-files', + documentation: 'for with files', + insertText: [ + 'for ${1:item} in *.${2:extension}; do', + '\t${4:command ...}', + 'done', + ].join('\n'), + }, + { + label: 'case', + documentation: 'case operator', + insertText: [ + 'case "${1:expression}" in', + '\t${2:pattern})', + '\t\t${3:command ...}', + '\t\t;;', + '\t*)', + '\t\t${4:command ...}', + '\t\t;;', + 'end', + ].join('\n'), + }, + { + label: 'function', + documentation: 'function definition', + insertText: ['${1:name}() {', '\t${2:command ...}', '}'].join('\n'), }, { documentation: 'documentation definition', @@ -143,62 +489,62 @@ export const SNIPPETS: BashCompletionItem[] = [ ].join('\n'), }, { - documentation: ':- expansion', + documentation: 'if unset or null', label: 'if-unset-or-null', insertText: '"\\${${1:variable}:-${2:default}}"', }, { - documentation: '- expansion', + documentation: 'if unset', label: 'if-unset', insertText: '"\\${${1:variable}-${2:default}}"', }, { - documentation: ':= expansion', + documentation: 'set if unset or null', label: 'set-if-unset-or-null', insertText: '"\\${${1:variable}:=${2:default}}"', }, { - documentation: '= expansion', + documentation: 'set if unset', label: 'set-if-unset', insertText: '"\\${${1:variable}=${2:default}}"', }, { - documentation: ':? expansion', + documentation: 'error if unset or null', label: 'error-if-unset-or-null', insertText: '"\\${${1:variable}:?${2:error_message}}"', }, { - documentation: '? expansion', + documentation: 'error if unset', label: 'error-if-unset', insertText: '"\\${${1:variable}?${2:error_message}}"', }, { - documentation: ':+ expansion', + documentation: 'if set or not null', label: 'if-set-or-not-null', insertText: '"\\${${1:variable}:+${2:alternative}}"', }, { - documentation: '+ expansion', + documentation: 'if set', label: 'if-set', insertText: '"\\${${1:variable}+${2:alternative}}"', }, { - documentation: '# expansion', + documentation: 'without shortest leading pattern', label: 'without-shortest-leading-pattern', insertText: '"\\${${1:variable}#${2:pattern}}"', }, { - documentation: '## expansion', + documentation: 'without longest leading pattern', label: 'without-longest-leading-pattern', insertText: '"\\${${1:variable}##${2:pattern}}"', }, { - documentation: '% expansion', + documentation: 'without shortest trailing pattern', label: 'without-shortest-trailing-pattern', insertText: '"\\${${1:variable}%${2:pattern}}"', }, { - documentation: '%% expansion', + documentation: 'without longest trailing pattern', label: 'without-longest-trailing-pattern', insertText: '"\\${${1:variable}%%${2:pattern}}"', }, From 1f4e6dc73006f96390481e4b7a26c2d315e67382 Mon Sep 17 00:00:00 2001 From: EmilySeville7cfg Date: Wed, 2 Aug 2023 22:24:54 +1000 Subject: [PATCH 02/10] feat(snippets): sync with Fish --- server/src/snippets.ts | 285 +++++++++++------------------------------ 1 file changed, 75 insertions(+), 210 deletions(-) diff --git a/server/src/snippets.ts b/server/src/snippets.ts index f9107ad15..aca133298 100644 --- a/server/src/snippets.ts +++ b/server/src/snippets.ts @@ -488,6 +488,53 @@ export const SNIPPETS: BashCompletionItem[] = [ '# - ${7:1} ${8:otherwise}', ].join('\n'), }, + { + documentation: 'block', + label: 'block', + insertText: [ + '{', + '\t${1:command ...}', + '}', + ].join('\n'), + }, + { + documentation: 'block redirected', + label: 'block-redirected', + insertText: [ + '{', + '\t${1:command ...}', + '} > ${2:file}', + ].join('\n'), + }, + { + documentation: 'block stderr redirected', + label: 'block-stderr-redirected', + insertText: [ + '{', + '\t${1:command ...}', + '} 2> ${2:file}', + ].join('\n'), + }, + { + documentation: 'variable', + label: 'variable', + insertText: 'declare ${1:variable}=${2:value}', + }, + { + documentation: 'variable index', + label: 'variable-index', + insertText: '${1:variable}[${2:index}]=${3:value}', + }, + { + documentation: 'variable append', + label: 'variable-append', + insertText: '${1:variable}+=${2:value}', + }, + { + documentation: 'variable-prepend', + label: 'variable-prepend', + insertText: '${1:variable}=${2:value}\\$$1', + }, { documentation: 'if unset or null', label: 'if-unset-or-null', @@ -529,244 +576,62 @@ export const SNIPPETS: BashCompletionItem[] = [ insertText: '"\\${${1:variable}+${2:alternative}}"', }, { - documentation: 'without shortest leading pattern', - label: 'without-shortest-leading-pattern', + documentation: 'string shortest leading replacement', + label: 'string-remove-leading', insertText: '"\\${${1:variable}#${2:pattern}}"', }, { - documentation: 'without longest leading pattern', - label: 'without-longest-leading-pattern', - insertText: '"\\${${1:variable}##${2:pattern}}"', - }, - { - documentation: 'without shortest trailing pattern', - label: 'without-shortest-trailing-pattern', + documentation: 'string shortest trailing replacement', + label: 'string-remove-trailing', insertText: '"\\${${1:variable}%${2:pattern}}"', }, { - documentation: 'without longest trailing pattern', - label: 'without-longest-trailing-pattern', - insertText: '"\\${${1:variable}%%${2:pattern}}"', + documentation: 'string-match', + label: 'string filtering', + insertText: 'sed ${1|-E -n,--regexp-extended --quiet|} \'/${2:pattern}/p\'', }, { - documentation: '.. expansion', - label: 'range', - insertText: '{${1:from}..${2:to}}', + documentation: 'string-replace', + label: 'string replacement', + insertText: 'sed ${1|-E,--regexp-extended|} \'s/${2:pattern}/${3:replacement}/\'', }, { - documentation: '"echo" invocation', - label: 'echo', - insertText: 'echo "${1:message}"', + documentation: 'string-replace-all', + label: 'string replacement', + insertText: 'sed ${1|-E,--regexp-extended|} \'s/${2:pattern}/${3:replacement}/g\'', }, { - documentation: '"printf" invocation', - label: 'printf', + documentation: 'string-transliterate', + label: 'string-transliterate', insertText: - 'printf \'${1|%c,%s,%d,%f,%15c,%15s,%15d,%15f,%.5s,%.5d,%.5f|}\' "${2:message}"', + "sed ${1|-E,--regexp-extended|} 'y/${2:source-characters}/${3:replacement-characters}/g'", }, { - documentation: '"source" invocation', - label: 'source', - insertText: '${1|source,.|} "${2:path/to/file}"', + documentation: 'file print', + label: 'file-print', + insertText: "sed '' ${1:file}", }, { - documentation: '"alias" invocation', - label: 'alias', - insertText: 'alias ${1:name}=${2:value}', - }, - { - documentation: '"cd" invocation', - label: 'cd', - insertText: 'cd "${1:path/to/directory}"', - }, - { - documentation: '"getopts" invocation', - label: 'getopts', - insertText: 'getopts ${1:optstring} ${2:name}', - }, - { - documentation: '"jobs" invocation', - label: 'jobs', - insertText: 'jobs -x ${1:command}', - }, - { - documentation: '"kill" invocation', - label: 'kill', - insertText: 'kill ${1|-l,-L|}', - }, - { - documentation: '"let" invocation', - label: 'let', - insertText: 'let ${1:argument}', - }, - { - documentation: '"test" invocation', - label: 'test', - insertText: - '[[ ${1:argument1} ${2|-ef,-nt,-ot,==,=,!=,=~,<,>,-eq,-ne,-lt,-le,-gt,-ge|} ${3:argument2} ]]', - }, - { - documentation: 'line print', - label: 'sed:print', - insertText: "sed '' ${1:path/to/file}", - }, - { - documentation: 'line pattern filter', - label: 'sed:filter-by-line-pattern', - insertText: - "sed ${1|--regexp-extended,-E|} ${2|--quiet,-n|} '/${3:pattern}/p' ${4:path/to/file}", - }, - { - documentation: 'line number filter', - label: 'sed:filter-by-line-number', - insertText: - "sed ${1|--regexp-extended,-E|} ${2|--quiet,-n|} '${3:number}p' ${4:path/to/file}", - }, - { - documentation: 'line number filter', - label: 'sed:filter-by-line-numbers', - insertText: - "sed ${1|--regexp-extended,-E|} ${2|--quiet,-n|} '${3:from},${4:to}p' ${5:path/to/file}", - }, - { - documentation: 'single replacement', - label: 'sed:replace-first', + documentation: 'file read', + label: 'file-read', insertText: - "sed ${1|--regexp-extended,-E|} 's/${2:pattern}/${3:replacement}/' ${4:path/to/file}", - }, - { - documentation: 'global replacement', - label: 'sed:replace-all', - insertText: - "sed ${1|--regexp-extended,-E|} 's/${2:pattern}/${3:replacement}/g' ${4:path/to/file}", - }, - { - documentation: 'transliteration', - label: 'sed:transliterate', - insertText: - "sed ${1|--regexp-extended,-E|} 'y/${2:source-characters}/${3:replacement-characters}/g' ${4:path/to/file}", - }, - { - documentation: 'whole file read', - label: 'sed:read-all', - insertText: - "sed ${1|--regexp-extended,-E|} ':${2:x} N $! b$2 ${3:command}' ${4:path/to/file}", - }, - { - documentation: 'line print', - label: 'awk:print', - insertText: "awk '/./' ${1:path/to/file}", - }, - { - documentation: 'line pattern filter', - label: 'awk:filter-by-line-pattern', - insertText: "awk '/${1:pattern}/' ${2:path/to/file}", - }, - { - documentation: 'line number filter', - label: 'awk:filter-by-line-number', - insertText: "awk 'NR == ${1:number}' ${2:path/to/file}", - }, - { - documentation: 'line number filter', - label: 'awk:filter-by-line-numbers', - insertText: "awk 'NR >= ${1:from} && NR <= ${2:to}' ${3:path/to/file}", - }, - { - documentation: 'single replacement', - label: 'awk:replace-first', - insertText: 'awk \'{ sub("${1:pattern}", "${2:replacement}") }\' ${3:path/to/file}', - }, - { - documentation: 'global replacement', - label: 'awk:replace-all', - insertText: 'awk \'{ gsub("${1:pattern}", "${2:replacement}") }\' ${3:path/to/file}', - }, - { - documentation: 'whole file read', - label: 'awk:read-all', - insertText: "awk RS='^$' '{ ${1:command} }' ${2:path/to/file}", + "sed ${1|-E,--regexp-extended|} ':${2:x} N $! b$2 ${3:command}' ${4:file}", }, { documentation: 'node print', - label: 'jq:print', - insertText: "jq '.${1:path/to/node}' ${2:path/to/file}", + label: 'json', + insertText: "jq '.${1:node}' ${2:file}", }, { documentation: 'node print', - label: 'yq:print', - insertText: "yq '.${1:path/to/node}' ${2:path/to/file}", - }, - { - documentation: 'home directory', - label: '~', - insertText: '$HOME', + label: 'json', + insertText: "jq '.${1:node}' ${2:file}", }, { - documentation: '[dev]ice name', - label: 'dev', + documentation: 'device', + label: 'device', insertText: '/dev/${1|null,stdin,stdout,stderr|}', }, - { - documentation: '[al]pha[num]eric characters', - label: 'alnum', - insertText: '[[:alnum:]]', - }, - { - documentation: '[alpha]betic characters', - label: 'alpha', - insertText: '[[:alpha:]]', - }, - { - documentation: '[blank] characters', - label: 'blank', - insertText: '[[:blank:]]', - }, - { - documentation: '[c]o[nt]ro[l] characters', - label: 'cntrl', - insertText: '[[:cntrl:]]', - }, - { - documentation: '[digit] characters', - label: 'digit', - insertText: '[[:digit:]]', - }, - { - documentation: '[graph]ical characters', - label: 'graph', - insertText: '[[:graph:]]', - }, - { - documentation: '[lower] characters', - label: 'lower', - insertText: '[[:lower:]]', - }, - { - documentation: '[print]able characters', - label: 'print', - insertText: '[[:print:]]', - }, - { - documentation: '[punct]uation characters', - label: 'punct', - insertText: '[[:punct:]]', - }, - { - documentation: '[space] characters', - label: 'space', - insertText: '[[:space:]]', - }, - { - documentation: '[upper] characters', - label: 'upper', - insertText: '[[:upper:]]', - }, - { - documentation: 'hexadecimal characters', - label: 'xdigit', - insertText: '[[:xdigit:]]', - }, ].map((item) => ({ ...item, documentation: { From 65b710fa6d3e7a0b8e40d68c8a19c31d51b7ba55 Mon Sep 17 00:00:00 2001 From: EmilySeville7cfg Date: Wed, 2 Aug 2023 22:30:05 +1000 Subject: [PATCH 03/10] fix(snippets): reformat and remove JSON snippet --- server/src/snippets.ts | 31 +++++++------------------------ 1 file changed, 7 insertions(+), 24 deletions(-) diff --git a/server/src/snippets.ts b/server/src/snippets.ts index aca133298..aa90a910d 100644 --- a/server/src/snippets.ts +++ b/server/src/snippets.ts @@ -491,29 +491,17 @@ export const SNIPPETS: BashCompletionItem[] = [ { documentation: 'block', label: 'block', - insertText: [ - '{', - '\t${1:command ...}', - '}', - ].join('\n'), + insertText: ['{', '\t${1:command ...}', '}'].join('\n'), }, { documentation: 'block redirected', label: 'block-redirected', - insertText: [ - '{', - '\t${1:command ...}', - '} > ${2:file}', - ].join('\n'), + insertText: ['{', '\t${1:command ...}', '} > ${2:file}'].join('\n'), }, { documentation: 'block stderr redirected', label: 'block-stderr-redirected', - insertText: [ - '{', - '\t${1:command ...}', - '} 2> ${2:file}', - ].join('\n'), + insertText: ['{', '\t${1:command ...}', '} 2> ${2:file}'].join('\n'), }, { documentation: 'variable', @@ -588,17 +576,17 @@ export const SNIPPETS: BashCompletionItem[] = [ { documentation: 'string-match', label: 'string filtering', - insertText: 'sed ${1|-E -n,--regexp-extended --quiet|} \'/${2:pattern}/p\'', + insertText: "sed ${1|-E -n,--regexp-extended --quiet|} '/${2:pattern}/p'", }, { documentation: 'string-replace', label: 'string replacement', - insertText: 'sed ${1|-E,--regexp-extended|} \'s/${2:pattern}/${3:replacement}/\'', + insertText: "sed ${1|-E,--regexp-extended|} 's/${2:pattern}/${3:replacement}/'", }, { documentation: 'string-replace-all', label: 'string replacement', - insertText: 'sed ${1|-E,--regexp-extended|} \'s/${2:pattern}/${3:replacement}/g\'', + insertText: "sed ${1|-E,--regexp-extended|} 's/${2:pattern}/${3:replacement}/g'", }, { documentation: 'string-transliterate', @@ -618,12 +606,7 @@ export const SNIPPETS: BashCompletionItem[] = [ "sed ${1|-E,--regexp-extended|} ':${2:x} N $! b$2 ${3:command}' ${4:file}", }, { - documentation: 'node print', - label: 'json', - insertText: "jq '.${1:node}' ${2:file}", - }, - { - documentation: 'node print', + documentation: 'json print', label: 'json', insertText: "jq '.${1:node}' ${2:file}", }, From 342f9b4fd20a564f5ddd8df04594f72f3760ed92 Mon Sep 17 00:00:00 2001 From: EmilySeville7cfg Date: Wed, 2 Aug 2023 22:40:17 +1000 Subject: [PATCH 04/10] feat(snippets): snip/take snippets --- server/src/snippets.ts | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/server/src/snippets.ts b/server/src/snippets.ts index aa90a910d..54d87c723 100644 --- a/server/src/snippets.ts +++ b/server/src/snippets.ts @@ -605,6 +605,36 @@ export const SNIPPETS: BashCompletionItem[] = [ insertText: "sed ${1|-E,--regexp-extended|} ':${2:x} N $! b$2 ${3:command}' ${4:file}", }, + { + documentation: 'skip-first', + label: 'skip-first', + insertText: 'tail ${1|-n,-c,--lines,--bytes|} +${2:count}', + }, + { + documentation: 'skip-last', + label: 'skip-last', + insertText: 'head ${1|-n,-c,--lines,--bytes|} -${2:count}', + }, + { + documentation: 'take-first', + label: 'take-first', + insertText: 'head ${1|-n,-c,--lines,--bytes|} ${2:count}', + }, + { + documentation: 'take-last', + label: 'take-last', + insertText: 'tail ${1|-n,-c,--lines,--bytes|} ${2:count}', + }, + { + documentation: 'take-range', + label: 'take-range', + insertText: "sed ${1|-n,--quiet|} '${2:from},${3:to}p'", + }, + { + documentation: 'take-stepped-range', + label: 'take-stepped-range', + insertText: "sed ${1|-n,--quiet|} '${2:from},${3:to}p' | sed $1 '1~${4:step}p'", + }, { documentation: 'json print', label: 'json', From c2c38a617be87c36ce95a23e50882f790a4fe315 Mon Sep 17 00:00:00 2001 From: EmilySeville7cfg Date: Wed, 2 Aug 2023 22:43:24 +1000 Subject: [PATCH 05/10] feat(snippets): simplify naming convention --- server/src/snippets.ts | 6 ------ 1 file changed, 6 deletions(-) diff --git a/server/src/snippets.ts b/server/src/snippets.ts index 54d87c723..42a99f9ed 100644 --- a/server/src/snippets.ts +++ b/server/src/snippets.ts @@ -3,7 +3,6 @@ * - for Bash operators it's ' operator' * - for Bash documentation it's 'documentation definition' or '"" documentation definition' * - for Bash functions it's 'function definition' or '"" function definition' - * - for Bash builtins it's '"" invocation' * - for Bash character classes it's any string with optional mnemonics depicted via square brackets * - for shell shebang it's 'shebang' * - for anything else it's any string @@ -20,13 +19,8 @@ * used when expansion modifies variable or prints error to stderr * - is 'if-(set|unset)[-or-[not-]null]' * - term delimiter: dash, like 'set-if-unset-or-null' - * - for Bash brace expansion it's 'range' * - for Bash documentation it's one of 'documentation'/'' * - for Bash functions it's one of 'function'/'' - * - for Bash builtins it's '' - * - for Bash character classes it's '' - * - for Sed it's 'sed:' - * - for Awk it's 'awk:' * - for anything else it's any string */ import { CompletionItemKind, InsertTextFormat, MarkupKind } from 'vscode-languageserver' From ca7d4aa0d924f75b068de16b78c4ab0f5e902d6c Mon Sep 17 00:00:00 2001 From: EmilySeville7cfg Date: Wed, 2 Aug 2023 22:48:38 +1000 Subject: [PATCH 06/10] fix(snippets): labels --- server/src/snippets.ts | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/server/src/snippets.ts b/server/src/snippets.ts index 42a99f9ed..02ed35c71 100644 --- a/server/src/snippets.ts +++ b/server/src/snippets.ts @@ -568,22 +568,22 @@ export const SNIPPETS: BashCompletionItem[] = [ insertText: '"\\${${1:variable}%${2:pattern}}"', }, { - documentation: 'string-match', - label: 'string filtering', + documentation: 'string filtering', + label: 'string-match', insertText: "sed ${1|-E -n,--regexp-extended --quiet|} '/${2:pattern}/p'", }, { - documentation: 'string-replace', - label: 'string replacement', + documentation: 'string replacement', + label: 'string-replace', insertText: "sed ${1|-E,--regexp-extended|} 's/${2:pattern}/${3:replacement}/'", }, { - documentation: 'string-replace-all', - label: 'string replacement', + documentation: 'string replacement', + label: 'string-replace-all', insertText: "sed ${1|-E,--regexp-extended|} 's/${2:pattern}/${3:replacement}/g'", }, { - documentation: 'string-transliterate', + documentation: 'string transliterate', label: 'string-transliterate', insertText: "sed ${1|-E,--regexp-extended|} 'y/${2:source-characters}/${3:replacement-characters}/g'", @@ -600,38 +600,38 @@ export const SNIPPETS: BashCompletionItem[] = [ "sed ${1|-E,--regexp-extended|} ':${2:x} N $! b$2 ${3:command}' ${4:file}", }, { - documentation: 'skip-first', + documentation: 'skip first', label: 'skip-first', insertText: 'tail ${1|-n,-c,--lines,--bytes|} +${2:count}', }, { - documentation: 'skip-last', + documentation: 'skip last', label: 'skip-last', insertText: 'head ${1|-n,-c,--lines,--bytes|} -${2:count}', }, { - documentation: 'take-first', + documentation: 'take first', label: 'take-first', insertText: 'head ${1|-n,-c,--lines,--bytes|} ${2:count}', }, { - documentation: 'take-last', + documentation: 'take last', label: 'take-last', insertText: 'tail ${1|-n,-c,--lines,--bytes|} ${2:count}', }, { - documentation: 'take-range', + documentation: 'take range', label: 'take-range', insertText: "sed ${1|-n,--quiet|} '${2:from},${3:to}p'", }, { - documentation: 'take-stepped-range', + documentation: 'take stepped range', label: 'take-stepped-range', insertText: "sed ${1|-n,--quiet|} '${2:from},${3:to}p' | sed $1 '1~${4:step}p'", }, { documentation: 'json print', - label: 'json', + label: 'json-print', insertText: "jq '.${1:node}' ${2:file}", }, { From 86c1ee4c38d0291548ae67e0f640e7fa92316eda Mon Sep 17 00:00:00 2001 From: EmilySeville7cfg Date: Wed, 2 Aug 2023 22:53:02 +1000 Subject: [PATCH 07/10] feat(snippets): comment snippet --- server/src/snippets.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/server/src/snippets.ts b/server/src/snippets.ts index 02ed35c71..b755027f1 100644 --- a/server/src/snippets.ts +++ b/server/src/snippets.ts @@ -639,6 +639,11 @@ export const SNIPPETS: BashCompletionItem[] = [ label: 'device', insertText: '/dev/${1|null,stdin,stdout,stderr|}', }, + { + documentation: 'comment', + label: 'comment definition', + insertText: '# ${1:description}', + }, ].map((item) => ({ ...item, documentation: { From 329754de29f70b68c37a73c26739632a04e12940 Mon Sep 17 00:00:00 2001 From: EmilySeville7cfg Date: Wed, 2 Aug 2023 23:14:50 +1000 Subject: [PATCH 08/10] feat(snippets): completion --- server/src/snippets.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/server/src/snippets.ts b/server/src/snippets.ts index b755027f1..b7af18b03 100644 --- a/server/src/snippets.ts +++ b/server/src/snippets.ts @@ -639,6 +639,18 @@ export const SNIPPETS: BashCompletionItem[] = [ label: 'device', insertText: '/dev/${1|null,stdin,stdout,stderr|}', }, + { + documentation: 'completion', + label: 'completion definition', + insertText: [ + '_$1_completions()', + '{', + '\treadarray -t COMPREPLY < <(compgen -W "-h --help -v --version" "${COMP_WORDS[1]}")', + '}', + '', + 'complete -F _$1_completions ${1:command}', + ].join('\n'), + }, { documentation: 'comment', label: 'comment definition', From f19249c86e6ca8b407106fce5ab594f5f5f4c4cd Mon Sep 17 00:00:00 2001 From: EmilySeville7cfg Date: Wed, 2 Aug 2023 23:15:19 +1000 Subject: [PATCH 09/10] fix(snippets): escape dollar sign --- server/src/snippets.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/src/snippets.ts b/server/src/snippets.ts index b7af18b03..d66ca274f 100644 --- a/server/src/snippets.ts +++ b/server/src/snippets.ts @@ -645,7 +645,7 @@ export const SNIPPETS: BashCompletionItem[] = [ insertText: [ '_$1_completions()', '{', - '\treadarray -t COMPREPLY < <(compgen -W "-h --help -v --version" "${COMP_WORDS[1]}")', + '\treadarray -t COMPREPLY < <(compgen -W "-h --help -v --version" "\${COMP_WORDS[1]}")', '}', '', 'complete -F _$1_completions ${1:command}', From 727c7ba6623d313ab40be807846680c9322437c5 Mon Sep 17 00:00:00 2001 From: EmilySeville7cfg Date: Wed, 2 Aug 2023 23:17:53 +1000 Subject: [PATCH 10/10] fix(snippets): broken escape --- server/src/snippets.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/src/snippets.ts b/server/src/snippets.ts index d66ca274f..2730fc1f7 100644 --- a/server/src/snippets.ts +++ b/server/src/snippets.ts @@ -645,7 +645,7 @@ export const SNIPPETS: BashCompletionItem[] = [ insertText: [ '_$1_completions()', '{', - '\treadarray -t COMPREPLY < <(compgen -W "-h --help -v --version" "\${COMP_WORDS[1]}")', + '\treadarray -t COMPREPLY < <(compgen -W "-h --help -v --version" "\\${COMP_WORDS[1]}")', '}', '', 'complete -F _$1_completions ${1:command}',