Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix arm snippets in JSON when not using CTRL+SPACE #1394

Merged
merged 2 commits into from
Oct 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

All notable changes to the "vscode-azurearmtools" extension will be documented in this file.

## Version 0.15.4 (2021-10-07)

### Fixed

- Using scaffolding snippets in empty JSON file should not require CTRL+SPACE [#1390](https://github.com/microsoft/vscode-azurearmtools/issues/1390)
## Version 0.15.3 (2021-09-27)

### Added
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "azurerm-vscode-tools",
"displayName": "Azure Resource Manager (ARM) Tools",
"description": "Language server, editing tools and snippets for Azure Resource Manager (ARM) template files.",
"version": "0.15.4-alpha",
"version": "0.15.4",
"publisher": "msazurermtools",
"config": {
"ARM_LANGUAGE_SERVER_NUGET_VERSION": "3.0.0-preview.21474.3"
Expand Down
21 changes: 14 additions & 7 deletions src/AzureRMTools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1402,7 +1402,7 @@ export class AzureRMTools implements IProvideOpenedDocuments {
return undefined;
}
} else {
const result = await this.getUnsupportedJsonSnippets(actionContext, document, position);
const result = await this.getJsonScaffoldingSnippets(actionContext, document, position);
jsonDocument = result.jsonDocument;
items = result.items;
}
Expand All @@ -1419,26 +1419,33 @@ export class AzureRMTools implements IProvideOpenedDocuments {
/**
* Retrieve snippets for a JSON file that is not a deployment or parameters file
*/
private async getUnsupportedJsonSnippets(
private async getJsonScaffoldingSnippets(
actionContext: IActionContext,
document: vscode.TextDocument,
position: vscode.Position
): Promise<{ jsonDocument?: IJsonDocument; items?: Item[] }> {
const text = document.getText();
if (text.length > 100 /*limit size of strings we trim*/ || text.trim() !== '') {
// We only want to show our scaffolding snippets (e.g. "arm!") when the document is empty or if they've started to type "arm" to bring up
// these snippets. If they already have other content in the JSON file, we don't want to show these snippets.

const fullText = document.getText();
let text = fullText;
if (text.length > 100) { // Limit size of strings we trim
return {};
}
text = text.trim();
if (!(text === "" || text === "a" || text === "ar" || text.startsWith("arm"))) {
return {};
}

// It's an empty (or whitespace) document, so we can try with the empty-document context
actionContext.telemetry.properties.isEmptyDoc = 'true';
const insertionContext: InsertionContext = {
context: KnownContexts.emptyDocument,
parents: []
};
const jsonDocument: IJsonDocument = new UnsupportedJsonDocument(document.getText(), document.uri);

const index = jsonDocument.getDocumentCharacterIndex(position.line, position.character);
const span = new Span(index, 0);
const index = fullText.length - fullText.trimLeft().length; // Start at beginning of non-whitespace
const span = new Span(index, fullText.length - index); // Should replace to end of buffer
const items: Item[] = await ext.snippetManager.value.getSnippetsAsCompletionItems(insertionContext, span);

return { jsonDocument, items };
Expand Down