From a284779fccf68fe235282d1bb366a2f716449153 Mon Sep 17 00:00:00 2001 From: James Pogran Date: Tue, 27 Aug 2024 14:54:46 -0400 Subject: [PATCH] Remove snippets file in favor of terraform-ls This commit removes the static snippets file in favor of using the Terraform Language Server to provide snippets completions. The file was a legacy feature from when there was no language server to provide more specific snippets. These snippets used the existing VS Code api to provide a minimal completion experience, but there was no facility to control when or where these snippets appeared. This frequently caused confusion for users as the snippets in the file were not always relevant to the current context and could not be disabled. The Terraform Language Server provides a more powerful and context-aware completion experience that can suggest completions for all Terraform language constructs. This is combined with the `editor.suggest.preview` and `terraform.experimentalFeatures.prefillRequiredFields` settings to provide a more accurate and helpful completion experience. --- .../ENHANCEMENTS-20240827-150104.yaml | 6 ++ README.md | 11 +--- package.json | 6 -- snippets/terraform.json | 61 ------------------- .../integration/basics/completion.test.ts | 18 +----- 5 files changed, 11 insertions(+), 91 deletions(-) create mode 100644 .changes/unreleased/ENHANCEMENTS-20240827-150104.yaml delete mode 100644 snippets/terraform.json diff --git a/.changes/unreleased/ENHANCEMENTS-20240827-150104.yaml b/.changes/unreleased/ENHANCEMENTS-20240827-150104.yaml new file mode 100644 index 0000000000..ff78651558 --- /dev/null +++ b/.changes/unreleased/ENHANCEMENTS-20240827-150104.yaml @@ -0,0 +1,6 @@ +kind: ENHANCEMENTS +body: Remove static snippets +time: 2024-08-27T15:01:04.207532-04:00 +custom: + Issue: "1830" + Repository: vscode-terraform diff --git a/README.md b/README.md index 0f0442972e..065d18c4cd 100644 --- a/README.md +++ b/README.md @@ -106,14 +106,9 @@ See the [Formatting](#formatting) Configuration section for information on how t ### Code Snippets -The extension provides several snippets to accelerate adding Terraform code to your configuration files: - -- `fore` - For Each -- `module` - Module -- `output` - Output -- `provisioner` - Provisioner -- `vare` - Empty variable -- `varm` - Map Variable +The extension provides context aware snippets to accelerate adding Terraform code to your configuration files. + +Combined with `editor.suggest.preview` and `terraform.experimentalFeatures.prefillRequiredFields`, the extension can suggest completions for all Terraform language constructs. ### HCP Terraform Integration diff --git a/package.json b/package.json index 2f07eb57ed..934864950a 100644 --- a/package.json +++ b/package.json @@ -315,12 +315,6 @@ } } }, - "snippets": [ - { - "language": "terraform", - "path": "./snippets/terraform.json" - } - ], "configuration": [ { "title": "General", diff --git a/snippets/terraform.json b/snippets/terraform.json deleted file mode 100644 index 5bad321736..0000000000 --- a/snippets/terraform.json +++ /dev/null @@ -1,61 +0,0 @@ -{ - "For Each": { - "prefix": "fore", - "body": [ - "for_each = {", - "\t${1:key} = \"${2:value}\"", - "}" - ], - "description": "The for_each meta-argument accepts a map or a set of strings, and creates an instance for each item in that map or set." - }, - "Module": { - "prefix": "module", - "body": [ - "module \"${1:name}\" {", - "\tsource = \"$2\"", - "\t$3", - "}" - ] - }, - "Output": { - "prefix": "output", - "body": [ - "output \"${1:name}\" {", - "\tvalue = \"$2\"", - "}" - ] - }, - "Provisioner": { - "prefix": "provisioner", - "body": [ - "provisioner \"${1:name}\" {", - "${2}", - "}" - ], - "description": "Provisioners can be used to model specific actions on the local machine or on a remote machine in order to prepare servers or other infrastructure objects for service." - }, - "Empty variable": { - "prefix": "vare", - "body": [ - "variable \"${1:name}\" {", - "\ttype = ${2|string,number,bool|}", - "\t${3:description = \"${4:(optional) describe your variable}\"}", - "}" - ], - "description": "Variable (empty)" - }, - "Map variable": { - "prefix": "varm", - "body": [ - "variable \"${1:name}\" {", - "\ttype = map(${2|string,number,bool|})", - "\t${3:description = \"${4:(optional) describe your variable}\"}", - "\tdefault = {", - "\t\t${5:key1} = \"${6:val1}\"", - "\t\t${7:key2} = \"${8:val2}\"", - "\t}", - "}" - ], - "description": "Variable (map)" - } -} \ No newline at end of file diff --git a/src/test/integration/basics/completion.test.ts b/src/test/integration/basics/completion.test.ts index 6653a92cb6..f0c2f253a7 100644 --- a/src/test/integration/basics/completion.test.ts +++ b/src/test/integration/basics/completion.test.ts @@ -7,15 +7,6 @@ import * as vscode from 'vscode'; import { assert } from 'chai'; import { activateExtension, getDocUri, open, testCompletion } from '../../helper'; -const snippets = [ - new vscode.CompletionItem({ label: 'fore', description: 'For Each' }, vscode.CompletionItemKind.Snippet), - new vscode.CompletionItem({ label: 'module', description: 'Module' }, vscode.CompletionItemKind.Snippet), - new vscode.CompletionItem({ label: 'output', description: 'Output' }, vscode.CompletionItemKind.Snippet), - new vscode.CompletionItem({ label: 'provisioner', description: 'Provisioner' }, vscode.CompletionItemKind.Snippet), - new vscode.CompletionItem({ label: 'vare', description: 'Empty variable' }, vscode.CompletionItemKind.Snippet), - new vscode.CompletionItem({ label: 'varm', description: 'Map variable' }, vscode.CompletionItemKind.Snippet), -]; - suite('completion', () => { suite('root document completion', function suite() { const docUri = getDocUri('empty.tf'); @@ -49,7 +40,7 @@ suite('completion', () => { new vscode.CompletionItem('terraform', vscode.CompletionItemKind.Class), new vscode.CompletionItem('variable', vscode.CompletionItemKind.Class), ]; - expected.push(...snippets); + await testCompletion(docUri, new vscode.Position(0, 0), { items: expected, }); @@ -83,7 +74,6 @@ suite('completion', () => { new vscode.CompletionItem('providers', vscode.CompletionItemKind.Property), new vscode.CompletionItem('version', vscode.CompletionItemKind.Property), ]; - expected.push(...snippets); await testCompletion(docUri, new vscode.Position(21, 0), { items: expected, @@ -97,10 +87,6 @@ suite('completion', () => { new vscode.CompletionItem('"./compute"', vscode.CompletionItemKind.Text), ]; - if (vscode.version <= '1.82.3') { - expected.push(...snippets); - } - // module "compute" { // source = "./compute" // ^ @@ -166,7 +152,7 @@ suite('completion', () => { new vscode.CompletionItem('project', vscode.CompletionItemKind.Property), new vscode.CompletionItem('region', vscode.CompletionItemKind.Property), ]; - expected.push(...snippets); + await testCompletion(docUri, new vscode.Position(1, 0), { items: expected, });