From 5d4dd91969daf7d422c9a66325f1c8a4bdc6ae3b Mon Sep 17 00:00:00 2001 From: Mingzhe Huang Date: Tue, 15 Oct 2024 10:58:24 +0800 Subject: [PATCH 1/8] feat(vscode): add basic snippets for typespec - add snippets for typespec basic constructs - package snippets within vs code extension part of #4559 --- packages/typespec-vscode/.vscodeignore | 1 + packages/typespec-vscode/package.json | 9 +++++- packages/typespec-vscode/snippets.json | 40 ++++++++++++++++++++++++++ 3 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 packages/typespec-vscode/snippets.json diff --git a/packages/typespec-vscode/.vscodeignore b/packages/typespec-vscode/.vscodeignore index 17dfc6fbc7..f668ef356f 100644 --- a/packages/typespec-vscode/.vscodeignore +++ b/packages/typespec-vscode/.vscodeignore @@ -17,3 +17,4 @@ dist/test/ !ThirdPartyNotices.txt !LICENSE !icons/ +!snippets.json diff --git a/packages/typespec-vscode/package.json b/packages/typespec-vscode/package.json index d4529aac86..e1e4c05d78 100644 --- a/packages/typespec-vscode/package.json +++ b/packages/typespec-vscode/package.json @@ -20,7 +20,8 @@ "publisher": "typespec", "displayName": "TypeSpec for VS Code", "categories": [ - "Programming Languages" + "Programming Languages", + "Snippets" ], "type": "module", "main": "./dist/src/extension.cjs", @@ -141,6 +142,12 @@ } } } + ], + "snippets": [ + { + "language": "typespec", + "path": "./snippets.json" + } ] }, "scripts": { diff --git a/packages/typespec-vscode/snippets.json b/packages/typespec-vscode/snippets.json new file mode 100644 index 0000000000..37c4287cf4 --- /dev/null +++ b/packages/typespec-vscode/snippets.json @@ -0,0 +1,40 @@ +{ + "Alias": { + "prefix": "alias", + "body": "alias ${1:AliasName} = ${0:Expression};", + "description": "Alias definition" + }, + "Enum": { + "prefix": "enum", + "body": "enum ${1:EnumName} {\n ${0:Value},\n}", + "description": "Enum definition" + }, + "Interface": { + "prefix": "interface", + "body": "interface ${1:InterfaceName} {\n ${2:member}(${3:parameters}): ${0:ReturnType};\n}", + "description": "Interface definition" + }, + "Model": { + "prefix": "model", + "body": "model ${1:ModelName} {\n ${2:propertyName}: ${0:propertyType};\n}", + "description": "Model definition" + }, + "Namespece": { + "prefix": "namespace", + "body": "namespace ${1:NamespaceName} {\n ${0:member}\n}", + "description": "Namespace definition" + }, + "Operation": { + "prefix": [ + "op", + "operation" + ], + "body": "operation ${1:OperationName}(${2:parameters}): ${0:ReturnType};", + "description": "Operation definition" + }, + "Union": { + "prefix": "union", + "body": "union ${1:UnionName} = ${2:Variant1} | ${0:Variant2};", + "description": "Named union definition" + } +} From 00ea6aa1ae8e06a709704c7e302d41db0552c18e Mon Sep 17 00:00:00 2001 From: Mingzhe Huang Date: Tue, 15 Oct 2024 11:02:40 +0800 Subject: [PATCH 2/8] add chronus change description --- ...s-code-extension-typespec-snippets-2024-9-15-11-2-20.md | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 .chronus/changes/vs-code-extension-typespec-snippets-2024-9-15-11-2-20.md diff --git a/.chronus/changes/vs-code-extension-typespec-snippets-2024-9-15-11-2-20.md b/.chronus/changes/vs-code-extension-typespec-snippets-2024-9-15-11-2-20.md new file mode 100644 index 0000000000..c0d2f518e6 --- /dev/null +++ b/.chronus/changes/vs-code-extension-typespec-snippets-2024-9-15-11-2-20.md @@ -0,0 +1,7 @@ +--- +changeKind: feature +packages: + - typespec-vscode +--- + +feat(vscode): add basic snippets for typespec \ No newline at end of file From 7ba92056778b25e96f463cfba80f0f6100220fb1 Mon Sep 17 00:00:00 2001 From: Mingzhe Huang Date: Tue, 15 Oct 2024 11:05:22 +0800 Subject: [PATCH 3/8] fix format issue --- packages/typespec-vscode/snippets.json | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/packages/typespec-vscode/snippets.json b/packages/typespec-vscode/snippets.json index 37c4287cf4..5e8bc3a9bf 100644 --- a/packages/typespec-vscode/snippets.json +++ b/packages/typespec-vscode/snippets.json @@ -19,16 +19,13 @@ "body": "model ${1:ModelName} {\n ${2:propertyName}: ${0:propertyType};\n}", "description": "Model definition" }, - "Namespece": { + "Namespace": { "prefix": "namespace", "body": "namespace ${1:NamespaceName} {\n ${0:member}\n}", "description": "Namespace definition" }, "Operation": { - "prefix": [ - "op", - "operation" - ], + "prefix": ["op", "operation"], "body": "operation ${1:OperationName}(${2:parameters}): ${0:ReturnType};", "description": "Operation definition" }, From 77bbfd10f95ce052266cba5ca04371e0bf0b2b26 Mon Sep 17 00:00:00 2001 From: Mingzhe Huang Date: Wed, 16 Oct 2024 11:58:11 +0800 Subject: [PATCH 4/8] update changeset --- .../vs-code-extension-typespec-snippets-2024-9-15-11-2-20.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.chronus/changes/vs-code-extension-typespec-snippets-2024-9-15-11-2-20.md b/.chronus/changes/vs-code-extension-typespec-snippets-2024-9-15-11-2-20.md index c0d2f518e6..adafae6e0a 100644 --- a/.chronus/changes/vs-code-extension-typespec-snippets-2024-9-15-11-2-20.md +++ b/.chronus/changes/vs-code-extension-typespec-snippets-2024-9-15-11-2-20.md @@ -4,4 +4,4 @@ packages: - typespec-vscode --- -feat(vscode): add basic snippets for typespec \ No newline at end of file +Add basic snippets for typespec From 95873a906048951432f15f09c65afa411671db6e Mon Sep 17 00:00:00 2001 From: Mingzhe Huang Date: Mon, 21 Oct 2024 14:45:56 +0800 Subject: [PATCH 5/8] change accorinding to review comments - simplify some placeholder names - use lower case for first letter of placeholder names - replace some placeholders with `$TM_SELECTED_TEXT$0` to just move the cursor - add `${3:type}` for operation --- packages/typespec-vscode/snippets.json | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/packages/typespec-vscode/snippets.json b/packages/typespec-vscode/snippets.json index 5e8bc3a9bf..3b46c1e322 100644 --- a/packages/typespec-vscode/snippets.json +++ b/packages/typespec-vscode/snippets.json @@ -1,37 +1,37 @@ { "Alias": { "prefix": "alias", - "body": "alias ${1:AliasName} = ${0:Expression};", + "body": "alias ${1:name} = $TM_SELECTED_TEXT$0;", "description": "Alias definition" }, "Enum": { "prefix": "enum", - "body": "enum ${1:EnumName} {\n ${0:Value},\n}", + "body": "enum ${1:name} {\n ${0:value},\n}", "description": "Enum definition" }, "Interface": { "prefix": "interface", - "body": "interface ${1:InterfaceName} {\n ${2:member}(${3:parameters}): ${0:ReturnType};\n}", + "body": "interface ${1:name} {\n ${2:member}(${3:parameters}:${4:type}): ${0:returnType};\n}", "description": "Interface definition" }, "Model": { "prefix": "model", - "body": "model ${1:ModelName} {\n ${2:propertyName}: ${0:propertyType};\n}", + "body": "model ${1:name} {\n ${2:propertyName}: ${0:propertyType};\n}", "description": "Model definition" }, "Namespace": { "prefix": "namespace", - "body": "namespace ${1:NamespaceName} {\n ${0:member}\n}", + "body": "namespace ${1:name} {\n $TM_SELECTED_TEXT$0\n}", "description": "Namespace definition" }, "Operation": { "prefix": ["op", "operation"], - "body": "operation ${1:OperationName}(${2:parameters}): ${0:ReturnType};", + "body": "operation ${1:name}(${2:parameters}:${3:type}): ${0:returnType};", "description": "Operation definition" }, "Union": { "prefix": "union", - "body": "union ${1:UnionName} = ${2:Variant1} | ${0:Variant2};", + "body": "union ${1:name} = ${2:variant1} | ${0:variant2};", "description": "Named union definition" } } From 7a81cc092c1eee9e64d5dac6611945a3c3083597 Mon Sep 17 00:00:00 2001 From: Mingzhe Huang Date: Mon, 21 Oct 2024 14:46:24 +0800 Subject: [PATCH 6/8] delete `Alias` snippet which is too simple --- packages/typespec-vscode/snippets.json | 5 ----- 1 file changed, 5 deletions(-) diff --git a/packages/typespec-vscode/snippets.json b/packages/typespec-vscode/snippets.json index 3b46c1e322..b48e25b548 100644 --- a/packages/typespec-vscode/snippets.json +++ b/packages/typespec-vscode/snippets.json @@ -1,9 +1,4 @@ { - "Alias": { - "prefix": "alias", - "body": "alias ${1:name} = $TM_SELECTED_TEXT$0;", - "description": "Alias definition" - }, "Enum": { "prefix": "enum", "body": "enum ${1:name} {\n ${0:value},\n}", From 02a7d7e331ed6152f342c95ec36425d193fe356c Mon Sep 17 00:00:00 2001 From: Mingzhe Huang Date: Mon, 21 Oct 2024 15:00:08 +0800 Subject: [PATCH 7/8] fix wrong operation key word --- packages/typespec-vscode/snippets.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/typespec-vscode/snippets.json b/packages/typespec-vscode/snippets.json index b48e25b548..255e30e82d 100644 --- a/packages/typespec-vscode/snippets.json +++ b/packages/typespec-vscode/snippets.json @@ -21,7 +21,7 @@ }, "Operation": { "prefix": ["op", "operation"], - "body": "operation ${1:name}(${2:parameters}:${3:type}): ${0:returnType};", + "body": "op ${1:name}(${2:parameters}:${3:type}): ${0:returnType};", "description": "Operation definition" }, "Union": { From b3d61b836bc3ffc34dc87fca7a6ed80be433ae93 Mon Sep 17 00:00:00 2001 From: Mingzhe Huang Date: Tue, 22 Oct 2024 16:12:16 +0800 Subject: [PATCH 8/8] change name placeholder to first letter upper case --- packages/typespec-vscode/snippets.json | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/typespec-vscode/snippets.json b/packages/typespec-vscode/snippets.json index 255e30e82d..bf161bdb06 100644 --- a/packages/typespec-vscode/snippets.json +++ b/packages/typespec-vscode/snippets.json @@ -1,22 +1,22 @@ { "Enum": { "prefix": "enum", - "body": "enum ${1:name} {\n ${0:value},\n}", + "body": "enum ${1:Name} {\n ${0:value},\n}", "description": "Enum definition" }, "Interface": { "prefix": "interface", - "body": "interface ${1:name} {\n ${2:member}(${3:parameters}:${4:type}): ${0:returnType};\n}", + "body": "interface ${1:Name} {\n ${2:member}(${3:parameters}:${4:type}): ${0:returnType};\n}", "description": "Interface definition" }, "Model": { "prefix": "model", - "body": "model ${1:name} {\n ${2:propertyName}: ${0:propertyType};\n}", + "body": "model ${1:Name} {\n ${2:propertyName}: ${0:propertyType};\n}", "description": "Model definition" }, "Namespace": { "prefix": "namespace", - "body": "namespace ${1:name} {\n $TM_SELECTED_TEXT$0\n}", + "body": "namespace ${1:Name} {\n $TM_SELECTED_TEXT$0\n}", "description": "Namespace definition" }, "Operation": { @@ -26,7 +26,7 @@ }, "Union": { "prefix": "union", - "body": "union ${1:name} = ${2:variant1} | ${0:variant2};", + "body": "union ${1:Name} = ${2:variant1} | ${0:variant2};", "description": "Named union definition" } }