forcedotcom / salesforcedx-vscode

Salesforce Extensions for VS Code
https://developer.salesforce.com/tools/vscode
BSD 3-Clause "New" or "Revised" License
947 stars 404 forks source link

Prettier suddenly Does not format Visualforce .page files #3383

Closed aalv-vt closed 3 years ago

aalv-vt commented 3 years ago

Summary

Does not format Visualforce .page files.

Steps To Reproduce:

  1. Create a Salesforce DX project in VS Code with the Salesforce Extension Pack installed.
  2. Follow the Prettier Code Formatter instructions.
  3. In Settings, set Editor: Default Formatter to Prettier.
  4. In Settings, check Editor:Format on Save.
  5. Create a Visualfoce page with the following code

    
    <apex:page controller="myAccountController"  lightningStylesheets="true">
    <apex:form>
        <apex:pageBlock title="Edit Account">
            <apex:pageBlockSection columns="1">
                <apex:inputField value="{! Account.Name }" ignoreEditPermissionForRendering="true"/>
    
    <apex:inputField value="{! Account.Phone }" ignoreEditPermissionForRendering="true"/>
    <apex:inputField value="{! Account.Industry }" ignoreEditPermissionForRendering="true"/>
    <apex:inputField value="{! Account.AnnualRevenue }" ignoreEditPermissionForRendering="true"/>
            </apex:pageBlockSection>
            <apex:pageBlockButtons>
                <apex:commandButton action="{! save }" value="Save" />
            </apex:pageBlockButtons>
        </apex:pageBlock>
        </apex:form>

</apex:page>


1. Save the Visualforce .page file

### Expected result

Prettier formats the document.

### Actual result

Error shows at bottom of window, with message that Prettier cannot format the file. 

### Additional information

![prettier visualforce](https://user-images.githubusercontent.com/59533717/124197054-b36d4180-da9b-11eb-97d8-d8c42b49a07c.png)

**VS Code Version**:
Version: 1.57.1 (user setup)

**SFDX CLI Version**:
sfdx-cli/7.107.0 win32-x64 node-v14.17.1

**OS and version**:
OS: Windows_NT x64 10.0.19041
smaddox-sf commented 3 years ago

Hi @aalv-vt - Thanks for reaching out. I have a couple questions: 1) What version of the Salesforce extension pack are you using? 2) Do you have the Visualforce > Format: Enable setting enabled in VS Code?

jonny-harte commented 3 years ago

@smaddox-sf I'm having a similar issue. To confirm I have Visualforce > Format Enabled. If I Disabled it the Message Extension 'Prettier - Code formatter' cannot format ... doesn't appear.

aalv-vt commented 3 years ago

@smaddox-sf,

Hi @aalv-vt - Thanks for reaching out. I have a couple questions:

  1. What version of the Salesforce extension pack are you using? v52.3.0
  2. Do you have the Visualforce > Format: Enable setting enabled in VS Code? Yes.
xyc commented 3 years ago

If you are using Prettier as the code formatter for visualforce, you should also add the following glob pattern to your .vscode/settings.json file.

"prettier.documentSelectors": ["*/.page"]

Otherwise, if you are using the formatter from visualforce language server, add the following setting to override the default formatter setting.

"[visualforce]": {
    "editor.defaultFormatter": "salesforce.salesforcedx-vscode-visualforce"
}
jonny-harte commented 3 years ago

Thanks @xyc the glob pattern didnt work but the below did.

"prettier.documentSelectors": ["**/*.{cmp,page,component}"],