Azure / Azure/bicep

Intellisense doesn't work when you're modifying an existing expression or resource (brownfield scenario)

Open
#4,082 1 comment 0 reactions 0 assignees View on GitHub
bug
Dominant language
Bicep
Stars
3.6k
Forks
830
Avg merge
1d 21m
Merged PRs (30d)
79

Description

I've hit this more than once while modifying bicep samples.

1) Start with this bicep:
```bicep
@description('Specifies location of all resources.')
param location string = resourceGroup().location

@description('Specifies SSH public key that is used to authenticate with linux VM')
param csadminSshKey string

@description('Specifies name of the administrator account for linux VM')
@secure()
param adminUserName string

@description('Specifies password for the administrator account for linux VM')
@secure()
param ccadminRawPassword string

@description('Specifies where network traffic originates from for ingress NSG rules.')
param myIp string

@description('Specifies size of cyclecloud VM')
param vmSize string = 'Standard_D1_v2'

var roleDefinitions = {
contributor: 'b24988ac-6180-42a0-ab88-20f7382dd24c'
}

var saName = take('cclocker${replace(guid(resourceGroup().id), '-', '')}', 24)

resource vnet 'Microsoft.Network/virtualNetworks@2020-05-01' = {
name: 'cc-vnet'
location: location
properties: {
addressSpace: {
addressPrefixes: [
'10.0.0.0/22'
]
}
subnets: [
{
name: 'Default'
properties: {
addressPrefix: '10.0.0.0/24'
networkSecurityGroup: {
id: 'nsg.id'
}
}
}
]
}
}

resource nic 'Microsoft.Network/networkInterfaces@2020-05-01' = {
name: 'cycleserver-nic'
location: location
properties: {
ipConfigurations: [
{
name: 'ipconfig'
properties: {
privateIPAllocationMethod: 'Dynamic'
subnet: {
id: '${vnet.id}/subnets/Default' // <<<<<<<<<<<<<<<< HERE
}
publicIPAddress: {
id: 'pip.id'
}
}
}
]
}
}
```
2) I want to change the line with "<<<<<<<<<<< HERE" into a resourceId call
3) Replace that line with this (partial) code:
```bicep
id: resourceId('Microsoft.Network/virtualNetworks/subnets/',
```
4) Place the cursor at the end and type "vnet."
!) EXPECTED: Intellisense for vnet properties (e.g. "name")
ACTUAL: top-level parameters/etc
![image](https://user-images.githubusercontent.com/6913354/130150216-7cf4e70d-aafc-4f18-a82a-0066709de079.png)

This happens because the closing ")" is not part of the line yet. This doesn't normally happen if you're using intellisense while building the line because the closing ")" will be filled in automatically. But it can be easy to get into this state when modifying existing or pasted code. For instance, I ended up here because I copied some sample JSON code and tried modifying it:

https://user-images.githubusercontent.com/6913354/130151295-578ac6aa-9e66-4b91-af8f-105e36e57eb0.mov

Intellisense shouldn't depend on the rest of the statement being syntaxtically correct.

Contributor guide

Open the contributing guide

Research direction

Reproduce the issue in the Bicep editor by leaving resourceId('Microsoft.Network/virtualNetworks/subnets/', incomplete and typing vnet. Compare completion results with the same expression after adding the closing parenthesis. Done means IntelliSense still offers vnet properties while the surrounding statement is syntactically incomplete.

Written by the indexing model from the issue text.

Assessment

Domain
developer-experience
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.