mirror of
https://github.com/Smaug123/nix-dotfiles
synced 2025-10-05 06:38:40 +00:00
Upgrade VS Code
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -1 +1,4 @@
|
||||
result/
|
||||
.idea/
|
||||
bin/
|
||||
obj/
|
||||
|
16
VsCodeExtensions.sln
Normal file
16
VsCodeExtensions.sln
Normal file
@@ -0,0 +1,16 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "VsCodeExtensions", "VsCodeExtensions\VsCodeExtensions.fsproj", "{5BD60C47-954A-42E3-9863-9B6ED29AC112}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{5BD60C47-954A-42E3-9863-9B6ED29AC112}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{5BD60C47-954A-42E3-9863-9B6ED29AC112}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{5BD60C47-954A-42E3-9863-9B6ED29AC112}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{5BD60C47-954A-42E3-9863-9B6ED29AC112}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
EndGlobal
|
176
VsCodeExtensions/Program.fs
Normal file
176
VsCodeExtensions/Program.fs
Normal file
@@ -0,0 +1,176 @@
|
||||
open System.IO
|
||||
open System.Net.Http
|
||||
open System.Text.Json
|
||||
|
||||
type Extension =
|
||||
{
|
||||
Name : string
|
||||
Publisher : string
|
||||
Version : string
|
||||
Sha256 : string
|
||||
}
|
||||
override this.ToString () =
|
||||
[
|
||||
"{"
|
||||
$" name = \"{this.Name}\";"
|
||||
$" publisher = \"{this.Publisher}\";"
|
||||
$" version = \"{this.Version}\";"
|
||||
$" sha256 = \"{this.Sha256}\";"
|
||||
"}"
|
||||
]
|
||||
|> String.concat "\n"
|
||||
|
||||
static member Parse (s : string list) : Extension =
|
||||
let collection =
|
||||
s
|
||||
|> List.fold (fun fields s ->
|
||||
match s.Split "=" |> List.ofArray with
|
||||
| field :: rest when not <| rest.IsEmpty ->
|
||||
Map.add (field.Trim ()) ((String.concat "=" rest).Split('"').[1].TrimEnd(';')) fields
|
||||
| _ -> fields
|
||||
) Map.empty
|
||||
|
||||
{
|
||||
Name = collection.["name"]
|
||||
Publisher = collection.["publisher"]
|
||||
Version = collection.["version"]
|
||||
Sha256 = collection.["sha256"]
|
||||
}
|
||||
|
||||
type Skipped =
|
||||
{
|
||||
NixpkgsRef : string
|
||||
Reason : string
|
||||
}
|
||||
override this.ToString () =
|
||||
[
|
||||
$"# {this.Reason}"
|
||||
$"# {this.NixpkgsRef}"
|
||||
]
|
||||
|> String.concat "\n"
|
||||
|
||||
let bimap f g (x, y) = (f x, g y)
|
||||
|
||||
let partition<'a, 'b> (l : List<Choice<'a, 'b>>) : 'a list * 'b list =
|
||||
l
|
||||
|> List.fold (fun (aEntries, bEntries) next ->
|
||||
match next with
|
||||
| Choice1Of2 a -> (a :: aEntries, bEntries)
|
||||
| Choice2Of2 b -> (aEntries, b :: bEntries)
|
||||
) ([], [])
|
||||
|> bimap List.rev List.rev
|
||||
|
||||
type NixFile =
|
||||
{
|
||||
NixpkgsRefs : string list
|
||||
Skipped : Skipped list
|
||||
SpecificVersions : Extension list
|
||||
}
|
||||
override this.ToString () =
|
||||
[
|
||||
yield "{ pkgs }:"
|
||||
yield ""
|
||||
yield "with pkgs.vscode-extensions; ["
|
||||
yield! this.NixpkgsRefs |> List.map (sprintf " %s")
|
||||
yield! this.Skipped |> List.map (sprintf "%O")
|
||||
yield "] ++ pkgs.vscode-utils.extensionsFromVscodeMarketplace ["
|
||||
yield! this.SpecificVersions |> List.map (sprintf "%O")
|
||||
yield "]"
|
||||
]
|
||||
|> String.concat "\n"
|
||||
|
||||
static member Parse (s : string) : NixFile =
|
||||
let pre, post =
|
||||
s.Split "\n] ++ pkgs.vscode-utils.extensionsFromVscodeMarketplace [\n"
|
||||
|> function
|
||||
| [| pre ; post |] -> pre, post
|
||||
| _ -> failwith "Unexpected number of '++'"
|
||||
|
||||
let verbatim, skipped =
|
||||
match pre.Split "\n" |> List.ofArray with
|
||||
| "{ pkgs }:" :: "" :: "with pkgs.vscode-extensions; [" :: rest ->
|
||||
rest
|
||||
|> List.map (fun s ->
|
||||
if s.StartsWith '#' then Choice2Of2 (s.[2..].Trim()) else Choice1Of2 (s.Trim())
|
||||
)
|
||||
|> partition
|
||||
| _ -> failwith $"Unexpected pre:\n{pre}"
|
||||
let pairs (l : 'a list) : ('a * 'a) list =
|
||||
let rec go acc l =
|
||||
match l with
|
||||
| [] -> acc
|
||||
| [singleton] -> failwith $"Expected pair, got {singleton}"
|
||||
| x :: y :: rest -> go ((x, y) :: acc) rest
|
||||
go [] l
|
||||
|> List.rev
|
||||
let skipped =
|
||||
skipped
|
||||
|> pairs
|
||||
|> List.map (fun (comment, link) -> { NixpkgsRef = link ; Reason = comment })
|
||||
|
||||
let specificVersions =
|
||||
post.TrimEnd([| '\n' ; ']'|]).Split "}"
|
||||
|> Array.choose (fun contents ->
|
||||
match contents.Trim([|'\n'|]).Split "\n" |> List.ofArray with
|
||||
| "{" :: rest ->
|
||||
Some (Extension.Parse rest)
|
||||
| [] ->
|
||||
failwith $"Expected extension, got:\n{contents}"
|
||||
| [""] -> None
|
||||
| fst :: rest ->
|
||||
failwith $"Expected bracket, got '{fst}'\n {rest}"
|
||||
)
|
||||
|> Array.toList
|
||||
|
||||
{
|
||||
Skipped = skipped
|
||||
NixpkgsRefs = verbatim
|
||||
SpecificVersions = specificVersions
|
||||
}
|
||||
|
||||
type Version =
|
||||
{
|
||||
Version : string
|
||||
TargetPlatform : string
|
||||
}
|
||||
|
||||
let upgradeExtension (client : HttpClient) (e : Extension) : Extension Async =
|
||||
let uri = System.Uri $"https://marketplace.visualstudio.com/items?itemName={e.Publisher}.{e.Name}"
|
||||
async {
|
||||
let! response = client.GetAsync uri |> Async.AwaitTask
|
||||
let! content = response.Content.ReadAsStringAsync () |> Async.AwaitTask
|
||||
let options = JsonSerializerOptions ()
|
||||
options.PropertyNameCaseInsensitive <- true
|
||||
let latestVersion =
|
||||
content.Split("\"Versions\":[").[1].Split("]").[0]
|
||||
|> sprintf "[%s]"
|
||||
|> fun s -> JsonSerializer.Deserialize<Version array> (s, options)
|
||||
|> Seq.head
|
||||
return { e with Version = latestVersion.Version }
|
||||
}
|
||||
|
||||
let upgrade (nixFile : NixFile) : NixFile =
|
||||
use client = new HttpClient ()
|
||||
{ nixFile with
|
||||
SpecificVersions =
|
||||
nixFile.SpecificVersions
|
||||
|> List.map (upgradeExtension client)
|
||||
|> Async.Parallel
|
||||
|> Async.RunSynchronously
|
||||
|> List.ofArray
|
||||
}
|
||||
|
||||
module Program =
|
||||
|
||||
[<EntryPoint>]
|
||||
let main args =
|
||||
let sourceFile =
|
||||
if args.Length = 0 then "vscode-extensions.nix" else args.[0]
|
||||
|
||||
File.ReadAllText sourceFile
|
||||
|> NixFile.Parse
|
||||
|> upgrade
|
||||
|> sprintf "%O"
|
||||
|> fun s -> File.WriteAllText (sourceFile, s)
|
||||
|
||||
0
|
12
VsCodeExtensions/VsCodeExtensions.fsproj
Normal file
12
VsCodeExtensions/VsCodeExtensions.fsproj
Normal file
@@ -0,0 +1,12 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Include="Program.fs"/>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
@@ -33,7 +33,7 @@ let python = import ./python.nix { inherit pkgs; }; in
|
||||
|
||||
nixpkgs.overlays = [
|
||||
(import (builtins.fetchTarball {
|
||||
url = https://github.com/nix-community/emacs-overlay/archive/25dd5297f613fd13971e4847e82d1097077eeb53.tar.gz;
|
||||
url = https://github.com/nix-community/emacs-overlay/archive/9516033899da467b8fcee6536a61ea66ebd0c4fa.tar.gz;
|
||||
}))
|
||||
];
|
||||
|
||||
|
@@ -7,15 +7,15 @@ with pkgs.vscode-extensions; [
|
||||
james-yu.latex-workshop
|
||||
vscodevim.vim
|
||||
# Doesn't work with vscodium, and unfree
|
||||
# ms-vscode-remote.remote-ssh
|
||||
# ms-vscode-remote.remote-ssh
|
||||
# Not supported on Darwin, apparently
|
||||
# ms-dotnettools.csharp
|
||||
# ms-dotnettools.csharp
|
||||
] ++ pkgs.vscode-utils.extensionsFromVscodeMarketplace [
|
||||
{
|
||||
name = "vscode-docker";
|
||||
publisher = "ms-azuretools";
|
||||
version = "1.14.0";
|
||||
sha256 = "0wc0k3hf9yfjcx7cw9vm528v5f4bk968bgc98h8fwmlx14vhapzp";
|
||||
version = "1.18.0";
|
||||
sha256 = "UPUfTOc5xJhI5ACm2oyWqtZ4zNxZjy16D6Mf30eHFEI=";
|
||||
}
|
||||
{
|
||||
name = "code-gnu-global";
|
||||
@@ -26,20 +26,20 @@ with pkgs.vscode-extensions; [
|
||||
{
|
||||
name = "rust-analyzer";
|
||||
publisher = "matklad";
|
||||
version = "0.2.792";
|
||||
sha256 = "1m4g6nf5yhfjrjja0x8pfp79v04lxp5lfm6z91y0iilmqbb9kx1q";
|
||||
version = "0.2.867";
|
||||
sha256 = "HYq8PuzchMwx0wd3SInitGzhNQe2biw2Njl+xdNuWjk=";
|
||||
}
|
||||
{
|
||||
name = "vscode-lldb";
|
||||
publisher = "vadimcn";
|
||||
version = "1.6.8";
|
||||
sha256 = "1c81hs2lbcxshw3fnpajc9hzkpykc76a6hgs7wl5xji57782bckl";
|
||||
version = "1.6.10";
|
||||
sha256 = "CGVVs//jIZM8uX7Wc9gM4aQGwECi88eIpfPqU2hKbeA=";
|
||||
}
|
||||
{
|
||||
name = "toml";
|
||||
publisher = "be5invis";
|
||||
version = "0.5.1";
|
||||
sha256 = "1r1y6krqw5rrdhia9xbs3bx9gibd1ky4bm709231m9zvbqqwwq2j";
|
||||
version = "0.6.0";
|
||||
sha256 = "yk7buEyQIw6aiUizAm+sgalWxUibIuP9crhyBaOjC2E=";
|
||||
}
|
||||
{
|
||||
name = "Ionide-Paket";
|
||||
@@ -50,8 +50,8 @@ with pkgs.vscode-extensions; [
|
||||
{
|
||||
name = "lean";
|
||||
publisher = "jroesch";
|
||||
version = "0.16.39";
|
||||
sha256 = "0v1w0rmx2z7q6lfrl430fl6aq6n70y14s2fqsp734igdkdhdnvmk";
|
||||
version = "0.16.41";
|
||||
sha256 = "9fbeSIBSLcCQFekeGuGaYnut3eFm2oQVqJA4Y0Yfy5o=";
|
||||
}
|
||||
{
|
||||
name = "language-haskell";
|
||||
@@ -68,20 +68,20 @@ with pkgs.vscode-extensions; [
|
||||
{
|
||||
name = "dotnet-interactive-vscode";
|
||||
publisher = "ms-dotnettools";
|
||||
version = "1.0.2309031";
|
||||
sha256 = "0vqlspq3696yyfsv17rpcbsaqs7nm7yvggv700sl1bia817cak10";
|
||||
version = "1.0.2606011";
|
||||
sha256 = "a3u9NKsqHZKhZkKqJqo+LgJFTL2yhehBepTOFOXE+jY=";
|
||||
}
|
||||
{
|
||||
name = "python";
|
||||
publisher = "ms-python";
|
||||
version = "2021.5.926500501";
|
||||
sha256 = "0hpb1z10ykg1sz0840qnas5ddbys9inqnjf749lvakj9spk1syk3";
|
||||
version = "2021.12.1559732655";
|
||||
sha256 = "hXTVZ7gbu234zyAg0ZrZPUo6oULB98apxe79U2yQHD4=";
|
||||
}
|
||||
{
|
||||
name = "remote-containers";
|
||||
publisher = "ms-vscode-remote";
|
||||
version = "0.183.0";
|
||||
sha256 = "12v7037rn46svv6ff2g824hdkk7l95g4gbzrp5zdddwxs0a62jlg";
|
||||
version = "0.209.6";
|
||||
sha256 = "SOYTUBY8EGLTYhNkQC56apAwgV0feCe9ydU8UOtRdbc=";
|
||||
}
|
||||
{
|
||||
name = "mono-debug";
|
||||
@@ -107,4 +107,4 @@ with pkgs.vscode-extensions; [
|
||||
version = "0.25.1";
|
||||
sha256 = "1l01sv6kwh8dlv3kygkkd0z9m37hahflzd5bx1wwij5p61jg7np9";
|
||||
}
|
||||
]
|
||||
]
|
Reference in New Issue
Block a user