Skip to content

Commit

Permalink
add strture for project in projectManager
Browse files Browse the repository at this point in the history
  • Loading branch information
keyroll-99 committed May 29, 2024
1 parent 650ad9d commit d077b2c
Show file tree
Hide file tree
Showing 8 changed files with 103 additions and 37 deletions.
3 changes: 3 additions & 0 deletions ide/src/Fiona.IDE.Compiler/Parser/Parser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
using Fiona.IDE.ProjectManager.Models;
using Microsoft.VisualBasic;
using System.Text;
using Class=Fiona.IDE.Compiler.Parser.Models.Class;
using Dependency=Fiona.IDE.Compiler.Parser.Models.Dependency;
using Endpoint=Fiona.IDE.Compiler.Parser.Models.Endpoint;

namespace Fiona.IDE.Compiler.Parser;

Expand Down
12 changes: 12 additions & 0 deletions ide/src/Fiona.IDE.ProjectManager/Models/Class.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace Fiona.IDE.ProjectManager.Models;

public sealed class Class
{
public IReadOnlyCollection<Dependency> Dependencies => _dependencies.AsReadOnly();

private List<Dependency> _dependencies = new();
private string _route;

Check warning on line 8 in ide/src/Fiona.IDE.ProjectManager/Models/Class.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable field '_route' must contain a non-null value when exiting constructor. Consider declaring the field as nullable.

Check warning on line 8 in ide/src/Fiona.IDE.ProjectManager/Models/Class.cs

View workflow job for this annotation

GitHub Actions / build

The field 'Class._route' is never used
private List<Endpoint> _endpoints = new();


}
2 changes: 1 addition & 1 deletion ide/src/Fiona.IDE.ProjectManager/Models/Dependency.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace Fiona.IDE.ProjectManager.Models;

internal sealed class Dependency(string name, string type)
public sealed class Dependency(string name, string type)
{
public string Name { get; } = name;
public string Type { get; } = type;
Expand Down
9 changes: 9 additions & 0 deletions ide/src/Fiona.IDE.ProjectManager/Models/Endpoint.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace Fiona.IDE.ProjectManager.Models;

public sealed class Endpoint
{
private string? _route;

Check warning on line 5 in ide/src/Fiona.IDE.ProjectManager/Models/Endpoint.cs

View workflow job for this annotation

GitHub Actions / build

The field 'Endpoint._route' is never used
private string[] _methods;

Check warning on line 6 in ide/src/Fiona.IDE.ProjectManager/Models/Endpoint.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable field '_methods' must contain a non-null value when exiting constructor. Consider declaring the field as nullable.

Check warning on line 6 in ide/src/Fiona.IDE.ProjectManager/Models/Endpoint.cs

View workflow job for this annotation

GitHub Actions / build

The field 'Endpoint._methods' is never used
private string _returnType;

Check warning on line 7 in ide/src/Fiona.IDE.ProjectManager/Models/Endpoint.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable field '_returnType' must contain a non-null value when exiting constructor. Consider declaring the field as nullable.

Check warning on line 7 in ide/src/Fiona.IDE.ProjectManager/Models/Endpoint.cs

View workflow job for this annotation

GitHub Actions / build

The field 'Endpoint._returnType' is never used

}
6 changes: 3 additions & 3 deletions ide/src/Fiona.IDE.ProjectManager/Models/FslnFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ internal static async Task<FslnFile> CreateAsync(string name, string pathToFolde
return await JsonSerializer.DeserializeAsync<FslnFile>(fs);
}

internal Task AddFile(string name, string path)
internal async Task AddFile(string name, string path)
{
ProjectFileUrl!.Add(
ProjectFile.Create($"{path}{System.IO.Path.DirectorySeparatorChar}{name}.{ProjectFile.Extension}"));
return SaveAsync();
await ProjectFile.Create($"{path}{System.IO.Path.DirectorySeparatorChar}{name}.{ProjectFile.Extension}"));
await SaveAsync();
}

private async Task SaveAsync()
Expand Down
15 changes: 15 additions & 0 deletions ide/src/Fiona.IDE.ProjectManager/Models/Input.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
namespace Fiona.IDE.ProjectManager.Models;

public sealed class Input
{
private string _name;
private string _type;
private string _attribute;

public Input(string name, string type, string attribute)
{
_name = name;
_type = type;
_attribute = attribute;
}
}
75 changes: 51 additions & 24 deletions ide/src/Fiona.IDE.ProjectManager/Models/ProjectFile.cs
Original file line number Diff line number Diff line change
@@ -1,35 +1,62 @@
using Fiona.IDE.ProjectManager.Exceptions;
using System.Text.Json.Serialization;

namespace Fiona.IDE.ProjectManager.Models
namespace Fiona.IDE.ProjectManager.Models;

public sealed class ProjectFile
{
public sealed class ProjectFile
{
public string Path { get; }
public string Name { get; }
public string Namespace { get; }
public const string Extension = "fn";
public string Path { get; }
public string Name { get; }
public string Namespace { get; }

public const string Extension = "fn";

private Class @class;

Check warning on line 14 in ide/src/Fiona.IDE.ProjectManager/Models/ProjectFile.cs

View workflow job for this annotation

GitHub Actions / build

The field 'ProjectFile.@Class' is never used

[JsonConstructor]
private ProjectFile(string path)
{
Path = path;
Name = path.Split(System.IO.Path.DirectorySeparatorChar).Last();
Namespace = path.Replace(System.IO.Path.DirectorySeparatorChar.ToString(), ".").Split(":").Last().Replace(".fn", "")[1..];
}

internal static ProjectFile Create(string path)
[JsonConstructor]
private ProjectFile(string path)

Check warning on line 18 in ide/src/Fiona.IDE.ProjectManager/Models/ProjectFile.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable field 'class' must contain a non-null value when exiting constructor. Consider declaring the field as nullable.
{
Path = path;
Name = path.Split(System.IO.Path.DirectorySeparatorChar).Last();
Namespace = path.Replace(System.IO.Path.DirectorySeparatorChar.ToString(), ".").Split(":").Last().Replace(".fn", "")[1..];
}

internal static async Task<ProjectFile> Create(string path)
{
if (File.Exists(path))
{
if (File.Exists(path))
{
throw new FileAlreadyExistsException(path);
}
File.Create(path);



return new ProjectFile(path);
throw new FileAlreadyExistsException(path);
}
File.Create(path);

ProjectFile projectFile = new(path);

await projectFile.SaveContentAsync(projectFile.GetBaseContent());

return projectFile;
}

private async Task SaveContentAsync(string content)
{
await File.WriteAllTextAsync(Path, content);
}

}

internal static class ProjectFileExtensions
{
public static string GetBaseContent(this ProjectFile projectFile)
{
return $"""
usingBegin;
using Fiona.Hosting.Controller.Attributes;
using Fiona.Hosting.Routing;
using Fiona.Hosting.Routing.Attributes;
usingEnd;
namespace: {projectFile.Namespace}
class: {projectFile.Name}
""";
}

}
18 changes: 9 additions & 9 deletions ide/tests/Fiona.IDE.Compiler.Tests/Parser/ParserTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public ParserTests()
public async Task When_Given_TokenizedCode_Should_Return_Parsed_Code()
{
// arrange
ProjectFile projectFile = GetTestProjectFile(nameof(When_Given_TokenizedCode_Should_Return_Parsed_Code));
ProjectFile projectFile = await GetTestProjectFile(nameof(When_Given_TokenizedCode_Should_Return_Parsed_Code));
using MemoryStream stream = new(Encoding.UTF8.GetBytes(SampleTestCode.FullTokensTest!));
using StreamReader reader = new(stream);

Expand Down Expand Up @@ -59,7 +59,7 @@ public async Task<User> Index()
public async Task When_Given_TokenizedCodeWithParameter_Should_Return_Parsed_Code()
{
// arrange
ProjectFile projectFile = GetTestProjectFile(nameof(When_Given_TokenizedCodeWithParameter_Should_Return_Parsed_Code));
ProjectFile projectFile = await GetTestProjectFile(nameof(When_Given_TokenizedCodeWithParameter_Should_Return_Parsed_Code));
using MemoryStream stream = new(Encoding.UTF8.GetBytes(SampleTestCode.FullTokensTestWithParameter!));
using StreamReader reader = new(stream);

Expand Down Expand Up @@ -103,7 +103,7 @@ public async Task<User> Index([FromRoute] string name, [QueryParam] int age, [Bo
public async Task When_Given_TokenizedCodeWithParameterAndBody_Should_Return_Parsed_Code()
{
// arrange
ProjectFile projectFile = GetTestProjectFile(nameof(When_Given_TokenizedCodeWithParameterAndBody_Should_Return_Parsed_Code));
ProjectFile projectFile = await GetTestProjectFile(nameof(When_Given_TokenizedCodeWithParameterAndBody_Should_Return_Parsed_Code));
using MemoryStream stream = new(Encoding.UTF8.GetBytes(SampleTestCode.FullControllerWithBody!));
using StreamReader reader = new(stream);

Expand Down Expand Up @@ -157,7 +157,7 @@ public async Task<User> Index([FromRoute] string name, [QueryParam] int age, [Bo
internal async Task When_Given_Invalid_Using_Tokens_Then_Throw_Exception(string fileName, params Token[] tokens)
{
// Arrange
ProjectFile projectFile = GetTestProjectFile(fileName);
ProjectFile projectFile = await GetTestProjectFile(fileName);

// Act
Func<Task<ReadOnlyMemory<byte>>> action = async () => await _parser.ParseAsync(tokens, projectFile);
Expand All @@ -170,7 +170,7 @@ internal async Task When_Given_Invalid_Using_Tokens_Then_Throw_Exception(string
internal async Task When_Given_Valid_Using_Tokens_Then_Should_Not_Throw_Error(string fileName, params Token[] tokens)
{
// Arrange
ProjectFile projectFile = GetTestProjectFile(fileName);
ProjectFile projectFile = await GetTestProjectFile(fileName);

// Act
Func<Task<ReadOnlyMemory<byte>>> action = async () => await _parser.ParseAsync(tokens, projectFile);
Expand All @@ -183,7 +183,7 @@ internal async Task When_Given_Valid_Using_Tokens_Then_Should_Not_Throw_Error(st
internal async Task When_Given_Invalid_Class_Tokens_Then_Throw_Exception(string fileName, params Token[] tokens)
{
// Arrange
ProjectFile projectFile = GetTestProjectFile(fileName);
ProjectFile projectFile = await GetTestProjectFile(fileName);

// Act
Func<Task<ReadOnlyMemory<byte>>> action = async () => await _parser.ParseAsync(tokens, projectFile);
Expand All @@ -196,7 +196,7 @@ internal async Task When_Given_Invalid_Class_Tokens_Then_Throw_Exception(string
internal async Task When_Given_Valid_Class_Tokens_Then_Should_Not_Throw_Error(string fileName, params Token[] tokens)
{
// Arrange
ProjectFile projectFile = GetTestProjectFile(fileName);
ProjectFile projectFile = await GetTestProjectFile(fileName);

// Act
Func<Task<ReadOnlyMemory<byte>>> action = async () => await _parser.ParseAsync(tokens, projectFile);
Expand All @@ -206,13 +206,13 @@ internal async Task When_Given_Valid_Class_Tokens_Then_Should_Not_Throw_Error(st
}


private ProjectFile GetTestProjectFile(string name)
private async Task<ProjectFile> GetTestProjectFile(string name)
{
if (File.Exists(name))
{
File.Delete(name);
}
return ProjectFile.Create(name);
return await ProjectFile.Create(name);
}

}

0 comments on commit d077b2c

Please sign in to comment.