<commit_before>{ lib, stdenv
, fetchFromGitHub
, fetchurl
, dotnetCorePackages
, makeWrapper
, unzip
, writeText
}:

let

  dotnet-sdk = dotnetCorePackages.sdk_6_0;

  deps = map (package: stdenv.mkDerivation (with package; {
    inherit pname version src;

    buildInputs = [ unzip ];
    unpackPhase = ''
      unzip $src
      chmod -R u+r .
      function traverseRename () {
        for e in *
        do
          t="$(echo "$e" | sed -e "s/%20/\ /g" -e "s/%2B/+/g")"
          [ "$t" != "$e" ] && mv -vn "$e" "$t"
          if [ -d "$t" ]
          then
            cd "$t"
            traverseRename
            cd ..
          fi
        done
      }

      traverseRename
    '';

    installPhase = ''
      runHook preInstall

      package=$out/lib/dotnet/${pname}/${version}
      mkdir -p $package
      cp -r . $package
      echo "{}" > $package/.nupkg.metadata

      runHook postInstall
    '';

    dontFixup = true;
  }))
    (import ./deps.nix { inherit fetchurl; });

  nuget-config = writeText "NuGet.Config" ''
    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
      <packageSources>
        <clear />
      </packageSources>
      <fallbackPackageFolders>
        ${lib.concatStringsSep "\n" (map (package: "<add key=\"${package}\" value=\"${package}/lib/dotnet\"/>") deps)}
      </fallbackPackageFolders>
    </configuration>
  '';

in stdenv.mkDerivation rec {
  pname = "omnisharp-roslyn";
  version = "1.38.2";

  src = fetchFromGitHub {
    owner = "OmniSharp";
    repo = pname;
    rev = "v${version}";
    sha256 = "7XJIdotfffu8xo+S6xlc1zcK3oY9QIg1CJhCNJh5co0=";
  };

  nativeBuildInputs = [ makeWrapper dotnet-sdk ];

  postPatch = ''
    # Relax the version requirement
    substituteInPlace global.json \
      --replace '6.0.100' '${dotnet-sdk.version}'
  '';

  buildPhase = ''
    runHook preBuild

    HOME=$(pwd)/fake-home dotnet msbuild -r \
      -p:Configuration=Release \
      -p:RestoreConfigFile=${nuget-config} \
      src/OmniSharp.Stdio.Driver/OmniSharp.Stdio.Driver.csproj

    runHook postBuild
  '';

  installPhase = ''
    mkdir -p $out/bin
    cp -r bin/Release/OmniSharp.Stdio.Driver/net6.0 $out/src
    makeWrapper $out/src/OmniSharp $out/bin/omnisharp \
      --prefix DOTNET_ROOT : ${dotnet-sdk} \
      --suffix PATH : ${dotnet-sdk}/bin
  '';

  meta = with lib; {
    description = "OmniSharp based on roslyn workspaces";
    homepage = "https://github.com/OmniSharp/omnisharp-roslyn";
    platforms = platforms.unix;
    license = licenses.mit;
    maintainers = with maintainers; [ tesq0 ericdallo corngood ];
    mainProgram = "omnisharp";
  };

}<commit_msg>omnisharp-roslyn: fix errors related to dlls Mimick the hack in the upstream omnisharp repository, which fixes omnisharp giving errors about being unable to find specific libraries<commit_after>{ lib, stdenv
, fetchFromGitHub
, fetchurl
, dotnetCorePackages
, makeWrapper
, unzip
, writeText
}:

let

  dotnet-sdk = dotnetCorePackages.sdk_6_0;

  deps = map (package: stdenv.mkDerivation (with package; {
    inherit pname version src;

    buildInputs = [ unzip ];
    unpackPhase = ''
      unzip $src
      chmod -R u+r .
      function traverseRename () {
        for e in *
        do
          t="$(echo "$e" | sed -e "s/%20/\ /g" -e "s/%2B/+/g")"
          [ "$t" != "$e" ] && mv -vn "$e" "$t"
          if [ -d "$t" ]
          then
            cd "$t"
            traverseRename
            cd ..
          fi
        done
      }

      traverseRename
    '';

    installPhase = ''
      runHook preInstall

      package=$out/lib/dotnet/${pname}/${version}
      mkdir -p $package
      cp -r . $package
      echo "{}" > $package/.nupkg.metadata

      runHook postInstall
    '';

    dontFixup = true;
  }))
    (import ./deps.nix { inherit fetchurl; });

  nuget-config = writeText "NuGet.Config" ''
    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
      <packageSources>
        <clear />
      </packageSources>
      <fallbackPackageFolders>
        ${lib.concatStringsSep "\n" (map (package: "<add key=\"${package}\" value=\"${package}/lib/dotnet\"/>") deps)}
      </fallbackPackageFolders>
    </configuration>
  '';

in stdenv.mkDerivation rec {
  pname = "omnisharp-roslyn";
  version = "1.38.2";

  src = fetchFromGitHub {
    owner = "OmniSharp";
    repo = pname;
    rev = "v${version}";
    sha256 = "7XJIdotfffu8xo+S6xlc1zcK3oY9QIg1CJhCNJh5co0=";
  };

  nativeBuildInputs = [ makeWrapper dotnet-sdk ];

  postPatch = ''
    # Relax the version requirement
    substituteInPlace global.json \
      --replace '6.0.100' '${dotnet-sdk.version}'
  '';

  buildPhase = ''
    runHook preBuild

    HOME=$(pwd)/fake-home dotnet msbuild -r \
      -p:Configuration=Release \
      -p:RestoreConfigFile=${nuget-config} \
      src/OmniSharp.Stdio.Driver/OmniSharp.Stdio.Driver.csproj

    runHook postBuild
  '';

  installPhase = ''
    mkdir -p $out/bin
    cp -r bin/Release/OmniSharp.Stdio.Driver/net6.0 $out/src

    # Delete files to mimick hacks in https://github.com/OmniSharp/omnisharp-roslyn/blob/bdc14ca/build.cake#L594
    rm $out/src/NuGet.*.dll
    rm $out/src/System.Configuration.ConfigurationManager.dll

    makeWrapper $out/src/OmniSharp $out/bin/omnisharp \
      --prefix DOTNET_ROOT : ${dotnet-sdk} \
      --suffix PATH : ${dotnet-sdk}/bin
  '';

  meta = with lib; {
    description = "OmniSharp based on roslyn workspaces";
    homepage = "https://github.com/OmniSharp/omnisharp-roslyn";
    platforms = platforms.unix;
    license = licenses.mit;
    maintainers = with maintainers; [ tesq0 ericdallo corngood ];
    mainProgram = "omnisharp";
  };

}
{'fraction_non_alphanumeric': 0.14427157001414428, 'fraction_numerical': 0.012199434229137199, 'mean_word_length': 2.379330943847073, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 2, '>': 23, 'https://': 3, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4327264', 'n_tokens_mistral': 2079, 'n_tokens_neox': 1979, 'n_words': 404}