Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#82: Add support for F# migrations projects #126

Draft
wants to merge 8 commits into
base: release/223
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ on:
branches: [ release/* ]
workflow_dispatch:

permissions: read-all

jobs:
build-ubuntu:
runs-on: ubuntu-latest
Expand All @@ -16,7 +18,13 @@ jobs:
- name: 🛠 Prepare Build Environment
uses: ./.github/workflows/prepare-build-env

- name: 🔍 List files (debug)
id: list-files
run: |
FILES=$(./gradlew :properties)
echo $FILES
echo "::set-output name=FILES_ALL::$FILES"

- name: 🏗 Build Plugin (Stable)
uses: gradle/gradle-build-action@v2
with:
arguments: buildPlugin
shell: bash
run: ./gradlew :buildPlugin
10 changes: 4 additions & 6 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,8 @@ jobs:
echo "PLUGIN_VERSION=$(./gradlew properties | grep -oP '(?<=PluginVersion: ).*')" >> $GITHUB_ENV

- name: 🏗 Build Plugin
uses: gradle/gradle-build-action@v2
with:
arguments: buildPlugin
shell: bash
run: ./gradlew :buildPlugin

- name: 🏗 Get current changelog
id: changelog_step
Expand All @@ -53,6 +52,5 @@ jobs:
token: ${{ secrets.GITHUB_TOKEN }}

- name: 🚀 Publish Plugin
uses: gradle/gradle-build-action@v2
with:
arguments: publishPlugin -PPublishToken=${{ secrets.JB_PUBLISH_TOKEN }} -PPublishChannel=${{ github.event.inputs.channel }}
shell: bash
run: ./gradlew :publishPlugin -PPublishToken=${{ secrets.JB_PUBLISH_TOKEN }} -PPublishChannel=${{ github.event.inputs.channel }}
6 changes: 2 additions & 4 deletions .github/workflows/prepare-build-env/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,5 @@ runs:
dotnet-version: '6.0.301'

- name: 🏗 Generate RD protocol data
uses: gradle/gradle-build-action@v2
with:
cache-disabled: true
arguments: rdgen
shell: bash
run: ./gradlew :rdgen
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [223.1.0] - 2022-10-20
### Added
- Support for F# migrations projects

## [223.0.0] - 2022-09-30
### Added
- Enable support for Rider 2022.3 EAP
Expand Down
38 changes: 21 additions & 17 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import org.apache.tools.ant.taskdefs.condition.Os
import java.text.SimpleDateFormat

plugins {
id 'java'
id 'org.jetbrains.kotlin.jvm' version '1.6.21'
id 'org.jetbrains.intellij' version '1.9.0' // https://github.com/JetBrains/gradle-intellij-plugin/releases
id 'com.jetbrains.rdgen' version '2022.3.2' // https://www.myget.org/feed/rd-snapshots/package/maven/com.jetbrains.rd/rd-gen
id 'org.jetbrains.changelog' version '1.3.1'
id "java"
id "org.jetbrains.kotlin.jvm" version "1.6.21"
id "org.jetbrains.intellij" version "1.10.0" // https://github.com/JetBrains/gradle-intellij-plugin/releases
id "com.jetbrains.rdgen" version "2022.3.2" // https://www.myget.org/feed/rd-snapshots/package/maven/com.jetbrains.rd/rd-gen
id "org.jetbrains.changelog" version "1.3.1"
}

ext {
Expand All @@ -19,12 +19,12 @@ ext {
}

repositories {
maven { url 'https://cache-redirector.jetbrains.com/intellij-repository/snapshots' }
maven { url 'https://cache-redirector.jetbrains.com/maven-central' }
maven { url "https://cache-redirector.jetbrains.com/intellij-repository/snapshots" }
maven { url "https://cache-redirector.jetbrains.com/maven-central" }
}

wrapper {
gradleVersion = '7.4.2'
gradleVersion = "7.4.2"
distributionType = Wrapper.DistributionType.ALL
distributionUrl = "https://cache-redirector.jetbrains.com/services.gradle.org/distributions/gradle-${gradleVersion}-all.zip"
}
Expand All @@ -33,9 +33,9 @@ version = ext.PluginVersion

sourceSets {
main {
java.srcDir 'src/rider/main/java'
kotlin.srcDir 'src/rider/main/kotlin'
resources.srcDir 'src/rider/main/resources'
java.srcDir "src/rider/main/java"
kotlin.srcDir "src/rider/main/kotlin"
resources.srcDir "src/rider/main/resources"
}
}

Expand All @@ -56,11 +56,15 @@ task setBuildTool {
ext.args << "/p:Configuration=${BuildConfiguration}"
ext.args << "/p:HostFullIdentifier="
ext.args << "/p:SdkVersion=${RiderSdkVersion}"
ext.args << "/p:RiderVersion=${ProductVersion}"
ext.args << "/p:GradleBuildDir=\"${buildDir}\""
}
}

task compileDotNet {
dependsOn setBuildTool
dependsOn setupDependencies

doLast {
def arguments = setBuildTool.args.clone()
arguments << "/t:Restore;Rebuild"
Expand Down Expand Up @@ -91,15 +95,15 @@ buildPlugin {
}
}

apply plugin: 'org.jetbrains.changelog'
apply plugin: "org.jetbrains.changelog"

intellij {
type = 'RD'
type = "RD"
version = "${ProductVersion}"
downloadSources = false
instrumentCode = false
// TODO: add plugins
// plugins = ["uml", "com.jetbrains.ChooseRuntime:1.0.9"]
plugins = ["rider-fsharp"]

patchPluginXml {
changeNotes = changelog.get(PluginVersion).toHTML()
Expand All @@ -117,10 +121,10 @@ changelog {
}

runIde {
// Match Rider's default heap size of 1.5Gb (default for runIde is 512Mb)
// Match Rider"s default heap size of 1.5Gb (default for runIde is 512Mb)
maxHeapSize = "1500m"

// Rider's backend doesn't support dynamic plugins. It might be possible to work with auto-reload of the frontend
// Rider"s backend doesn"t support dynamic plugins. It might be possible to work with auto-reload of the frontend
// part of a plugin, but there are dangers about keeping plugins in sync
autoReloadPlugins = false

Expand All @@ -131,7 +135,7 @@ runIde {
rdgen {
def modelDir = new File(rootDir, "protocol/src/main/kotlin/model")
def csOutput = new File(rootDir, "src/dotnet/${DotnetPluginId}/Rd")
def ktOutput = new File(rootDir, "src/rider/main/kotlin/${RiderPluginId.replace('.','/').toLowerCase()}/rd")
def ktOutput = new File(rootDir, "src/rider/main/kotlin/${RiderPluginId.replace(".","/").toLowerCase()}/rd")

verbose = true
classpath {
Expand Down
106 changes: 106 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
buildScript {
repositories {
maven { setUrl("https://cache-redirector.jetbrains.com/intellij-repository/snapshots") }
maven { setUrl("https://cache-redirector.jetbrains.com/maven-central") }
}

// https://search.maven.org/artifact/com.jetbrains.rd/rd-gen
dependencies {
classpath("com.jetbrains.rd:rd-gen:2022.3.2")
}
}

plugins {
id("java")
id("me.filippov.gradle.jvm.wrapper") version "0.14.0"
id("org.jetbrains.kotlin.jvm") version "1.7.20"
id("org.jetbrains.intellij") version "1.9.0"
}

apply {
plugin("com.jetbrains.rdgen")
}

val DotnetPluginId: String by project
val DotnetSolution: String by project
val RiderPluginId: String by project
val PluginVersion: String by project

val BuildConfiguration: String by project

val PublishToken: String by project
val PublishChannel: String by project

val RiderSdkVersion: String by project
val ProductVersion: String by project

val rdLibDirectory: () -> File = { file("${tasks.setupDependencies.get().idea.get().classes}/lib/rd") }
extra["rdLibDirectory"] = rdLibDirectory

version = PluginVersion

repositories {
maven { setUrl("https://cache-redirector.jetbrains.com/intellij-repository/snapshots") }
maven { setUrl("https://cache-redirector.jetbrains.com/maven-central") }
}

sourceSets {
main {
java.srcDir("src/rider/main/kotlin")
resources.srcDir("src/rider/main/resources")
}
}

apply(plugin = "com.jetbrains.rdgen")

configure<com.jetbrains.rd.generator.gradle.RdGenExtension> {
val modelDir = file("$projectDir/protocol/src/main/kotlin/model")
val csOutput = file("$projectDir/src/dotnet/$DotnetPluginId/Rd")
val ktOutput = file("$projectDir/src/rider/main/kotlin/${RiderPluginId.replace(".","/").toLowerCase()}/rd")

verbose = true
classpath({
"${rdLibDirectory()}/rider-model.jar"
})
sources("$modelDir/rider")
hashFolder = "$rootDir/build/rdgen/rider"
packages = "model.rider"

generator {
language = "kotlin"
transform = "asis"
root = "com.jetbrains.rider.model.nova.ide.IdeRoot"
namespace = "me.seclerp.rider.plugins.efcore.model"
directory = "$ktOutput"
}

generator {
language = "csharp"
transform = "reversed"
root = "com.jetbrains.rider.model.nova.ide.IdeRoot"
namespace = RiderPluginId
directory = "$csOutput"
}
}

intellij {
type.set("RD")
version.set(RiderSdkVersion)
downloadSources.set(false)
}

tasks {
wrapper {
gradleVersion = "7.5.1"
distributionType = Wrapper.DistributionType.ALL
distributionUrl = "https://cache-redirector.jetbrains.com/services.gradle.org/distributions/gradle-${gradleVersion}-all.zip"
}

val riderSdkPath by lazy {
val path = setupDependencies.get().idea.get().classes.resolve("lib/DotNetSdkForRdPlugins")
if (!path.isDirectory) error("$path does not exist or not a directory")

println("Rider SDK path: $path")
return@lazy path
}
}
8 changes: 8 additions & 0 deletions protocol/src/main/kotlin/model/rider/RiderEfCoreModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,13 @@ object RiderEfCoreModel : Ext(SolutionModel.Solution) {
field("migrationShortName", string)
field("migrationLongName", string)
field("migrationFolderAbsolutePath", string)
field("language", language)
}

private val DbContextInfo = structdef {
field("name", string)
field("fullName", string)
field("language", language)
}

private val EfToolDefinition = structdef {
Expand All @@ -49,6 +51,12 @@ object RiderEfCoreModel : Ext(SolutionModel.Solution) {
})
}

private val language = enum {
+"Unknown"
+"CSharp"
+"FSharp"
}

init {
setting(CSharp50Generator.Namespace, "Rider.Plugins.EfCore.Rd")
setting(Kotlin11Generator.Namespace, "me.seclerp.rider.plugins.efcore.rd")
Expand Down
2 changes: 2 additions & 0 deletions src/dotnet/Plugin.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

<PropertyGroup>
<SdkVersion Condition=" '$(SdkVersion)' == '' ">2022.3.0-eap01</SdkVersion>
<RiderVersion Condition=" '$(RiderVersion)' == '' ">2022.3-EAP1-SNAPSHOT</RiderVersion>
<GradleBuildDir Condition=" '$(GradleBuildDir)' == '' ">../../../build</GradleBuildDir>

<Title>Entity Framework Core</Title>
<Description>JetBrains Rider plugin for Entity Framework Core</Description>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,17 @@ public SupportedMigrationsProjectsProvider(ISolution solution)
public IEnumerable<IProject> GetSupportedMigrationProjects()
{
var supportedMigrationProjects = _solution.GetAllProjects()
.Where(project => project.TargetFrameworkIds.Any(IsSupportedInMigrationsProject))
.Where(project => project.ProjectFileLocation.ExtensionNoDot == "csproj");
.Where(project => project.TargetFrameworkIds.Any(IsSupportedTargetFramework))
.Where(project => IsSupportedProjectExtension(project.ProjectFileLocation.ExtensionNoDot));

return supportedMigrationProjects;
}

private static bool IsSupportedInMigrationsProject(TargetFrameworkId targetFrameworkId) =>
private static bool IsSupportedProjectExtension(string extensionNoDot) =>
extensionNoDot == "csproj"
|| extensionNoDot == "fsproj";

private static bool IsSupportedTargetFramework(TargetFrameworkId targetFrameworkId) =>
targetFrameworkId.UniqueString.StartsWith(SupportedTargetFrameworks.Net5)
|| targetFrameworkId.UniqueString.StartsWith(SupportedTargetFrameworks.Net6)
|| targetFrameworkId.UniqueString.StartsWith(SupportedTargetFrameworks.Net7)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,23 +37,23 @@ public IEnumerable<IProject> GetSupportedStartupProjects()

var result = projectsWithNugetPacks
.Concat(referencingProjects)
.Where(project => project.TargetFrameworkIds.Any(IsSupportedInStartupProject))
.Where(project => project.TargetFrameworkIds.Any(IsSupportedTargetFramework))
.Distinct();

return result;
}

private bool StartupProjectPackagesInstalled(IProject project) =>
_nugetTracker.HasPackage(project, EfCoreRequiredPackages.EfCoreToolsNugetId)
|| _nugetTracker.HasPackage(project, EfCoreRequiredPackages.EfCoreDesignNugetId);
_nugetTracker.HasPackage(project, KnownNuGetPackages.EfCoreToolsNugetId)
|| _nugetTracker.HasPackage(project, KnownNuGetPackages.EfCoreDesignNugetId);

private IEnumerable<IProject> GetReferencingProjects(IProject project) =>
project.TargetFrameworkIds
.SelectMany(x => project.GetReferencingProjectsEx(x))
.Select(x => x.Value)
.ToList();

private static bool IsSupportedInStartupProject(TargetFrameworkId targetFrameworkId) =>
private static bool IsSupportedTargetFramework(TargetFrameworkId targetFrameworkId) =>
targetFrameworkId.UniqueString.StartsWith(SupportedTargetFrameworks.Net5)
|| targetFrameworkId.UniqueString.StartsWith(SupportedTargetFrameworks.Net6)
|| targetFrameworkId.UniqueString.StartsWith(SupportedTargetFrameworks.Net7)
Expand Down
11 changes: 10 additions & 1 deletion src/dotnet/Rider.Plugins.EfCore/DbContext/DbContextProvider.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using System.Collections.Generic;
using System.Linq;
using JetBrains.ProjectModel;
using JetBrains.ReSharper.Plugins.FSharp.Psi;
using JetBrains.ReSharper.Psi;
using JetBrains.ReSharper.Psi.CSharp;
using JetBrains.ReSharper.Psi.Modules;
using JetBrains.RiderTutorials.Utils;
using Rider.Plugins.EfCore.Extensions;
Expand Down Expand Up @@ -38,7 +40,14 @@ private static bool TryGetDbContextInfo(IClass @class, out DbContextInfo dbConte
return false;
}

dbContextInfo = new DbContextInfo(@class.ShortName, @class.GetFullClrName());
var language = @class.PresentationLanguage switch
{
CSharpLanguage _ => Language.CSharp,
FSharpLanguage _ => Language.FSharp,
_ => Language.Unknown
};

dbContextInfo = new DbContextInfo(@class.ShortName, @class.GetFullClrName(), language);

return true;
}
Expand Down
Loading