Skip to content

Sqlite support added to C# plugin#854

Open
matecsad wants to merge 1 commit intoEricsson:feature/csharp_pluginfrom
matecsad:feature/csharp_plugin
Open

Sqlite support added to C# plugin#854
matecsad wants to merge 1 commit intoEricsson:feature/csharp_pluginfrom
matecsad:feature/csharp_plugin

Conversation

@matecsad
Copy link
Copy Markdown
Collaborator

@matecsad matecsad commented Apr 28, 2026

Resolves #819

@mcserep mcserep requested review from Copilot and mcserep April 28, 2026 09:13
@mcserep mcserep added Kind: Enhancement 🌟 Plugin: C# Issues related to the parsing and presentation of C# projects. labels Apr 28, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds SQLite support to the C# plugin by refactoring the EF Core model into a shared DbModel project and introducing separate EF Core migration projects for PostgreSQL and SQLite, enabling the parser/service components to target either DB backend.

Changes:

  • Extract EF Core entities/DbContext into a new plugins/csharp/db_model project and update parser/service to reference it.
  • Add SQLite EF Core provider dependencies and SQLite migration project alongside PostgreSQL migrations.
  • Update connection-string handling and DbContext configuration to select provider/migrations by a DB “scheme” prefix (e.g., pgsql: vs sqlite:).

Reviewed changes

Copilot reviewed 27 out of 31 changed files in this pull request and generated 15 comments.

Show a summary per file
File Description
plugins/csharp/service/src_csharp/csharpservice.csproj Switches from compiling model sources to referencing DbModel; adds SQLite provider package.
plugins/csharp/service/src_csharp/CSharpQueryServer.cs Updates model namespace usage to DbModel.
plugins/csharp/service/src_csharp/CSharpQueryHandler.cs Creates CsharpDbContext based on scheme; updates AST node lookup; adds connection-string transformation helper.
plugins/csharp/parser/src_csharp/Program.cs Updates to use DbModel DbContext; adds scheme-based connection-string transform; adjusts assembly scanning logic.
plugins/csharp/parser/src_csharp/CSharpParser.csproj Replaces compiled-in model/migrations with project references; adds EF Core design + SQLite provider.
plugins/csharp/parser/src_csharp/AstVisitor.cs Updates model namespace usage to DbModel.
plugins/csharp/model/CsharpEntity.cs Removes old in-project model type (moved to DbModel).
plugins/csharp/model/CsharpDbContext.cs Removes old in-project DbContext (moved to DbModel).
plugins/csharp/migrations/sqliteMigrations/SqliteMigrations.csproj New SQLite migrations project referencing DbModel.
plugins/csharp/migrations/sqliteMigrations/SqliteDbContextModelSnapshot.cs Adds SQLite model snapshot for migrations.
plugins/csharp/migrations/sqliteMigrations/20260302184000_Initial.cs Adds initial SQLite migration.
plugins/csharp/migrations/sqliteMigrations/20260302184000_Initial.Designer.cs Adds SQLite migration designer metadata.
plugins/csharp/migrations/pgsqlMigrations/PgsqlMigrations.csproj New PostgreSQL migrations project referencing DbModel.
plugins/csharp/migrations/pgsqlMigrations/CsharpDbContextModelSnapshot.cs Moves PostgreSQL model snapshot into new project.
plugins/csharp/migrations/pgsqlMigrations/20220518134047_Initial.cs Moves initial PostgreSQL migration into new project.
plugins/csharp/migrations/pgsqlMigrations/20220518134047_Initial.Designer.cs Moves PostgreSQL migration designer metadata into new project.
plugins/csharp/migrations/CsharpDbContextModelSnapshot.cs Removes old snapshot location.
plugins/csharp/migrations/20220518134047_Initial.cs Removes old migration location.
plugins/csharp/migrations/20220518134047_Initial.Designer.cs Removes old migration designer location.
plugins/csharp/db_model/DbModel.csproj New shared model project with EF Core + providers.
plugins/csharp/db_model/CsharpVariable.cs Updates namespace to DbModel; makes entity/enum public.
plugins/csharp/db_model/CsharpNamespace.cs Updates namespace to DbModel; makes entity public.
plugins/csharp/db_model/CsharpMethod.cs Updates namespace to DbModel; makes entity/enum public.
plugins/csharp/db_model/CsharpEnumMember.cs Updates namespace to DbModel; makes entity public; adds FK id.
plugins/csharp/db_model/CsharpEnum.cs Updates namespace to DbModel; makes entity public; relaxes nullability.
plugins/csharp/db_model/CsharpEntity.cs New shared base entity/types in DbModel.
plugins/csharp/db_model/CsharpDbContext.cs New shared DbContext selecting provider/migrations by scheme.
plugins/csharp/db_model/CsharpClass.cs Updates namespace to DbModel; makes entities/enums public; relaxes nullability.
plugins/csharp/db_model/CsharpAstNode.cs Updates namespace to DbModel; makes entity/enums public; relaxes nullability.
CodeCompass-fork.sln Adds a Visual Studio solution including new projects.
.gitignore Ignores Build/ directory.
Files not reviewed (3)
  • plugins/csharp/migrations/20220518134047_Initial.Designer.cs: Language not supported
  • plugins/csharp/migrations/pgsqlMigrations/20220518134047_Initial.Designer.cs: Language not supported
  • plugins/csharp/migrations/sqliteMigrations/20260302184000_Initial.Designer.cs: Language not supported
Comments suppressed due to low confidence (1)

plugins/csharp/parser/src_csharp/CSharpParser.csproj:29

  • EF Core provider package version (Microsoft.EntityFrameworkCore.Sqlite 8.0.11 / Npgsql.EntityFrameworkCore.PostgreSQL 8.0.11) doesn’t match the shared EF Core runtime version (Microsoft.EntityFrameworkCore 8.0.20). Keeping EFCore + providers on the same patch version avoids binding/runtime incompatibilities; consider aligning all EF-related package versions.
    <PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.20" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.20">
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
      <PrivateAssets>all</PrivateAssets>
    </PackageReference>
    <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.11" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.20">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
    <PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.11" />

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +19 to +24
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.11" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.20">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.11" />
Copy link

Copilot AI Apr 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

EF Core provider package versions (Sqlite 8.0.11 / Npgsql 8.0.11) don’t match the EF Core runtime version (8.0.20). Aligning EFCore and provider patch versions reduces the risk of runtime binding and subtle behavior mismatches.

Suggested change
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.11" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.20">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.11" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.20" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.20">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.20" />

Copilot uses AI. Check for mistakes.
Comment on lines +22 to +26
modelBuilder.HasAnnotation("ProductVersion", "8.0.20");

modelBuilder.Entity("CSharpParser.model.CsharpAstNode", b =>
{
b.Property<ulong>("Id")
Copy link

Copilot AI Apr 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This migration designer still references the old entity type names ("CSharpParser.model.*") even though the entities now live in DbModel. Regenerate/update the migration metadata to reflect the new namespaces to avoid inconsistencies when adding future migrations.

Copilot uses AI. Check for mistakes.
Comment on lines +21 to +25
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);

modelBuilder.Entity("CSharpParser.model.CsharpAstNode", b =>
{
b.Property<decimal>("Id")
Copy link

Copilot AI Apr 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This snapshot still uses entity type names under the old namespace ("CSharpParser.model.*") even though the model types have been moved to DbModel. Regenerate or update the migrations snapshot so the model reflects the current CLR namespaces; otherwise future migrations generation and model comparisons can become inconsistent.

Copilot uses AI. Check for mistakes.
Comment thread CodeCompass-fork.sln
Comment on lines +35 to +39
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "sqliteMigrations", "plugins\csharp\migrations\sqliteMigrations\sqliteMigrations.csproj", "{4709E553-FC92-44D2-85CC-A1EFE918F70B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "pgsqlMigrations", "plugins\csharp\migrations\pgsqlMigrations\pgsqlMigrations.csproj", "{AB02187B-59AB-4E35-B1C8-B835F25B9692}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "db_model", "plugins\csharp\db_model\db_model.csproj", "{B9532E7A-2CB8-4DEC-A0DA-672AF7D054E6}"
Copy link

Copilot AI Apr 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The solution references csproj paths that don’t match the actual filenames’ casing (e.g., sqliteMigrations.csproj vs SqliteMigrations.csproj, db_model.csproj vs DbModel.csproj). This breaks loading/building the solution on case-sensitive filesystems. Update the paths to match the real on-disk filenames.

Suggested change
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "sqliteMigrations", "plugins\csharp\migrations\sqliteMigrations\sqliteMigrations.csproj", "{4709E553-FC92-44D2-85CC-A1EFE918F70B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "pgsqlMigrations", "plugins\csharp\migrations\pgsqlMigrations\pgsqlMigrations.csproj", "{AB02187B-59AB-4E35-B1C8-B835F25B9692}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "db_model", "plugins\csharp\db_model\db_model.csproj", "{B9532E7A-2CB8-4DEC-A0DA-672AF7D054E6}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "sqliteMigrations", "plugins\csharp\migrations\sqliteMigrations\SqliteMigrations.csproj", "{4709E553-FC92-44D2-85CC-A1EFE918F70B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "pgsqlMigrations", "plugins\csharp\migrations\pgsqlMigrations\pgsqlMigrations.csproj", "{AB02187B-59AB-4E35-B1C8-B835F25B9692}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "db_model", "plugins\csharp\db_model\DbModel.csproj", "{B9532E7A-2CB8-4DEC-A0DA-672AF7D054E6}"

Copilot uses AI. Check for mistakes.
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.11" />
Copy link

Copilot AI Apr 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

EF Core provider package version (Microsoft.EntityFrameworkCore.Sqlite 8.0.11) doesn’t match the shared EF Core runtime version (8.0.20). Align provider and EFCore patch versions to avoid potential runtime/binding issues.

Suggested change
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.11" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.20" />

Copilot uses AI. Check for mistakes.
Comment on lines +94 to 97
ulong NodeId = ulong.Parse(astNodeId);
ret = dbContext.CsharpAstNodes
.Where(a => a.Id.ToString()==astNodeId)
.Where(a => a.Id==NodeId)
.First();
Copy link

Copilot AI Apr 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Parsing astNodeId with ulong.Parse can throw FormatException/OverflowException for non-numeric IDs, but only InvalidOperationException is caught. Use ulong.TryParse (or catch parse exceptions) and return a sensible not-found result instead of crashing the service on malformed input.

Copilot uses AI. Check for mistakes.
Comment on lines +690 to +694
else
{
// "sqlite:database=" needs to be removed from the connection string.
connectionString = connectionString.Substring(connectionString.IndexOf(':') + 10);
csharpConnectionString = "Data Source=" + connectionString;
Copy link

Copilot AI Apr 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

transformConnectionString treats any dbSystem other than "pgsql" as SQLite and then slices the string using a hard-coded offset. This will mis-handle unknown schemes and is fragile to connection-string format changes. Consider explicitly handling only supported values ("pgsql"/"sqlite"), validating the expected prefix (e.g., "sqlite:database="), and throwing a clear error for unsupported formats.

Copilot uses AI. Check for mistakes.
Comment on lines +41 to +43
default:
break;
}
Copy link

Copilot AI Apr 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OnConfiguring silently does nothing for unknown _dbSystem values, leaving the DbContext potentially unusable and making misconfiguration hard to debug. Consider throwing an ArgumentException/InvalidOperationException with the supported values (or at least logging) in the default branch.

Copilot uses AI. Check for mistakes.
Comment on lines +23 to +27
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);

modelBuilder.Entity("CSharpParser.model.CsharpAstNode", b =>
{
b.Property<decimal>("Id")
Copy link

Copilot AI Apr 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This migration designer still references the old entity type names ("CSharpParser.model.*") even though the entities now live in DbModel. Regenerate/update the migration metadata to reflect the new namespaces to avoid inconsistencies when adding future migrations.

Copilot uses AI. Check for mistakes.
Comment on lines 17 to +18
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.20" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.11" />
Copy link

Copilot AI Apr 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

EF Core provider package version (Microsoft.EntityFrameworkCore.Sqlite 8.0.11) doesn’t match the shared EF Core runtime version (Microsoft.EntityFrameworkCore 8.0.20). Keeping EFCore + providers on the same patch version avoids binding/runtime incompatibilities; consider bumping the provider to 8.0.20 (or aligning all EF packages consistently).

Copilot uses AI. Check for mistakes.
@mcserep mcserep linked an issue Apr 28, 2026 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Kind: Enhancement 🌟 Plugin: C# Issues related to the parsing and presentation of C# projects.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support Sqlite in the C# plugin

3 participants