microsoft / winget-dsc

MIT License
23 stars 14 forks source link

DSC resource to configure Visual Studio Code workspace settings #69

Open Gijsreyn opened 1 month ago

Gijsreyn commented 1 month ago

Description of the new feature / enhancement

I'd like a DSC resource so I can configure Visual Studio Code workspace settings.

Proposed technical implementation details

No response

Gijsreyn commented 1 month ago

Hi @denelon,

I have been experimenting with Visual Studio Code workspace settings and have opened a PR that covers approximately 80-85% of the settings. I tried adding enums to make things more configurable.

Although VSCode offers many ways to configure and sync settings, exporting through DSC v3 can potentially help users discover available settings and configure them consistently.

Lastly, this was also to kickstart the idea to see if it is feasible for this repository. If it is not, I understand. Could you please let me know if that’s the case? Thanks in advance.

P.S.: For the record, I'm lazy in writing. I'm grabbing all available settings from the settings.md. I have created two functions that parse the output and return the whole class with enum as script content. It goes something like:

$settings = Get-VSCodeSettings

$groups = $settings | Sort-Object -Property Setting -Unique | Group-Object -Property Category
$filter = $groups | Where-Object { $_.Name -notin @('_os', '_vscode') -and $_.Name -notlike '`[*' -and $_.Name -notlike '`**' }
foreach ($group in $filter)
{
    $class = New-VSCodeSettingClass -settings $group.Group
    $filePath = "C:\Source\winget-dsc\output\$($group.Name)Setting.ps1"
    try {
        $class | Out-File -FilePath "C:\Source\winget-dsc\output\$($group.Name)Setting.ps1" -ErrorAction Stop
    } catch {
        Write-Host "Error writing $($group.Name)Setting.ps1"
        Write-Host $_.Exception.Message

        continue;
    }
    try {
        . $filePath

        $content = Get-Content $filePath -Raw
        $content | Add-Content -Path C:\Source\winget-dsc\resources\Microsoft.VSCode.Dsc\test.psm1
    } catch {
        Write-Host "Error loading $($group.Name)Setting.ps1"
        Write-Host $_.Exception.Message

        continue;
    }
}

If you want, I can always share the script.