GithubHelp home page GithubHelp logo

Comments (4)

handzlikchris avatar handzlikchris commented on June 6, 2024 1

Thanks - that looks good, and targetting just VisitRecordDeclaration makes it quite isolated. It'd be great if you can create a PR and I'll merge that in

from fastscriptreload.

builder-main avatar builder-main commented on June 6, 2024

Actually the issue is witch the record keyword itself not specifically on the shortcut syntax of records.

from fastscriptreload.

builder-main avatar builder-main commented on June 6, 2024

Also :

  • Tried to add a script override, for instance adding suffix public record LeapAction__Patched_
  • FSR still rewrites it public record LeapAction
  • The constructor gets rewritten with the suffix though : public LeapAction__Patched_().
  • We end up with the compiler throwing on the ctor error CS1520: Method must have a return type' as the ctor is recognised as a regular function.

from fastscriptreload.

builder-main avatar builder-main commented on June 6, 2024

Alright, I think I got it, I post the workaround here and either I'll do a PR or someone else after further testing, for now it looks okay with the regular and the shotcut syntax.
Add in DynamicCompilationBase just before user Scripts overrides :
root = new RecordeRewriter(DebugWriteRewriteReasonAsComment).Visit(root);
Rewriter :

using FastScriptReload.Runtime;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;

namespace FastScriptReload.Editor.Compilation.CodeRewriting
{
	class RecordeRewriter : FastScriptReloadCodeRewriterBase
        {
	        public RecordeRewriter(bool writeRewriteReasonAsComment)
				: base(writeRewriteReasonAsComment)
	        {
		        }
	        
	        public override SyntaxNode VisitRecordDeclaration(RecordDeclarationSyntax node)
	        {
		        return AdjustRecordName(node, node.Identifier);
	        }

	        private SyntaxNode AdjustRecordName(RecordDeclarationSyntax node, SyntaxToken nodeIdentifier)
	        {
		        var typeName = nodeIdentifier.ToString(); //Not ToFullString() as it may include spaces and break.
		        
		        if (!typeName.EndsWith(AssemblyChangesLoader.ClassnamePatchedPostfix))
		        {
			        typeName += AssemblyChangesLoader.ClassnamePatchedPostfix;
		        }

		        return AddRewriteCommentIfNeeded(
			        node.ReplaceToken(nodeIdentifier, SyntaxFactory.Identifier(typeName)), 
			        $"{nameof(RecordeRewriter)}:{nameof(AdjustRecordName)}"
			    );
	        }
        }
}

from fastscriptreload.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.